var idelement_focused='';
var right_col_visible=true;
var double_col_width=245;
var triple_col_width=229;
var window_loaded=false;
var horizontal_spacer_short=573;
var horizontal_spacer_long=780;
var gsp_processing=Array();


function isMaxLength(obj){ //maxlength 4 textareas
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if(obj.getAttribute && obj.value.length+1>mlength) return false;
}

function isMaxLength_validated(obj, e, regexp){ //maxlength 4 textareas with input validation
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""

	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31 && obj.getAttribute && obj.value.length<mlength) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	} else {
		return false;
	}

}

function input_validator(e, regexp) {
	if(navigator.userAgent.indexOf('Gecko') != -1) charCode = e.which; else charCode = e.keyCode;
	if(charCode > 31) {
		znak = String.fromCharCode(charCode);
		return regexp.test(znak);
	}
}

function get_url_params() {
	var idx=document.URL.indexOf('?');
	var url_params=new Array();
	if(idx!=-1) {
		var pairs=document.URL.substring(idx+1,document.URL.length).split('&');
		for(var i=0; i<pairs.length; i++) {
			nameVal=pairs[i].split('=');
			url_params[nameVal[0]]=nameVal[1];
	   }
	}
	return url_params;
}

function ulubione(title,url){
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if(window.opera && window.print) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	} else if(document.all) {
		window.external.AddFavorite(url,title);
	}
}

function check_email(forma) {
	if(forma.email.value.length > '0') {
		var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
		var wynik = re.test(forma.email.value);
		if (wynik == false) {
			alert('Nieprawidłowy adres E-mail!');
			forma.email.focus();
			return false;
		}
	} else {
		alert('Podaj adres E-mail!');
		forma.email.focus();
		return false;
	}
}



function show_hide(list) {
	var listElementStyle=document.getElementById(list).style; 
	listElementStyle.display = (listElementStyle.display=="none" ? "inline" : "none");
}

function show_hide_block(list) {
	var listElementStyle=document.getElementById(list).style; 
	listElementStyle.display = (listElementStyle.display=="none" ? "block" : "none");
}


function link_potwierdzenie(link,pytanie) {
	if(window.confirm(pytanie)==true) window.location=link;
}


function search() {
	var szukaj=document.getElementById('s').value
	if(szukaj.length>0 && szukaj!=" ") {
		document.main_szukaj.submit();
		return true;
	}
}


function toggleRows(kat_id,man_id){
	var cont=document.getElementById('sortable');
	var disp;

	if(document.getElementById('sortable').nodeName=='TABLE') {
		var len=cont.rows.length;

		for(i=1; i<len; i++) {
			if(cont.rows[i].id!='m_'+man_id && man_id!="") disp="none"; else disp="";
			cont.rows[i].style.display=disp;
		}
   } else {
		var len=cont.childNodes.length;
		for(var i=0; i<len; i++) {
			if(cont.childNodes[i].nodeName=="DIV") {
				if(cont.childNodes[i].id!='m_'+man_id && man_id!="") disp="none"; else disp="";
				cont.childNodes[i].style.display=disp;
         }
		}
	}

	document.getElementById('sort_link_nazwa').href=document.getElementById('sort_link_nazwa').rel+'_'+man_id;
	document.getElementById('sort_link_cena').href=document.getElementById('sort_link_cena').rel+'_'+man_id;

//	rows_setCookie("pcm_manuf_"+kat_id, man_id, 1);
}

function auto_toggleRows(kat_id) {
	var state=rows_getCookie("pcm_manuf_"+kat_id);
	if(rows_getCookie!="") {
		toggleRows(kat_id,state);
		if(document.getElementById('producenci')) {
			var sel=document.getElementById('producenci');
			for(var i=0; i<sel.options.length; i++) {
		      if(sel.options[i].value==state) {
					sel.selectedIndex=i;
					break;
				}
			}
      }
//		rows_clearCookie("pcm_manuf_"+kat_id);
	}
}


