// JavaScript Document
function pageload(hash, target, source, callback, history, color) {
	if (!target) 
		target = '.content';
	if (!source) 
		source = '.content';
	if (!callback) 
		callback = 'void(0);';
	if(hash) {
		if ( hash != GUI.hash_test) {
			GUI.hash_test = hash;
			color = $("body").css("background-color");
			color2 = $("#main").css("background-color");
			GUI.load(hash, target, source, callback, 'no');
		};
	} else {
		// start page
		$("#load").empty();
	};
};
cGUI = function(){
	this.changeBg = function(target, color, time){
		if (!target) 
			target = 'body';
		if (!color) 
			color = '#1B1F06';
		if (!time) 
			time = '1000';
		$(target).animate({
			backgroundColor: color
		}, time);		
	};
	this.load = function(url, source, target, callback, history){
		if (!target) 
			target = '.content';
		if (!source) 
			source = '.content';
		if (!callback) 
			callback = 'void(0);';
		if (!history) 
			history = 'yes';
		if (history != 'no') {
			url = url.replace(/^.*#/, '');
			$.historyLoad(url, target, source, callback, history);
			return;
		};
		$("#content_container").css({opacity:0.7});
		$("#content_container").append("<img src='../themes/images/throbber.gif' id='throbber' style='position:absolute; top:220px; left:200px;'/>");
		$.post(url, function(data){
				$(target).html($(data).find(source).html());
				eval(callback);
				$("#throbber").remove();
				$("#content_container").animate({opacity:1},1000);
			}
		);
		//GUI.pageInit();
	};
	this.initPage = function(color, color2) {
		sIFR.replace(helve, {
			selector: 'h1',
			css: [
					'.sIFR-root {color:#B2B19D; font-size:30px; height:20px; overflow:hidden;}'
				],
			onReplacement: function(){
					 $('.content h1').css({
					 	"height":"40px",
						"overflow":"hidden"
					 });
			 }
		});
		/*if (!GUI.color) {
			GUI.color = $("body").css("background-color");
		};
		if (!color2) {
			GUI.color2 = $("#main").css("background-color");
		};*/
		$("#formular").css({height:"15px", cursor: "pointer"});
		setTimeout("$('#scroll').jScrollPane();",100);
		$(".content img").load(function () {
		    $('#scroll').jScrollPane();
			//setTimeout('GUI.changeBg(".jScrollPaneDrag", color2, 1000);',2000);
//			GUI.changeBg('.jScrollPaneTrack', color2, 1000);
    	});
		$("#formular a").unbind()
		$("#formular a").bind("click",
			function() {
				if ( GUI.test_form == 0 ) {
					GUI.test_form = 1;
					$(this).parent().animate({height:"190px"}, function() {$('#scroll').jScrollPane();});
					return false;
				}
				else {
					GUI.test_form = 0;
					$(this).parent().animate({height:"15px"}, function() {$('#scroll').jScrollPane();});
					return false;
				};
				
			}
		);
		$(".content a").click(
			function(){
				if ($(this).attr("href") && $(this).attr("target") != "_blank" && $(this).attr("class") != "form_a" && $(this).attr("class") != "ruka"){
					if( $(this).attr("rel")) {
							$("#menu li a.active").removeClass("active");
							$($(this).attr("rel")).addClass("active");
					};
					GUI.load($(this).attr("href"),".content",".content","GUI.initPage();");
					return false;
				};
				
			}
		);
	};
	this.customize = function(stranka,x,y) {    
		var address = "../../system/img.php?img="+stranka;   
		var op_tool  = 0;    
		var op_loc_box  =  0;    
		var op_dir  =  0;    
		var op_stat  =  0;    
		var op_menu  =  0;    
		var op_scroll  =  0;    
		var op_resize  = 0;    
		var op_wid  = x;   
		var op_heigh = y;                 
		var option = "toolbar="+ op_tool +",location="+ op_loc_box +",directories=" 
		+ op_dir +",status="+ op_stat +",menubar="+ op_menu +",scrollbars="  
		+ op_scroll +",resizable="  + op_resize +",width=" + op_wid +",height="+ op_heigh;
		//var win3 = window.open("", "what_I_want", option);  
		var win4 = window.open(address, "xx",option);
		return false;
		
	};
	this.curClass = "";
	this.test_form = 0;
	this.test_a = 0;
	this.hash_test = 0;
};
var GUI = new cGUI();
$(
	function(){
		$.historyInit(pageload);
		GUI.initPage();
		$("#menu li a").click(
			function(){			
				if ( $(this).attr("class") && $(this).attr("class") != GUI.curClass ) {
					classa = $(this).attr("class");
					color = '#' + $(this).attr("class");
					color2 = '#' + $(this).attr("name");
					GUI.changeBg("body", color, 1000);
					GUI.changeBg("#main", color2, 1000);
					$("#flash").fadeOut("slow",
										function(){
											$("#flash").css({"background":"url(../themes/images_ch/"+ classa +".jpg) no-repeat 0 0"}).fadeIn("slow");
											}
										);//
					GUI.curClass = $(this).attr("class");
				};
				$("#menu li a.active").removeClass("active");
				$(this).addClass("active");
				if ($(this).attr("href")){
					GUI.load($(this).attr("href"),".content",".content","GUI.initPage(color, color2);");
				};
				return false;
			}
		);
	}
);

