$(document).ready(function(){
	ENABLE_ANIMATIONS=true;

	if(ENABLE_ANIMATIONS==true) {
		menu_t1=350;
		menu_t2=250;
		menu_easing='easeOutQuart';
	} else {
		menu_t1=menu_t2=0;
		menu_easing=false;
	}

	//MENU
	$("#left_menu li a.submenu").bind('click', function() {
		$(this).parent().find("ul").toggle(menu_t1,menu_easing);
		$(this).parent().siblings().find("ul").hide(menu_t2,menu_easing);
		return false;
	});


	//GO TOP
	$("#bottom_bg a")
		.css('opacity', 0.3)
		.hover(function() {
			$(this).css('opacity', 0.75);
		}, function() {
			$(this).css('opacity', 0.3);
		});


	//CHECK-ALL
	$('#del_on_list_sel_all').click(function(){ $(this).parent().parent().parent().parent().find("input.del_on_list").attr('checked', $(this).is(':checked')); });
	$('#del_on_list_bottom_sel_all').click(function(){ $(this).parent().parent().parent().parent().parent().parent().parent().find("input.del_on_list").attr('checked', !$('#del_on_list_sel_all').is(':checked')); });


	//IMAGE PREVIEW
	$("a.box_img").colorbox({'title':false, overlayClose:true, fixed:false, img:true, contentClose:true});


	//TABS
	/*
	$('div.mainbox_tabs a').bind('click',function() {
		$(this).parent().find("a").removeClass('sel');
		$(this).addClass('sel');
		tab = $(this).attr('href');
		$(tab).siblings().hide();
		$(tab).show();
		return false;
	});
	*/

});


function question(question, confirm_url, ajax) {
	if(ajax==true) {
		callback=function() { $.ajax({url: confirm_url, dataType:'script'}); }
	} else {
		callback=function() { go(confirm_url); }
	}

	html 	='<div id="cboxContentPadd">'+question+'<div id="cboxContentPadd_spacer"></div></div>'
			+'<div id="cboxContentButtons">'
			+'		<a href="#" class="yes button"><span class="ico w_yes"></span></a>'
			+'		<a href="#" class="no button button_gray"><span class="ico w_no"></span></a>'
			+'</div>';

	$.colorbox({
		'title': 'Pytanie',
		'html': html,
		enterKey: true,
		onConfirmed: callback
	});
	return false;

	/*
	$(".group1").colorbox({rel:'group1'});
	$(".group2").colorbox({rel:'group2', transition:"fade"});
	$(".group3").colorbox({rel:'group3', transition:"none", width:"75%", height:"75%"});
	$(".group4").colorbox({rel:'group4', slideshow:true});
	$(".ajax").colorbox();
	$(".youtube").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	$(".iframe").colorbox({iframe:true, width:"80%", height:"80%"});
	$(".inline").colorbox({inline:true, width:"50%"});
	$(".callbacks").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
		onConfirmed: function() { alert('ok!'); }
		onCanceled: function() { alert('cancel!'); }
	});
	*/
}


function return_question(question, callback) {
	html 	='<div id="cboxContentPadd">'+question+'<div id="cboxContentPadd_spacer"></div></div>'
			+'<div id="cboxContentButtons">'
			+'		<a href="#" class="yes button"><span class="ico w_yes"></span></a>'
			+'		<a href="#" class="no button button_gray"><span class="ico w_no"></span></a>'
			+'</div>';

	$.colorbox({
		'title': 'Pytanie',
		'html': html,
		enterKey: true,
		onConfirmed: callback
	});
}


function notif(type, message, time) {
	if(time==undefined || time=="") time=2500;

	$("#right").prepend('<div id="notif_cont_'+type+'" class="notif notif_'+type+'"><span class="ico i_'+type+'"></span>'+message+'</div>');

	setTimeout(function(){
		$("div.notif_"+type).fadeOut(250,function(){ $(this).remove(); });
	}, time);
	$("div.notif_"+type).click(function(){ $(this).fadeOut(250,function(){ $(this).remove(); }); });
}