function manufacturer(man_id, custom_link){
	var cont=document.getElementById('sortable');
	var disp;

	if(document.getElementById('sortable').nodeName=='TABLE') {
		var len=cont.rows.length;

		for(i=1; i<len-1; i++) {
			if(cont.rows[i].id!='m_'+man_id && man_id!="") disp="none"; else disp="";
			cont.rows[i].style.display=disp;
		}
   } else {
		var len=cont.childNodes.length;
		for(var i=0; i<len; i++) {
			if(cont.childNodes[i].nodeName=="DIV") {
				if(cont.childNodes[i].id!='m_'+man_id && man_id!="") disp="none"; else disp="";
				cont.childNodes[i].style.display=disp;
         }
		}
	}

	if(document.getElementById('producenci')) {
		var sel=document.getElementById('producenci');
		for(var i=0; i<sel.options.length; i++) {
	      if(sel.options[i].value==man_id) {
				sel.selectedIndex=i;
				break;
			}
		}
	}

	if(man_id!="" && man_id!=undefined) {
		if(custom_link!="" && custom_link!=undefined) { // ? &
			post_man_id="&manuf_id="+man_id;
			post_man_id_print="&manuf_id="+man_id+'&print=tak';
		} else { // _
			post_man_id="_"+man_id;
			post_man_id_print="_"+man_id+'/print/';
		}
	} else {
		post_man_id="";
		post_man_id_print="";
	}

	$('#sort_link_nazwa').attr('href', $('#sort_link_nazwa').attr('rel')+post_man_id);
	$('#sort_link_cena').attr('href', $('#sort_link_cena').attr('rel')+post_man_id);
	$('#sort_link_dost').attr('href', $('#sort_link_dost').attr('rel')+post_man_id);

	$('#switch_link_icon').attr('href', $('#switch_link_icon').attr('rel')+post_man_id);
	$('#switch_link_list').attr('href', $('#switch_link_list').attr('rel')+post_man_id);
	$('#print_link').attr('href', $('#print_base_url').val()+post_man_id_print);
}

function ukryj_menu2() {
	if($("#menu_hider").length==0) return false;

	if(right_col_visible==true) { //hide
		$("#right_col").hide();
		$("#hidden_cart").show();
		$("#center_col").css('width','768px');
		modify_listing(3);
		right_col_visible=false;
		$('#menu_hider').attr('class','menu_hider_left').attr('title','Pokaż menu');
		$('#menu_hider_caption').html('Pokaż menu');
		rows_setCookie('right_menu_hide',1);
	} else { //show
		modify_listing(2);
		right_col_visible=true;
		$("#center_col").css('width','546px');
		$("#right_col").show();
		$("#hidden_cart").hide();
		$('#menu_hider').attr('class','menu_hider_right').attr('title','Schowaj menu');
		$('#menu_hider_caption').html('Schowaj menu');
		rows_setCookie('right_menu_hide',0);
	} 
}

menu_anim_progress=0;
function ukryj_menu() {
	if(menu_anim_progress==1) return false;
	menu_anim_progress=1;
	cursor('wait');

	if(right_col_visible==true) { //hide
		$("#right_div").animate({'width':'0px'}, 250);
		$("#right_column").animate({'width':'0px'}, 250, function(){
			$("#right_div").css('width','1px');
			$("#right_column").css('width','1px');
			$('#menu_hider').attr('class','menu_hider_left').title='Pokaż menu';
			$('#menu_hider_caption').html('Pokaż menu');
			modify_listing(3);
			$('#horizontal_spacer').css('width',horizontal_spacer_long+"px");
			right_col_visible=false;
			cursor('default');
			menu_anim_progress=0;
		});
	} else { //show
		var base_width=211;
		$('#horizontal_spacer').css('width',horizontal_spacer_short+"px");
		$("#right_div").animate({'width':base_width}, 250);
		$("#right_column").animate({'width':base_width}, 250, function(){
			$('#menu_hider').attr('class','menu_hider_right').title='Schowaj menu';
			$('#menu_hider_caption').html('Schowaj menu');
			modify_listing(2);
			right_col_visible=true;
			cursor('default');
			menu_anim_progress=0;
		});
	} 
}

