//--- request parameters
var params = new Array();
var params_asarray = window.location.href.match(/([\?&][^=]+=[^&#]*)/gi);
if (params_asarray) {
	for (var i=0; i<params_asarray.length; i++) {
		var insidehits = params_asarray[i].match(/[\?&]([^=]+)=([^&#]*)/i);
		if (insidehits) {
			params[insidehits[1]] = insidehits[2];
		}
	}
}

var addthis_config = { 
	services_exclude: 'print' 
} 


//--- are we in a frame (e.g. in a popup)
var isiniframe = (window.location.href != parent.location.href) ? true : false;
var suggestformdiv = null, suggestformdivdone = null;

//--- popup but not in a popup? close the popup and reload in bottom
if (isiniframe && params['popup']) {
	var newurl= window.location.href;
	newurl = newurl.replace(/\?popup=1/i, '?');
	newurl = newurl.replace(/&popup=1/, '');
	newurl = newurl.replace(/\?$/, '');
	window.location = newurl;
}

//--- document ready!
$(document).ready(function() {
	//--- popup uid discovery
	if (isiniframe) {
		myframe_uid = window.top.lastpopupopened_uid;
	}

	//--- click anywhere closes the admin controls
	$(document).click(function () { 
		hideAllAdminControls();
	} );

	//--- colorbox related stuff
	$("a.picturepreview").colorbox({
		current: "Bild {current} von {total}",
		previous: "voriges",
		next: "nächstes",
		close: "schließen",
		opacity: 0.5
	});

	//--- overlay animation over some buttons
	$("a.nextprevious").mouseover(function () { 
		$(this).find('img').animate({opacity: 0.5}, 'fast');
	});
	$("a.nextprevious").mouseout(function () { 
		$(this).find('img').animate({opacity: 1}, 'fast');
	});

	$("img.thumbnailsized").mouseover(function () { $(this).animate({opacity: 0.5}, 'fast'); });
	$("img.thumbnailsized").mouseout(function () { $(this).animate({opacity: 1}, 'fast'); });

	$("div.startpagebox").mouseover(function () { divcancelexit(this.id); $(this).stop().animate({top: 375, height: 162 }, 'slow', 'easeOutBack'); });
	$("div.startpagebox").mouseout(function () { divexit(this.id, function(id) { $('#'+id).stop().animate({top: 398, height: 92 }, 'fast', 'easeInBack'); }); });
	$("div.startpagebox1").click(function () { window.location = '/knowhow/'; });
	$("div.startpagebox2").click(function () { window.location = '/verein/'; });
	$("div.startpagebox3").click(function () { window.location = '/fussballschule/'; });
	
	$("#topnavi > a.ease").mouseover(function () { $(this).stop().animate({backgroundPosition: '0px 0px', color: '#FFFFFF' }, 500, 'easeOutBack'); });
	$("#topnavi > a.ease").mouseout(function () { $(this).stop().animate({backgroundPosition: '0px -48px', color: '#696969' }, 500, 'easeInBack'); });

	$(".listbox").mouseover(function () { divcancelexit(this.id); $(this).stop().animate({backgroundPosition: '0px 0px' }, 300, 'jswing'); });
	$(".listbox").mouseout(function () { divexit(this.id, function(id) { $('#'+id).stop().animate({backgroundPosition: '-600px 0px' }, 300, 'jswing'); }); });

	$(".listbox").bind('click', function () { 
		$(this).unbind('click');
		window.location = $(this).find('a.listboxaction').attr('href');
		//$(this).find('a.listboxaction').first().each( function () { this.click(); } );
	});


	//--- print mode exceptions
	if (params['printpreview'])	{
		$('.listsubs2_listbutton').hide();
		$('.listsubs1_listbutton').hide();
		$('.slideshows_listbutton').hide();
		$('.pressimages_listbutton').hide();
		$('.news_listbutton').hide();		
		$('.backbutton').hide();
	}

	//--- sortable lists triggers
	$("ul.slideshow[id*='cmssl']").sortable({
		update: function(event, ui) { 
			$.get("./?action=serializeupdate&" + ui.item.parent().sortable('serialize'), function(data) {
				if (data) {
					alert(data);
				}
			});
		}
	});


	//--- navigation animation and magick :)
	$('#mainnavi a.toplevel').click(function () {
		var div = $('#sub_' + this.id);
		if (!div.length) return true; //--- no id - no subs!
		if (div.attr('animating') == 1) return false; //--- animating - dont animate again

		div.attr('animating', 1);
		var maxheight = div.find('div').height();

		if (div.height() > 1) {
			$(this).find('img').attr('src', '/images/layout/naviarrow.png');
			div.animate({ height: 1 }, 300, false, function () { div.attr('animating', 0); });
		} else {
			$(this).find('img').attr('src', '/images/layout/naviarrow_sel.png');
			div.animate({ height: maxheight }, 300, false, function () { div.attr('animating', 0); });
		}
		this.blur();
		return false;
	});


	//--- login form needs opening?
	if (params['dologin']) {
		openpopup('loginform', './?form=login', 500, 120, 'Login', '', '');
	}


	//--- font size changing
	$('.size1').click(function () {
		$('#bottom div.right').find('p').css({'font-size': '13px'});
		$('#bottom div.right').find('blockquote').css({'font-size': '13px'});
		$('#bottom div.right').find('h1').css({'font-size': '33px'});
		$('#bottom div.right').find('h2').css({'font-size': '24px'});
		$('#bottom div.right').find('h3').css({'font-size': '18px'});
		$('#bottom div.right').find('h4').css({'font-size': '13px'});
		return false;
	});
	$('.size2').click(function () {
		$('#bottom div.right').find('p').css({'font-size': '15px'});
		$('#bottom div.right').find('blockquote').css({'font-size': '15px'});
		$('#bottom div.right').find('h1').css({'font-size': '40px'});
		$('#bottom div.right').find('h2').css({'font-size': '28px'});
		$('#bottom div.right').find('h3').css({'font-size': '21px'});
		$('#bottom div.right').find('h4').css({'font-size': '15px'});
		return false;
	});
	$('.size3').click(function () {
		$('#bottom div.right').find('p').css({'font-size': '17px'});
		$('#bottom div.right').find('blockquote').css({'font-size': '17px'});
		$('#bottom div.right').find('h1').css({'font-size': '50px'});
		$('#bottom div.right').find('h2').css({'font-size': '33px'});
		$('#bottom div.right').find('h3').css({'font-size': '24px'});
		$('#bottom div.right').find('h4').css({'font-size': '17px'});
		return false;
	});
	
	$("#suggestlink").click(function () {
		if (!suggestformdiv) {
			suggestformdiv = $(document.createElement('div')).load('./?suggest=1&url=' + location, function() {  });
		}
		suggestformdiv.dialog({ 
			modal: true, title: 'Seite Empfellen', width: 600, height: 400,
			buttons: {
				"Empfellung senden": function() {
					suggestformdiv.find('form').submit();
				},
				"Abbrechen": function() { suggestformdiv.dialog( "close" ); }
			}
		});
		return false;
	});
	if (params['os']) {
		$("#suggestlink").click();
	}
	if (params['ds']) {
		$(document.createElement('div')).load('./?suggest=1&sent=1', function() { 
			$(this).dialog({ 
				modal: true, title: 'Seite Empfellen', width: 300, height: 150,
				buttons: { "Fertig": function() { $( this ).dialog( "close" ); } }
			});
		})
	}
	$('#pagenotfound').dialog({ 
		modal: true, title: '404 Seite nicht gefunden', width: 500, height: 150,
		buttons: { "OK": function() { $( this ).dialog( "close" ); } }
	});


	//--- newsletterseting needed?
	$("#newsletterprogress").each(function () {
		init_newslettersending(this.className);
	});
});

var divexits = [];
function divexit(id, func) {
	divexits[id] = func;
	setTimeout('divexittimedout(\'' + id + '\');', 150);
}
function divexittimedout(id) {
	if (divexits[id]) {
		var func = divexits[id];
		divexits[id] = null;
		func(id);
	}
}
function divcancelexit(id) {
	divexits[id] = null;
}


var myframe_uid = false;
var lastpopupopened_uid = false;
var disableclosingpopup = false;

var nextpopupid = 1;
var popupsopener = [];
var popupimagespreloaded = false;
//--- open interface popup function
function openpopup(uid, url, width, height, title, icon, helplink, openeruid) {
	//--- already inside a popup?
	if (isiniframe) {
		window.top.openpopup(uid, url, width, height, title, icon, helplink, myframe_uid);
		return false;
	}
	if (!openeruid) openeruid = lastpopupopened_uid;
	popupsopener[uid] = openeruid;

	if ($('#popup_'+uid)) {	$('#popup_'+uid).remove(); }
	if ($('#popupbox_'+uid)) { $('#popupbox_'+uid).remove(); }
	
	//--- 1. create the overlay container div
	var mainoverlaydiv = $(document.createElement('div'));
	mainoverlaydiv.attr('id', 'popup_' + uid);
	mainoverlaydiv.css({
		'display': 'none',
		'position': 'fixed',
		'left': '0',
		'top': '0',
		'width': '100%',
		'height': '100%',
		'opacity': 0.8,
		'background-color': '#CCCCCC',
		'z-index': 9999 + nextpopupid++,
		'cursor': 'pointer'
	});
	mainoverlaydiv.click(function () { closepopup(uid); });
	$('body').append(mainoverlaydiv);


	var totalwidth = width + 2 * 14;
	var totalheight = height + 34 + 14;

	var boxleft = parseInt( (mainoverlaydiv.width() / 2) - (totalwidth / 2) );
	var boxtop = parseInt( (mainoverlaydiv.height() / 2) - (totalheight / 2) );

	//--- 2. create the box itself as a second div
	var boxcontainerdiv = $(document.createElement('div'));
	boxcontainerdiv.attr('id', 'popupbox_' + uid);
	boxcontainerdiv.css({
		'display': 'none',
		'position': 'fixed',
		'left': boxleft,
		'top': boxtop,
		'width': totalwidth,
		'height': totalheight,
		'z-index': 9999 + nextpopupid++
	});
	$('body').append(boxcontainerdiv);

	//--- borders of the box
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_tl').css({ 'position': 'absolute', 'top': 0, 'left': 0, 'width': 14, 'height': 34, 'background-image': 'url(/images/admin/popup/border_tl.png)'}));
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_t').css({ 'position': 'absolute', 'top': 0, 'left': 0 + 14, 'width': width, 'height': 34, 'background-image': 'url(/images/admin/popup/border_t.png)'}));
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_tr').css({ 'position': 'absolute', 'top': 0, 'left': 0 + 14 + width, 'width': 14, 'height': 34, 'background-image': 'url(/images/admin/popup/border_tr.png)'}));

	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_l').css({ 'position': 'absolute', 'top': 0 + 34, 'left': 0, 'width': 14, 'height': height, 'background-image': 'url(/images/admin/popup/border_l.png)'}));
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_r').css({ 'position': 'absolute', 'top': 0 + 34, 'left': 0 + 14 + width, 'width': 14, 'height': height, 'background-image': 'url(/images/admin/popup/border_r.png)'}));

	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_bl').css({ 'position': 'absolute', 'top': 0 + 34 + height, 'left': 0, 'width': 14, 'height': 15, 'background-image': 'url(/images/admin/popup/border_bl.png)'}));
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_b').css({ 'position': 'absolute', 'top': 0 + 34 + height, 'left': 0 + 14, 'width': width, 'height': 15, 'background-image': 'url(/images/admin/popup/border_b.png)'}));
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_br').css({ 'position': 'absolute', 'top': 0 + 34 + height, 'left': 0 + 14 + width, 'width': 14, 'height': 15, 'background-image': 'url(/images/admin/popup/border_br.png)'}));

	//--- close link
	boxcontainerdiv.append($(document.createElement('a')).addClass('popup_close').css({ 'position': 'absolute', 'display': 'block', 'top': 0 + 11, 'left': 0 + 14 + width + 3 - 16, 'width': 16, 'height': 16, 'text-decoration': 'none'}).attr('href', 'javascript: closepopup(\''+uid+'\')').append($(document.createElement('img')).css({'width': 16, 'height': 16, 'border': 0}).attr('src', '/images/admin/popup/close.png')));

	//--- icon
	icon = icon ? '/images/admin/popup/icons/'+icon : '/images/admin/popup/icons/default.png';
	boxcontainerdiv.append($(document.createElement('img')).addClass('popup_icon').css({ 'position': 'absolute', 'display': 'block', 'top': 0 + 11, 'left': 0 + 11, 'width': 16, 'height': 16, 'border': 0}).attr('src', icon));

	//--- help link
	if (helplink) {
		boxcontainerdiv.append($(document.createElement('a')).addClass('popup_icon').css({ 'position': 'absolute', 'display': 'block', 'top': 0 + 11, 'left': 0 + 14 + width + 3 - 16 - 3 - 16, 'width': 16, 'height': 16, 'text-decoration': 'none'}).attr('href', helplink).append($(document.createElement('img')).css({'width': 16, 'height': 16, 'border': 0}).attr('src', '/images/admin/popup/help.png')));
	}

	//--- title row
	boxcontainerdiv.append($(document.createElement('div')).addClass('popup_title').css({ 'position': 'absolute', 'display': 'block', 'top': 0 + 11, 'left': 0 + 11 + 3 + 16, 'width': width - 50, 'height': 16, 'overflow': 'hidden', 'text-align': 'left', 'font-size': 12, 'color': '#333333', 'font-family': 'Arial, sans-serif'}).html(title));

	//--- container
	var containerdrame = $(document.createElement('iframe'));
	containerdrame.addClass('popup_container');
	containerdrame.attr('frameborder',  0);
	containerdrame.attr('marginwidth',  0);
	containerdrame.attr('marginheight',  0);
	containerdrame.attr('scrolling',  'auto');
	containerdrame.css({ 'position': 'absolute', 'top': 0 + 34, 'left': 0 + 14, 'width': width, 'height': height, 'background-color': '#FFFFFF', 'border': 0});
	boxcontainerdiv.append(containerdrame);

	mainoverlaydiv.fadeIn(300, function() {
		lastpopupopened_uid = uid;
		if (popupimagespreloaded) {
			boxcontainerdiv.show();
			popup_loadcontents(uid, url);
		} else {
			$.loadImages([
				'/images/admin/popup/border_tl.png',
				'/images/admin/popup/border_t.png',
				'/images/admin/popup/border_tr.png',
				'/images/admin/popup/border_l.png',
				'/images/admin/popup/border_r.png',
				'/images/admin/popup/border_bl.png',
				'/images/admin/popup/border_b.png',
				'/images/admin/popup/border_br.png',
				'/images/admin/popup/close.png'
			], function() { popupimagespreloaded = true; boxcontainerdiv.show(); popup_loadcontents(uid, url); } )
		}
	});

	return false;
}

function popup_resize(uid, width, height) {
	//--- already inside a popup?
	if (isiniframe) {
		window.top.popup_resize(uid, width, height);
		return;
	}

	var mainoverlaydiv = $('#popup_' + uid);
	var maincontainer = $('#popupbox_' + uid);
	if (!maincontainer || !mainoverlaydiv) return;

	var totalwidth = width + 2 * 14;
	var totalheight = height + 34 + 14;

	var boxleft = parseInt( (mainoverlaydiv.width() / 2) - (totalwidth / 2) );
	var boxtop = parseInt( (mainoverlaydiv.height() / 2) - (totalheight / 2) );

	maincontainer.css({'top': boxtop, 'left': boxleft, 'width': totalwidth, 'height': totalheight});
	maincontainer.find('.popup_t').css({'width': width});
	maincontainer.find('.popup_tr').css({'left': 0 + 14 + width});

	maincontainer.find('.popup_l').css({'height': height});
	maincontainer.find('.popup_r').css({'left': 0 + 14 + width ,'height': height});

	maincontainer.find('.popup_bl').css({'top': 0 + 34 + height});
	maincontainer.find('.popup_b').css({'top': 0 + 34 + height, 'width': width});
	maincontainer.find('.popup_br').css({'left': 0 + 14 + width, 'top': 0 + 34 + height});

	maincontainer.find('.popup_close').css({'left': 0 + 14 + width + 3 - 16});
	maincontainer.find('.popup_help').css({'left': 0 + 14 + width + 3 - 16 - 3 - 16});

	maincontainer.find('.popup_container').css({'width': width, 'height': height});
}

function popup_reload(uid) {
	//--- already inside a popup?
	if (isiniframe) {
		window.top.popup_reload(uid);
		return;
	}

	lastpopupopened_uid = uid;

	var maincontainer = $('#popupbox_' + uid);
	if (!maincontainer.size()) return;

	var datacontainer = maincontainer.find('.popup_container');
	datacontainer[0].contentWindow.location.reload(true);
}

function popup_loadcontents(uid, newurl, newwidth, newheight, newtitle, newicon, newhelplink) {
	//--- already inside a popup?
	if (isiniframe) {
		window.top.popup_loadcontents(uid, newurl, newwidth, newheight, newtitle, newicon, newhelplink);
		return;
	}

	var maincontainer = $('#popupbox_' + uid);
	if (!maincontainer) return;

	var datacontainer = maincontainer.find('.popup_container');
	datacontainer.contents().find('html body').html('&nbsp;');

	//--- resize needed?
	if ((newwidth && datacontainer.width() != newwidth) || (newheight && datacontainer.height() != newheight)) {
		popup_resize(uid, newwidth, newheight);
	}

	//--- new title?
	if (newtitle) {
		maincontainer.find('.popup_title').html(newtitle);
	}

	//--- new icon?
	if (newicon) {
		maincontainer.find('.popup_icon').attr('src', '/images/admin/popup/icons/'+icon);
	}

	//--- put loading image
	var loadingimage = $(document.createElement('img'));
	loadingimage.attr('src', '/images/layout/loading_new.gif');
	loadingimage.css({ 'position': 'absolute', 'display': 'block', 'top': maincontainer.height() / 2 - 8, 'left': maincontainer.width() / 2 - 52, 'width': 105, 'height': 16, 'border': 0, 'opacity': 0.7});
	maincontainer.append(loadingimage);

	//--- load the iframe
	datacontainer.attr('src', newurl);

	datacontainer.load(function () {
		loadingimage.remove();
		datacontainer.show();
	});
}


function closepopup(uid, reloadme) {
	//--- closing popups disabled?
	if (window.top.disableclosingpopup) {
		return;
	}
	//--- called from inside a popup?
	if (isiniframe) {
		window.top.closepopup(uid, reloadme);
		return;
	}

	if (uid) {
		if ($('#popupbox_'+uid)) {
			$('#popupbox_'+uid).hide();
			//--- remove tinymce editor here!!
		}
		if ($('#popup_'+uid)) {
			$('#popup_'+uid).fadeOut();
		}

		if (popupsopener[uid]) {
			if (reloadme) popup_reload(popupsopener[uid]);
		} else {
			if (reloadme) window.location.reload();
		}
	} else {
		if (lastpopupopened_uid) {
			closepopup(lastpopupopened_uid, reloadme);
		}
	}
}

//--- admin control layers
function showAdminControl(controlid) {
	hideAllAdminControls(controlid);
	$('#'+controlid).show();
}

function hideAdminControl(controlid) {
	$('#'+controlid).hide();
}

function hideAllAdminControls(except) {
	$('div.admincontrol').each(function () {
		if (this.id != except) {
			$(this).hide();
		}
	});
	$('div._admincontrol').each(function () {
		if (this.id != except) {
			$(this).hide();
		}
	});
}


function slideshow_move(plsorminus) {
	var wemove = $('#slides');
	if (wemove.width() <= 290) {
		return;
	}

	var howmuch = 200;
	var remainderright = wemove.width() + wemove.position().left - 290;
	if (plsorminus == -1 && howmuch > remainderright) {
		howmuch = remainderright;
	}
	if (plsorminus == 1 && howmuch > - wemove.position().left) {
		howmuch = - wemove.position().left;
	}
	if (howmuch == 0) {
		return;
	}

	var movestring = '' + (plsorminus == -1 ? '-' : '+') + '=' + howmuch;
	wemove.animate({
		left: movestring
	}, 500, function() {});
}
function slideshw_showslide(picid) {
	$('#slides > a > img').each(function(index) {
		$(this).css({opacity: 1});
	});
	$('#picture_'+picid).css({opacity: 0.25});
	$('#previewimage').attr('src', './?showmediimage=' + picid);
}

function etoggle(whoid) {
	$('#'+whoid).toggle();
}
function formSubmit(f) { 
	var form = $('body');

	var formoverlay = $(document.createElement('div'));
	formoverlay.css({ 'position': 'absolute', 'display': 'none', 'top':0, 'left': 0, 'width': form.width(), 'height': $(document).height(), 'background-color': '#FFFFFF', 'opacity': 0.8});
	form.append(formoverlay);

	var loadingimage = $(document.createElement('img'));
	loadingimage.attr('src', '/images/layout/loading_new.gif');
	loadingimage.css({ 'position': 'absolute', 'display': 'block', 'top': $(document).height() / 2 - 8, 'left': form.width() / 2 - 52, 'width': 105, 'height': 16, 'border': 0, 'opacity': 0.7});
	formoverlay.append(loadingimage);

	formoverlay.fadeIn('fast');

	return false;
}
function popup(url, name, w, h) {
	window.open(url, name, 'width='+w+',height='+h+',menubar=no,scrollbars=no,toolbars=no');
}

function mcvrt(f) {
	var i = f.innerHTML;
	if (!i)	{
		return;
	}

	i = i.replace(/ at /i, '@');
	i = i.replace(/ dot /i, '.');

	f.innerHTML = i;
}


function init_newslettersending(newsletter) {
	window.top.disableclosingpopup = true;
	newslettersending_nextstep(newsletter);
}
function newslettersending_error(error) {
	window.top.disableclosingpopup = false;
	$('#newsletterprogress').hide();
	$('#newslettererrormessage').html(error + '<br><br>');
	$('#newslettererror').show();
}
function newslettersending_nextstep(newsletter) {
	var url = './?action=sendnewsletter&sub=send&newsletter=' + newsletter;
	$.ajax({
		url				: url,
		type			: 'GET',
		parameters:		{ },

		success			: function(content) {
			var result = null, sent = 0, total = 0;

			result = /<error>(.+?)<\/error>/.exec(content);
			if (result && result[1]) {
				newslettersending_error(result[1]);
				return;
			}


			result = /<sent>(.+?)<\/sent>/.exec(content);
			if (result && result[1]) sent = parseInt(result[1]);
			result = /<total>(.+?)<\/total>/.exec(content);
			if (result && result[1]) total = parseInt(result[1]);

			if (sent > 0 && total > 0) {
				if (sent >= total) {
					$('#newsletterprogress').hide();
					$('#newsletterdone').show();
					window.top.disableclosingpopup = false;
				} else {
					$('#sent').html(sent);
					$('#total').html(total);
					newslettersending_nextstep(newsletter)
				}
			} else {
				newslettersending_error('Invalid reponse from server.');
			}
		},
		error			: function() { 
			newslettersending_error('Conneciton to the server was not possible.');
		}
	});
}



(function($){
    //cache needed for overagressive garbage collectors.
    var cache = [];
    //images can either be an array of paths to images or a  single image. 
    $.loadImages = function(images, callback){
    
        //convert to array if needed so rest of script works
        if (!(images instanceof Array)) {
            images = [images];
        }
        
        var imagesLength = images.length;
        var loadedCounter = 0;
        
        for (var i = imagesLength; i--;) {
			var cacheImage = document.createElement('img');
			//set the onload method before the src is called otherwise will fail to be called in IE
            cacheImage.onload = function(){
                loadedCounter++;
                if (loadedCounter >= imagesLength) {
                    if ($.isFunction(callback)) {
                        callback();
                    }
                }
            }
            cacheImage.src = images[i];
            cache.push(cacheImage);
        }
    }
})(jQuery);


(function($) {
	if(!document.defaultView || !document.defaultView.getComputedStyle){ // IE6-IE8
		var oldCurCSS = jQuery.curCSS;
		jQuery.curCSS = function(elem, name, force){
			if(name === 'background-position'){
				name = 'backgroundPosition';
			}
			if(name !== 'backgroundPosition' || !elem.currentStyle || elem.currentStyle[ name ]){
				return oldCurCSS.apply(this, arguments);
			}
			var style = elem.style;
			if ( !force && style && style[ name ] ){
				return style[ name ];
			}
			return oldCurCSS(elem, 'backgroundPositionX', force) +' '+ oldCurCSS(elem, 'backgroundPositionY', force);
		};
	}
	
	var oldAnim = $.fn.animate;
	$.fn.animate = function(prop){
		if('background-position' in prop){
			prop.backgroundPosition = prop['background-position'];
			delete prop['background-position'];
		}
		if('backgroundPosition' in prop){
			prop.backgroundPosition = '('+ prop.backgroundPosition;
		}
		return oldAnim.apply(this, arguments);
	};
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	
	$.fx.step. backgroundPosition = function(fx) {
		if (!fx.bgPosReady) {
			var start = $.curCSS(fx.elem,'backgroundPosition');
			
			if(!start){//FF2 no inline-style fallback
				start = '0px 0px';
			}
			
			start = toArray(start);
			
			fx.start = [start[0],start[2]];
			
			var end = toArray(fx.options.curAnim.backgroundPosition);
			fx.end = [end[0],end[2]];
			
			fx.unit = [end[1],end[3]];
			fx.bgPosReady = true;
		}
		//return;
		var nowPosX = [];
		nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
		nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
		fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

	};
})(jQuery);