function save_as_draft(elem) {
	if($("div.save_as_draft_cont").length==0) return false;
	form=$(elem).parents('form');
	if(form.find('draft').length==0) form.append('<input type="hidden" name="draft" value="1" id="draft" style="display:none" />');
	form.find('draft').val('1');
	form.unbind('submit').attr("action","");
	form.submit();
}



function shortcut_add(elem, shortcut_id) {
	$.colorbox({
//		'transition': 'elastic',
		'href': 'includes/ajax/shortcut.php?SID='+SID+'&shortcut_id='+(shortcut_id!=undefined ? shortcut_id:"")+'&url='+encodeURIComponent(window.location)+'&title='+encodeURIComponent($("div.mainbox_header_navi h3").text())
	});
	return false;
}

function shortcut_choose_icon(elem, path, icon) {
	$(elem).parent().find('a').removeClass('sel');
	$(elem).addClass('sel');
	$(elem).closest('form').find('#icon').val(icon);
	$('#shortcut_icon_preview img').attr('src',path+icon).show();
}

var shortcut_edit_state=0;
function shortcut_edit(elem) {
	var selectors=$("#shortcuts_sort div, #top_shortcuts_left, #top_shortcuts_right");
	if(shortcut_edit_state==0) {
		selectors.dragsort({dragSelector:"span.img", dragBetween:true, dragEnd:function(){
			loc=$(this).parent().attr('id');
			if(loc=='top_shortcuts_left' || loc=='top_shortcuts_right') {
				$(this).find('img').attr('src', $(this).find('img').attr('src').replace('/large/','/large_preview/').replace('.png','.jpg'));
				$(this).find('img').attr('src', $(this).find('img').attr('src').replace('/large/','/large_preview/').replace('.png','.jpg'));
				$("#top_shortcuts_left input[type='hidden']").attr("name","row_7[]");
				$("#top_shortcuts_right input[type='hidden']").attr("name","row_8[]");

				$.post('includes/ajax/shortcut.php?SID='+SID+'&action=sort', $("#top_shortcuts_sort").serialize());
			} else {
				$(this).find('img').attr('src', $(this).find('img').attr('src').replace('/large_preview/','/large/').replace('.jpg','.png'));
				for(i=1; i<=6; i++) $("#shortcuts_row_"+i+" input[type='hidden']").attr("name","row_"+i+"[]");
				$.post('includes/ajax/shortcut.php?SID='+SID+'&action=sort', $("#shortcuts_sort").serialize());
			}
		}});
		$("div.shortcuts").addClass("shortcuts_edit");
		selectors.find("a").bind("click", function(){ return false; });
		selectors.find("a").addClass("edit");
		selectors.find("a span.action_edit").show();
		selectors.find("a span.action_del").show();

		shortcut_edit_state=1;
		$(elem).find("span.edit_label").html("Zakończ edycję");
		$(elem).find("span.ico").removeClass("b_edit").addClass("b_ok");
	} else {
		$("div.shortcuts").removeClass("shortcuts_edit");
		selectors.dragsort("destroy");
		selectors.find("a").unbind("click");
		selectors.find("a").removeClass("edit");
		selectors.find("a span.action_edit").hide();
		selectors.find("a span.action_del").hide();

		shortcut_edit_state=0;
		$(elem).find("span.edit_label").html("Edytuj skróty");
		$(elem).find("span.ico").removeClass("b_ok").addClass("b_edit");
	}
}

function shortcut_del(elem, shortcut_id) {
	question('Na pewno usunąć skrót?', 'includes/ajax/shortcut.php?SID='+SID+'&action=del&shortcut_id='+shortcut_id, true);
}

function table_sort(table_id,module,parent_id) {
	$("#table_"+table_id+" tbody").tableDnD({
		onDrop: function(table, row) {
			$.ajax({
				url: "includes/ajax/table_sort.php?SID="+SID+"&table="+table_id+"&module="+module+"&parent_id="+parent_id,
				data: $("table.listing").tableDnDSerialize(),
				type: "post",
				cache: false
			});
		}
	});
}


function ajax_input(type, crc, module, table, col, id, val) {
	$.ajax({ type: "post", cache: false,
		url: "includes/ajax/ajax_input.php?SID="+SID,
		data: "type="+type+"&crc="+crc+"&table="+table+"&module="+module+"&col="+col+"&id="+id+"&val="+encodeURIComponent(val)
	});
}