function wyloguj() {
	modal_confirm('<b>Na pewno chcesz się wylogować?</b><br /><br /><br /><br />', function(){
		$.ajax({
			url: '/includes/forms.php?SID='+$('#SID').val()+"&form_name=wyloguj",
			type: 'post',
			dataType: 'script',
			cache: false,
			error: function(request) { alert('AJAX: Server connection error!'); }
		});
	});
}

function compare_selected() {
	var count=0;
	var url='';
	var allCHs=document.getElementsByTagName("input");
	for(x=0;x<=allCHs.length-1;x++) {
		var ch_check=allCHs.item(x).id.search("compare_");
		if(ch_check!=-1) { 
			if(allCHs.item(x).checked==true) {
				count++;
				real_id=allCHs.item(x).id.replace('compare_','');
				url+=real_id+'-';
			}
		}
	}
	if(count<2) {
		alert('Musisz wybrać przynajmniej 2 produkty do porównania!');
	} else {
		window.open('/porownaj/'+url.substring(0,url.length-1));
	}
}

function compare_selected2() {
	var count=0;
	var url='';
	var allCHs=document.getElementsByTagName("input");
	for(x=0; x<=allCHs.length-1; x++) {
		var ch_check=allCHs.item(x).id.search("compare_");
		if(ch_check!=-1) { 
			if(allCHs.item(x).checked==true) {
				count++;
				real_id=allCHs.item(x).id.replace('compare_','');
				url+=real_id+'-';
			}
		}
	}
	if(count<2) {
		alert('Musisz zostawić przynajmniej 2 produkty!');
	} else {
		window.location='/porownaj/'+url.substring(0,url.length-1);
	}
}


function cmp_click(id) {
	$('#compare_'+id).click();
}

function compare_clear() {
	var count=0;
	var url='';
	var allCHs=document.getElementsByTagName("input");
	for(x=0; x<=allCHs.length-1; x++) {
		var ch_check=allCHs.item(x).id.search("compare_");
		if(ch_check!=-1) { 
			allCHs.item(x).checked=false;
		}
	}
}


function toggleVis_hide(btn,name){
	cells = document.getElementsByName('t'+btn);
	for(j=0; j<cells.length; j++) cells[j].style.display='none';

	document.getElementById('ukryte').style.display='block';
	document.getElementById('ukryte').innerHTML+='<span id="ukryte_'+btn+'">Pokaż produkt: <a href="javascript:void(0)" name="'+btn+'" onclick="toggleVis_show(this.name)"><b>'+name+'</b></a><br /></span>';
}


function toggleVis_show(btn){
	var showMode = 'table-cell';
	if(navigator.appName=="Microsoft Internet Explorer") showMode='block';

	cells = document.getElementsByName('t'+btn);
	for(j = 0; j < cells.length; j++) cells[j].style.display=showMode;

	remove_html_element('ukryte','ukryte_'+btn);

	if(document.getElementById('ukryte').innerHTML=="") document.getElementById('ukryte').style.display='none';
}


function table_highlight(klasa_tabeli,kolor_over,head,foot) {
	if(head>0) ii=head; else ii=0;
	if(foot>0) iii=foot; else iii=0;

	for(var i=0; i<document.getElementsByTagName('table').length; i++) { 
		if(document.getElementsByTagName('table')[i].className==klasa_tabeli) {
			for(var j=0+ii; j<document.getElementsByTagName('table')[i].getElementsByTagName('tr').length-iii; j++) {
				if(document.getElementsByTagName('table')[i].getElementsByTagName('tr')[j].getElementsByTagName('th').length==0) {
					document.getElementsByTagName('table')[i].getElementsByTagName('tr')[j].onmouseover=function() { this.style.backgroundColor=kolor_over; }; 
					document.getElementsByTagName('table')[i].getElementsByTagName('tr')[j].onmouseout=function()  { this.style.backgroundColor='';	};
				}
			}                       
		}
	}
}

