// lpanel.js
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
var show_menu = readCookie('show_menu') ? readCookie('show_menu') : 1;

// 





var maxWidth = 995; /* 995 */
var minWidth = 652; /*  */
// 0 = spis treci, 1 = pdf menu
var what = readCookie('show_menu_mode') ? readCookie('show_menu_mode') : 0;
var visible = show_menu;
var panel = "#flp_main";
var grafika = "#graph_scrolls";
var text = "#pop_art";
var tekst = "#text";

	function showUl(target) {
		jQuery(target).next('ul').show()
		jQuery(target).removeClass('down');
		jQuery(target).addClass('up');
	};
	function hideUl(target) {
		jQuery(target).next('ul').hide();
		jQuery(target).removeClass('up');
		jQuery(target).addClass('down');					
	};
jQuery(document).ready(function () {
	if ($.browser.mozilla) {
		jQuery('body').css("overflow-y","scroll");
	};

	// funkcje 
	var iever = false;
	if ($.browser.msie && ((parseInt(jQuery.browser.version)) <= 6 )) {
		iever = true;
	};

	function showShow () {
		if (iever) {
			jQuery("#show").show();
		} else {
			jQuery("#show").fadeIn("fast");
		};
	};
	function showPanel() {
		if (iever) {
			jQuery(panel).show();					
		} else {
			jQuery(panel).fadeIn("fast");					
		};
	};

	function pokazuj() {

		showPanel();
		jQuery(grafika).width(minWidth);
		jQuery(text).width(minWidth - 60);
		visible = true;
		createCookie('show_menu', 1,14);
	};
	function chowaj() {
		jQuery(panel).hide();
		jQuery(grafika).width(maxWidth);
		jQuery(text).width(maxWidth - 60);
		visible = false;
		createCookie('show_menu', 0,14);
	};
	// start
	
	if (visible == true) {
		pokazuj();
		// hide & show
		jQuery("#ico_hidepanel").toggle(function() {
			chowaj();
			jQuery(this).attr("title", "Pokaż lewy panel");
		}, function() {
			pokazuj();
			jQuery(this).attr("title", "Ukryj lewy panel");
		});
	} else {
		chowaj();
		// hide & show
		jQuery("#ico_hidepanel").toggle(function() {
			pokazuj();
			jQuery(this).attr("title", "Ukryj lewy panel");
		}, function() {
			chowaj();
			jQuery(this).attr("title", "Pokaż lewy panel");
		});
	};
	
	// specyfic for wprost
	
	jQuery('#flp_txt ul').hide();

	jQuery('#flp_txt h3').click(function() {
										 	
											 if (jQuery(this).hasClass('down') ==  true) {
												 showUl(this);
											 } else {
												 hideUl(this);
											 };
										 });
	if (jQuery('#flp_txt ul li.active')) {
		var target = jQuery('#flp_txt ul li.active').parent('ul').prev('h3');
		showUl(target);
	};
	

	jQuery('#pdfs div').hide();
	jQuery('#pdfs h3 a').toggle(function() {
			jQuery(this).parent().next('div').show();
			jQuery(this).parent().removeClass('down');
			jQuery(this).parent().addClass('up');
		}, function() {
			jQuery(this).parent().next('div').hide();
			jQuery(this).parent().removeClass('up');
			jQuery(this).parent().addClass('down');
		});
	
	
	var s = "" + document.location;
	var arr = s.match(/#(header_\d+)$/);
	if( arr !== null ){
		showUl(document.getElementById(arr[1]));
	}
});
function setblWidth() {
	var imgWidth = jQuery("#pdfimg").width() + 70;
	var imgHeight = jQuery("#pdfimg").height();
	jQuery("#kjp_area").width(imgWidth);
	jQuery("#kjp_area").height(imgHeight);
	if ($.browser.opera && (jQuery("#pdfimg").length > 0)) {		
		if (imgWidth < 250) {
			setblWidth();
		};
	};	

};
function hidePreloader() {
	doc = document.getElementById( 'preloader' );
	if( doc != null )
	{
		doc.style.display = 'none';
		document.getElementById( 'kjp_area' ).style.display = 'block';
	}
};