function tip(elem, text, on_target, off_x, off_y, extra_class, forceToLeft) {
	if(text==-1) { $(elem).poshytip('disable').poshytip('destroy'); return true; }

	if($(elem).attr("start_hide")!=1) {
		if(on_target==1) {
			$(elem).poshytip({
				content: 			text,
				classNameExtra:	(extra_class!=null ? extra_class : ""),
				showOn: 				'hover',
				alignTo: 			'target',
				cursorViewport: 	true,
				alignX: 				'inner-left',
				alignY: 				'top',
				offsetX: 			(off_x!=null ? off_x : 0),
				offsetY: 			(off_y!=null ? off_y : 7),
				forceToLeft:		(forceToLeft!=null ? forceToLeft : "")
			});
		} else {
			$(elem).poshytip({
				content: 			text,
				classNameExtra:	(extra_class!=null ? extra_class : ""),
				showOn: 				'hover',
				alignTo: 			'cursor',
				cursorViewport: 	true,
				alignX: 				'inner-right',
				alignY: 				'top',
				offsetX: 			(off_x!=null ? off_x : 16),
				offsetY: 			(off_y!=null ? off_y : 16),
				forceToLeft:		(forceToLeft!=null ? forceToLeft : "")
			});
		}
	}
	$(elem).attr("start_hide",0);

	$(elem).mouseout(function(){
		$(elem).attr("start_hide",1);
		setTimeout(function(){
			if($(elem).attr("start_hide")==1) {
				$(elem).poshytip('disable').poshytip('destroy');
				$(elem).removeAttr("start_hide",0);
			}
		},25)
	});
	setTimeout(function(){ $(elem).poshytip('show'); }, 10);
}


function left_menu_toggle() {
	$("body").toggleClass('left_hidden');
	setTimeout(function(){ $("#left_menu_toggle_link").toggleClass('hidden'); },75);
	$.cookie('left_menu_hidden', ($.cookie('left_menu_hidden')!=1 ? 1:0));
}







var iEditor_root_top=0, jcrop_api, img_constr, jcrop_src, jcrop_first_load, jcrop_in_temp, jcrop_temp_form, jcrop_temp_field, jcrop_save;

function image_editor(form_id, field_name, file, temp) {
	iEditor_root_top=$(window).scrollTop();
	$("#root").hide();
	if($("#image_editor").length==0) $("body").append('<div id="image_editor" />');
	$("body").addClass("image_editor");

	jcrop_in_temp=(temp=true ? true : false);
	jcrop_temp_form=form_id;
	jcrop_temp_field=field_name;

	$.getScript('/libs/js/jquery.jcrop/jcrop.min.js', function() {
		$.get('includes/ajax/image_editor.php?_='+(new Date).getTime()+'&jcrop_in_temp='+(jcrop_in_temp==true ? 1+'&jcrop_temp_form='+jcrop_temp_form+'&jcrop_field_name='+jcrop_temp_field : 0)+'&src='+urlencode(file), function(data) {
			$("#image_editor").html(data);

			php_img=$("#image_editor_area img").attr('src').split('?');
			jcrop_src=urlencode(php_img[0]);

			$("#image_editor_loading").show();
			$("#image_editor_toolbar").hide();

			$('#ori_w').val("0");
			$('#ori_h').val("0");
			$('#jcrop_x').val(0);
			$('#jcrop_y').val(0);
			$('#jcrop_x2').val(0);
			$('#jcrop_y2').val(0);
			$('#jcrop_w').val(0);
			$('#jcrop_h').val(0);
			$('#resize_w').val("");
			$('#resize_h').val("");

			jcrop_first_load=true;
			initJcrop();

			$(document).bind('keypress', function(e) { if(e.keyCode==27) imageEditorClose(); });
		});
	});
}

function imageEditorClose() {
	jcrop_api.destroy();
	$("#image_editor").remove();
	$("body").removeClass("image_editor");
	$("#root").show();
	$(window).scrollTop(iEditor_root_top);
	$(document).unbind('keypress');
}