function remove_html_element(parent_id, child_id) {
	var master_node=document.getElementById(parent_id);
	var len=master_node.childNodes.length;

	for(var i=0; i<len; i++) {
		if(master_node.childNodes[i].id==child_id) {
			master_node.removeChild(master_node.childNodes[i]);
		}
	}
}

function resize_col(direction) {
   var resizeby=150;
	var w=document.getElementById('compare_tbl').offsetWidth;

	if(direction=='+') document.getElementById('compare_tbl').style.width=w+resizeby;
	if(direction=='-') document.getElementById('compare_tbl').style.width=w-resizeby;
}


var koszyk_in_progress=0;
function koszyk(action,id,ilosc,no_scroll_up,view_only,no_link,target_div) {
	if(koszyk_in_progress==1) return false;
	koszyk_in_progress=1;
	$("#"+target_div).css('opacity',0.4);

	if(right_col_visible==false) {
		if(typeof(window["HDD"])!="undefined") ukryj_menu2(); else ukryj_menu();
	}
	if(action=='kup' && no_scroll_up!=true) {
		if(typeof(window["HDD"])!="undefined") {
			$.scrollTo("276px", 200);
		} else {
			$.scrollTo("216px", 200);
		}
	}

	$.ajax({
		url : "/includes/koszyk.php?SID="+$('#SID').val()+"&view_only="+view_only+"&no_link="+no_link,
		data: "action="+action+"&id="+id+"&ilosc="+ilosc+"&target_div="+target_div,
		type: 'post',
		dataType: 'html',
		cache: false,
		error: function(request) { alert('AJAX: Server connection error!'); },
		success: function(response) {
			$("#"+target_div).html(response);
			koszyk_in_progress=0;
			$("#"+target_div).css('opacity',1);

			if(action=='kup' && no_scroll_up!=true) $("#"+target_div).fadeOut(100).fadeIn(100);

			if(response.indexOf('<!-- check_popup() -->')!=-1) check_popup();
		}
	});
}

function koszyk_q(id,state,target_div) {
	if(target_div=='zamowienie') var no_link=true; else var no_link='';

	if(state==1) {
		document.getElementById('produkt_ilosc_ok_'+id).style.display='block';
		document.getElementById('produkt_ilosc_'+id).select();
	}

	if(state==0) {
		var ile_old=document.getElementById('produkt_ilosc_'+id).name;
		var ilosc=document.getElementById('produkt_ilosc_'+id).value;
		if(ilosc==0 || ilosc=='') {
			if(window.confirm('Chcesz usunąć ten produkt?')) {
	         koszyk('usun',id,'','','',no_link,target_div);
			} else {
				document.getElementById('produkt_ilosc_'+id).value=ile_old;
			}
		} else {
         koszyk('kup',id,ilosc,true,'',no_link,target_div);
		}
		document.getElementById('produkt_ilosc_ok_'+id).style.display='none';
		document.getElementById('produkt_ilosc_'+id).blur();
	}
}

function edytuj_koszyk() {
	$('#zamowienie_navi').css('display','none');
	koszyk('','','','','','true','zamowienie');
}

function show_popup(msg) {
	modal_info(msg);
}

function check_popup() {
	$.ajax({
		url: "/includes/ajax_popup.php?SID="+$('#SID').val(),
		type: 'post',
		dataType: 'script',
		cache: false,
		error: function(request) { alert('AJAX: Server connection error!'); }
	});
}