function initJcrop() {
	$('#image_editor_area img').Jcrop({
		bgOpacity: .6,
		onChange: showCoords,
		onSelect: showCoords
	}, function(){
		jcrop_api=this;

		if(jcrop_save==true) {
			jcrop_first_load=true;
			jcrop_save=false;
			imageEditorClose();
			return false;
		}

		new_img=$('#image_editor_area img');
		w=new_img.width();
		h=new_img.height();
		$('#resize_w').val(w);
		$('#resize_h').val(h);
		$('#resize_w_base').val(w);
		$('#resize_h_base').val(h);
		img_constr=(w/h);

		$("#image_editor_loading").hide();
		$("#image_editor_toolbar").show();
	});
}

function showCoords(c) {
	$('#jcrop_x').val(c.x);
	$('#jcrop_y').val(c.y);
	$('#jcrop_x2').val(c.x2);
	$('#jcrop_y2').val(c.y2);
	$('#jcrop_w').val(c.w);
	$('#jcrop_h').val(c.h);
	$('#resize_w').val($('#resize_w_base').val());
	$('#resize_h').val($('#resize_h_base').val());
}

function calcImgResize(src,elem){
	jcrop_api.release();
	$('#jcrop_w').val("0");
	$('#jcrop_h').val("0");
	$('#jcrop_x').val("0");
	$('#jcrop_y').val("0");
	$('#jcrop_x2').val("0");
	$('#jcrop_y2').val("0");


	val=$(elem).val();
	if(src=='w') {
		val2=parseInt(val/img_constr);
		$("#resize_w").val(parseInt(val));
		$("#resize_h").val(val2);
	} else {
		val2=parseInt(val*img_constr);
		$("#resize_w").val(val2);
		$("#resize_h").val(parseInt(val));
	}

	if($("#resize_w").val()=="NaN" || $("#resize_w").val()=="0") $("#resize_w").val("");
	if($("#resize_h").val()=="NaN" || $("#resize_h").val()=="0") $("#resize_h").val("");
}


function processImageResize(form){
	if($('#resize_w').val()==$('#resize_w_base').val() || $('#resize_h').val()==$('#resize_h_base').val()) return false;

	$('#resize_w').blur();
	$('#resize_h').blur();
	w=parseInt($('#resize_w').val());
	h=parseInt($('#resize_h').val());
	if($('#resize_w').val().length==0 || $('#resize_h').val().length==0) {
		$('#resize_w').focus();
		$(form).find('.submit').removeClass('button_dis').removeAttr('disabled');
		return false;
	}

	$("#image_editor_loading").show();
	$("#image_editor_toolbar").hide();
	$("#resize_w").val("");
	$("#resize_h").val("");
	$("#image_editor_area").html('<img src="includes/ajax/image_editor_process.php?_='+(new Date).getTime()+'&action=resize&w='+w+'&h='+h+'&jcrop_first_load='+(jcrop_first_load==true ? 1:0)+'&jcrop_in_temp='+(jcrop_in_temp==true ? 1+'&jcrop_temp_form='+jcrop_temp_form+'&jcrop_field_name='+jcrop_temp_field : 0)+'&src='+jcrop_src+'" alt="" />');
	jcrop_first_load=false;
	$("#image_save_as").show();
	$(form).find('.submit').removeClass('button_dis').removeAttr('disabled');

	initJcrop();
	return false;
}


function callback_crop_start() { processImageCrop(jcrop_temp_form); }
function processImageCrop(form){
	x=parseInt($('#jcrop_x').val());
	y=parseInt($('#jcrop_y').val());
	x2=parseInt($('#jcrop_x2').val());
	y2=parseInt($('#jcrop_y2').val());
	if((x==0 && y==0 && x2==0 && y2==0) || (x==x2 && y==y2)) {
		jcrop_api.animateTo([0, 0, $("#resize_w_base").val()+1, $("#resize_h_base").val()+1]);
		$(form).find('.submit').removeClass('button_dis').removeAttr('disabled');
		return false;
	}

	if(x==0 && y==0 && x2==$("#resize_w_base").val() && y2==$("#resize_h_base").val()) {
		$(form).find('.submit').removeClass('button_dis').removeAttr('disabled');
		return false;
	}

	if(x==x2 && y==y2) {
		$(form).find('.submit').removeClass('button_dis').removeAttr('disabled');
		return false;
	}


	$("#image_editor_loading").show();
	$("#image_editor_toolbar").hide();

	$("#image_editor_area").html('<img src="includes/ajax/image_editor_process.php?_='+(new Date).getTime()+'&action=crop&x='+x+'&y='+y+'&x2='+x2+'&y2='+y2+'&jcrop_first_load='+(jcrop_first_load==true ? 1:0)+'&jcrop_in_temp='+(jcrop_in_temp==true ? 1+'&jcrop_temp_form='+jcrop_temp_form+'&jcrop_field_name='+jcrop_temp_field : 0)+'&src='+jcrop_src+'" alt="" />');
	jcrop_first_load=false;
	$("#image_save_as").show();
	$(form).find('.submit').removeClass('button_dis').removeAttr('disabled');

	initJcrop();
	$("#jcrop_w").val("0");
	$("#jcrop_h").val("0");
	$('#jcrop_x').val("0");
	$('#jcrop_y').val("0");
	$('#jcrop_x2').val("0");
	$('#jcrop_y2').val("0");

	return false;
}


function image_save(form) {
	$("#image_editor_area").html('<img src="includes/ajax/image_editor_process.php?_='+(new Date).getTime()+'&action=save&jcrop_in_temp='+(jcrop_in_temp==true ? 1+'&jcrop_temp_form='+jcrop_temp_form+'&jcrop_field_name='+jcrop_temp_field : 0)+'&src='+jcrop_src+'" alt="" />');
	jcrop_save=true;
	initJcrop();
}




//////////////////////////////////////////////////////////////////////
$(window).resize(function(){ auto_resize(); });
$(document).ready(function(){
	auto_resize();
	setInterval(function(){ $.ajax({ type:"get", cache:false, url:"includes/ajax/session_maintain.php?SID="+SID }); }, 5*60*1000);
});


function go(url) { window.location=url; return false; }
function on_screen(elem) { docViewTop=$(window).scrollTop(); docViewBottom=docViewTop+$(window).height(); elemTop=$(elem).offset().top; elemBottom=elemTop+$(elem).height(); return ((elemTop+((elemBottom-elemTop)/2))>=docViewTop && ((elemTop+((elemBottom-elemTop)/2))<=docViewBottom)); }
function row_hover(elem) { $(elem).addClass("hover"); elem.onmouseout=function() { $(this).removeClass("hover"); } }
function auto_resize() { h=$(window).height(); $("table.root").css("height", h+"px"); $.cookie('table_root_last_height', h); }