function cursor(c) {
	document.getElementsByTagName('body').item(0).style.cursor=c;
}


function modify_listing(ile) {
	if(document.getElementById('sortable')) {
		if(document.getElementById('sortable').nodeName=='DIV') {
			var master_node=document.getElementById('sortable');
			var len=master_node.childNodes.length;

			for(var i=0; i<len; i++) {
				if(master_node.childNodes[i].nodeName=='DIV') {
					div=master_node.childNodes[i];

			      if(ile==3) div.className="d_prod2";
			      if(ile==2) div.className="d_prod";
	         }
			}
		}
   }
}

function set_prod_style_width(w) {
	if(document.getElementById('sortable')) {
		var master_node=document.getElementById('sortable');
		var len=master_node.childNodes.length;

		for(var i=0; i<len; i++) {
			master_node.childNodes[i].style.width=w+"px";
		}
   }
}


function changeCSS(theClass,element,value) {
	var cssRules;
	if (document.all) {
		cssRules = 'rules';
	} else if (document.getElementById) {
		cssRules = 'cssRules';
	}
	for(var S = 0; S < document.styleSheets.length; S++) {
		for(var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if(document.styleSheets[S][cssRules][R].selectorText == theClass) {
				document.styleSheets[S][cssRules][R].style[element] = value;
			}
		}
	}	
}


function check_all(link,id,len) {
	for(var i=0; i<len; i++) {
		chk=document.getElementById(id+'[]'+i);
		chk.checked=true;
	}
	link.blur();
}

function uncheck_all(link,id,len) {
	for(var i=0; i<len; i++) {
		chk=document.getElementById(id+'[]'+i);
		chk.checked=false;
	}
	link.blur();
}


function onload_preload_img() {
	function preloadImages() {
		for (i=0;i<preloadImages.arguments.length;i++) {
			myimages[i]=new Image();
			myimages[i].src=preloadImages.arguments[i];
		}
	}
	var myimages=new Array();

	preloadImages(
		"gfx/plus.gif",
		"gfx/minus.gif",
		"includes/js/jquery.modal/header.gif",
		"includes/js/jquery.modal/header_hdd.gif"
	);
}

function rows_setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/";
}

function rows_getCookie(c_name) {
	if(document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1) c_end=document.cookie.length;
//alert(document.cookie);
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function rows_clearCookie(c_name) {
	expiredays=1;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()-expiredays);
	document.cookie=c_name+ "=''"+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/";
}


function update_zamowienie_komentarz(val) {
	$.ajax({
		url: "/includes/ajax_zamowienie_komentarz.php?SID="+$('#SID').val(),
		data: "zamowienie_komentarz="+val,
		type: 'post',
		dataType: 'script',
		cache: false,
		error: function(request) { alert('AJAX: Server connection error!'); }
	});
}


var lokalizacja_typ=0;
function lokalizacja(typ) {
	lokalizacja_typ=typ;
	if(typ==1) {
		$('#dl1_data').css('display','block');
		$('#dl2_data').css('display','none');
		$('#dl3_data').css('display','none');
	}

	if(typ==2) {
		$('#dl1_data').css('display','none');
		$('#dl2_data').css('display','block');
		$('#dl3_data').css('display','none');
	}

	if(typ==3) {
		$('#dl1_data').css('display','none');
		$('#dl2_data').css('display','none');
		$('#dl3_data').css('display','block');
	}
}


window.onload=function() {
	window_loaded=true;
	setTimeout("onload_preload_img()",2000);
}


/////////////////////////////////////////////////////////////////////////////