function sub_check_all(elem) { checked_all=($(elem).attr('checked_all')=='true' ? true:false); $(elem).attr('checked_all',!checked_all); $(elem).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked',!checked_all); }
function sub_check_all_hover(elem) { z=$(elem).parent().parent().parent().parent().find("td.del span"); z.css('opacity',0.4); $(elem).mouseout(function(){ z.css('opacity',1); }) }


function do_batch_action(elem) {
	if($("#batch_action").val()=="") return false;
	chx=$(elem).parent().parent().parent().parent().parent().parent().parent().parent().find('input.del_on_list:checked');
	if(chx.length==0) return false;
	return_question('Na pewno wykonać tą akcję dla zaznaczonych elementów? <br /><br /><b>('+chx.length+')</b>', function(){
		$.each(chx, function(index,elem){ $("#batch_form").append('<input type="hidden" name="batch[]" value="'+$(elem).val()+'" style="display:none" />'); });
		$("#batch_form").submit();
	});
}


function sortable_del_row(el,callback) {
	rows=$(el).closest('tbody').find('> tr');
	if(rows.length>1) { //del row
		$(el).closest('tr').remove();
	} else { //clear
		$(el).closest('tr').find('input').val("");
	}

	if(callback!=undefined && callback!="") {
		callback.call(el);
	}
}

function sortable_add_row(el,callback,skip_focus) {
	table=$(el).closest('table');
	tbody=table.find('tbody');
	clone=tbody.find(' > tr:first').clone();

	last_row_id=parseInt(table.attr('last_row_id'));
	table_id=table.attr('id').replace('_sortable','');
	table.attr('last_row_id',++last_row_id);
	/////

	clone.html(clone.html().replace(new RegExp('\\[[0-9]+\\]', 'g'), '['+last_row_id+']').replace(new RegExp('___[0-9]+', 'g'), '___'+last_row_id+''));


	clone.find('td.drag2sort input').val(last_row_id);

	clone.find(':text').val('');
	clone.find('textarea').val('');
	clone.find('checkbox').removeAttr('checked');
	clone.find('radio').removeAttr('checked');
	clone.find('select').val('');

	/////
	tbody.append(clone);
	tbody.tableDnD();
	focus_elem=tbody.find(' > tr:last td:first').next().find('input:first,textarea:first,select:first');

	if(callback!=undefined && callback!="") {
		callback.call(this, tbody.find(' > tr:first'), tbody.find(' > tr:last'), last_row_id);
	}
	if(skip_focus!=true) focus_elem.focus();
}



(function($) {
	$.fn.delay = function(time,func){ this.each(function(){ setTimeout(func,time); }); return this; };
	$.cookie = function(name,value,options){ if(typeof value!='undefined') { options = options||{}; if(value === null) { value=''; options.expires=-1; } var expires=''; if(options.expires && (typeof options.expires=='number' || options.expires.toUTCString)) { var date; if(typeof options.expires=='number') { date=new Date(); date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); } else { date = options.expires; } expires='; expires='+date.toUTCString(); } var path=options.path ? '; path='+(options.path):''; var domain=options.domain ? '; domain='+(options.domain):''; var secure = options.secure ? '; secure':''; document.cookie=[name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); } else { var cookieValue=null; if(document.cookie && document.cookie!='') { var cookies=document.cookie.split(';'); for(var i=0; i<cookies.length; i++) { var cookie=$.trim(cookies[i]); if(cookie.substring(0, name.length+1)==(name+'=')) { cookieValue=decodeURIComponent(cookie.substring(name.length+1)); break; } } } return cookieValue; }};
	(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?300: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);

	$.extend({
		str_replace: function(from,to,s) { if(typeof(from)=='object' || typeof(to)=='object') { if(from.length==to.length) { for(i=0; i<from.length; i++) { s=s.replace(new RegExp("\\"+from[i], 'g'), to[i]); } return s; } } return s.replace(new RegExp("\\"+from, 'g'), to); },
		striptags: function(s) { return this.s(s).replace(/<\/?[^>]+>/gi, ''); }
	});
}(jQuery));


function log(text) { if(typeof console!=="undefined") { console.log(text); } else { $("#log").append(text+" "); } }
function print_r (array, return_val) { var output = '', pad_char = ' ', pad_val = 4, d = this.window.document, getFuncName = function (fn) { var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn); if (!name) { return '(Anonymous)'; } return name[1]; }, repeat_char = function (len, pad_char) { var str = ''; for (var i = 0; i < len; i++) { str += pad_char; } return str; }, formatArray = function (obj, cur_depth, pad_val, pad_char) { if (cur_depth > 0) { cur_depth++; } var base_pad = repeat_char(pad_val * cur_depth, pad_char); var thick_pad = repeat_char(pad_val * (cur_depth + 1), pad_char); var str = ''; if (typeof obj === 'object' && obj !== null && obj.constructor && getFuncName(obj.constructor) !== 'PHPJS_Resource') { str += 'Array\n' + base_pad + '(\n'; for (var key in obj) { if (Object.prototype.toString.call(obj[key]) === '[object Array]') { str += thick_pad + '[' + key + '] => ' + formatArray(obj[key], cur_depth + 1, pad_val, pad_char); } else { str += thick_pad + '[' + key + '] => ' + obj[key] + '\n'; } } str += base_pad + ')\n'; } else if (obj === null || obj === undefined) { str = ''; } else { str = obj.toString();}  return str; };  output = formatArray(array, 0, pad_val, pad_char);  if (return_val !== true) { alert(output); return true; } return output; }
function nl2br (str, is_xhtml) { return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2'); }
function time() { return Math.floor(new Date().getTime()/1000); }
function microtime(get_as_float) { var now = new Date().getTime() / 1000; var s = parseInt(now, 10); return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s; }
function urlencode (str) { str=(str+'').toString(); return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+'); }
function urldecode(str) { return decodeURIComponent(str.replace(/\+/g, '%20')); }