jQuery.fn.aForm = function(options) {
	options = options || {};
	
	$(this).bind("submit", function() {
		if(options.in_progress==1) return false;
		post_form(this);
		return false;
	});


	function post_form(forma) {
		options.in_progress=1;
		$(forma).parent().css('opacity',0.4);

		$.ajax({
			url: 'includes/forms.php?SID='+$('#SID').val()+'&form_name='+$(forma).attr('id'),
			data: $(forma).serialize(),
			type: 'post',
			dataType: 'script',
			cache: false,
			error: function(request) { alert('AJAX: Server connection error!'); },
			success: function(response) {
				options.in_progress=0;
				$(forma).parent().css('opacity',1);
			}
		});
	}
}




function ajax(target,method,action,param1,param2,param3,param4,param5,param6,param7,param8,param9,param10) {
	if(action=='get_search_params') {
		var chbox=document.getElementById(target.replace('c_',''));
		gsp_processing[target.replace('c_','')]='';
	}

	if(action=='get_search_params') chbox.disabled=true;

	$.ajax({
		url: '/includes/ajax.php?SID='+$('#SID').val(),
		data: "action="+action+"&param1="+param1+"&param2="+param2+"&param3="+param3+"&param4="+param4+"&param5="+param5+"&param6="+param6+"&param7="+param7+"&param8="+param8+"&param9="+param9+"&param10="+param10,
		type: 'post',
		dataType: 'html',
		cache: false,
		error: function(request) { alert('AJAX: Server connection error!'); },
		success: function(response) {
			if(method=='replace') {
	         if(action=='get_search_params') {
	            if(gsp_processing[target.replace('c_','')]!='stop') {
						$('#'+target).html(response);
	               chbox.disabled=false;
               }
				} else {
	            $('#'+target).html(response);
				}
			}
			if(method=='add') 			$('#'+target).html($('#'+target).html()+response);
			if(method=='alert')			alert(response);

			if(action=='var2session') proceed2search();
		}
	});
}



function gsp(param_id,param_value) {
	if(document.getElementById(param_id).checked!=true) {
		$('#c_'+param_id).html('');
	} else {
		var kat_id=$('#get_kat_id').val();
		$('#c_'+param_id).html('<div style="height:17px"><img src="gfx/loading_small.gif" width="16" height="16" alt="" style="vertical-align:middle; margin-right:5px;" /><a href="#" onclick="gsp_stop(&quot;'+param_id+'&quot;); return false;"><b>przerwij</b></a></div>');
		ajax('c_'+param_id,'replace','get_search_params',param_id,param_value,kat_id);
	}
}

function gsp_stop(param_id) {
	gsp_processing[param_id]='stop';
	$('#c_'+param_id).html('');

	var chbox=document.getElementById(param_id);
	chbox.disabled=false;
	chbox.checked=false;
}

function form2session(ses_name,ses_value) {
	ajax('','','var2session',ses_name,ses_value);
}

function save_search_data() {
	if($('#ajax_search_link').html()=="") {
		$('#ajax_search_link').html('<div style="height:17px"><img src="gfx/loading_small.gif" width="16" height="16" alt="" style="border:1px solid #CCCCCC" /></div>');
		ajax('ajax_search_link','replace','save_search_data');
		$('#ajax_search_link_link').html('');
   }
}

function usun_produkty() {
	$('#prod_top').show();
	$('#prod_link').hide();
	$('#prod_update').show();
}


var xhr_produkt;
function sprawdz_dostepnosc(elem,id,ch) {
	modal_window('<b>Proszę czekać...</b><br />Trwa sprawdzanie dostępności produktu:<br /><br /><b class="red" style="font-size:14px;">'+$("#produkt_title").html()+'</b><br /><br /><div class="response"><br /></div>');

	xhr_produkt = $.ajax({
		url: '/includes/online_status.php?SID='+$('#SID').val(),
		data: "id="+id+"&ch="+ch,
		type: 'post',
		dataType: 'script',
		cache: false,
		error: function(request) { alert('AJAX: Server connection error!'); },
		success: function(response) {}
	});
}


$(document).ready(function(){
	if(rows_getCookie("right_menu_hide")==1) ukryj_menu2();
});


//$.scrollTo()
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);