// JavaScript Document
 var panel_dont_slide = 0;
//

function mcr_resize_area(ta_id) {
 var alines = countlines(document.getElementById(ta_id));
// document.getElementById(ta_id).rows = alines+2;
// document.getElementById('reply_form').style.height = 80 + alines*13 +'px';
// document.getElementById('form1').style.height = 110 + alines*13 +'px';
}
var winW = 0;
var winH = 0;
var winHc = 0;
var winWc = 0;
var menu_slideH = 1600;
	var winHcp = winH;
	var winWcp = winW;
	var mainContentOpen = 0;
function mcr_window_resize() {

 if (parseInt(navigator.appVersion)>3) {

 if (navigator.appName.indexOf("Microsoft")!=-1) {
 winW = document.body.offsetWidth;
 winH = document.body.offsetHeight;
 } else {
 winW = window.innerWidth;
 winH = window.innerHeight;
 }

 }
 document.getElementById('top_menu').style.left = (winW/2)-410+'px' ;
 document.getElementById('main_content').style.left = (winW/2)-400+'px' ;
 
 document.getElementById('mcr_head_container').style.left = (winW/2)+140+'px' ;
 document.getElementById('mcr_logo').style.left = (winW/2)-480+'px' ;
 document.getElementById('mcr_loading').style.left = (winW/2)-50+'px' ;
  document.getElementById('mcr_loading').style.top = (winH/2)-50+'px' ;
	center_buttons();
}
function mcr_centerX(widthW) {
 if (widthW < winW) {
 	var trgX = (winW - widthW)/2 ;
 } else {
 	var trgX = 0 ;
 }
 return trgX;
}
function mcr_centerY(heightH) {
 if (heightH < winH) {
	 var trgY = (winH - heightH)/2 ;
 } else {
 	var trgY = 0 ;
 }
 return trgY;
}

var menu_open = 0;
function center_buttons(){
	if ( menu_open != 1 ) {
	document.getElementById('but_01').style.left = 21 + (winW/2)- 420+'px';
	document.getElementById('but_02').style.left = 286 + (winW/2)- 420+'px';
	document.getElementById('but_03').style.left = 286 + (winW/2)- 420+'px';
	document.getElementById('but_04').style.left = 466 + (winW/2)- 420+'px';
	document.getElementById('but_05').style.left = 587 + (winW/2)- 420+'px';	
	document.getElementById('but_06').style.left = 528 + (winW/2)- 420+'px';		
		if (winH > 720) {
			document.getElementById('but_01').style.top = 282 +'px';
		document.getElementById('but_02').style.top = 232 +'px';
		document.getElementById('but_03').style.top = 409 +'px';
		document.getElementById('but_04').style.top = 284 +'px';
		document.getElementById('but_05').style.top = 163 +'px';	
		document.getElementById('but_06').style.top = 409 +'px';
		} else {
			var Hadd = 50;
		document.getElementById('but_01').style.top = 282 - Hadd +'px';
		document.getElementById('but_02').style.top = 232 - Hadd +'px';
		document.getElementById('but_03').style.top = 409 - Hadd +'px';
		document.getElementById('but_04').style.top = 284 - Hadd +'px';
		document.getElementById('but_05').style.top = 163 - Hadd +'px';	
		document.getElementById('but_06').style.top = 409 - Hadd +'px';
		}
	}
}
function show_smenu(but){
	var slideH = menu_slideH ;
	  winHcp = winH;
 	  winWcp = winW;
 $('#but_01').animate({'left': '-='+slideH+'px'}, '600');
 $('#but_02').animate({'left': '-='+slideH+'px'}, '700');
 $('#but_03').animate({'left': '-='+slideH+'px'}, '800');
 $('#but_04').animate({'left': '+='+slideH+'px'}, '600');
  $('#but_05').animate({'left': '+='+slideH+'px'}, '700');
 $('#but_06').animate({'left': '+='+slideH+'px'}, '800');   
 $('#top_menu').animate({'top': '+=100px'}, '800');   
 menu_open = 1;
 	winHc = 0;
		
	  document.getElementById('main_content').style.visibility = 'visible';
	  document.getElementById('main_content').style.display = "none";
	//setTimeout("$('#main_content').animate({'top': '+=800px'}, '800');",600);	 
	mainContentOpen = 1;
	set_topic(but);
// document.getElementById('but_01').style.left = mcr_centerX(440)+200+'px';
// document.getElementById('but_01').style.top = mcr_centerY(800)+'px';
 } 
 function hide_smenu() {
	 if (menu_open != 0 && buttons_disabled !=1 ) {
		 $("#main_content").fadeOut("fast");
		// $('#main_content').hide("blind", { direction: "vertical" }, 100);
	// $('#main_content').animate({'top': '-=800px'}, '800');
	// document.getElementById('main_content').style.visibility = 'hidden';	 
		 winWc =  winW - winWcp;
	// alert(winWc+'|'+winWcp+'|'+winW);
	 	var slideH1 = menu_slideH + winWc/2;
	 	var slideH2 = menu_slideH - winWc/2;		
	//alert(slideH1+'|'+slideH2);
		winHc = 0;
		 $('#but_01').animate({'left': '+='+slideH1+'px'}, '600');
	 $('#but_02').animate({'left': '+='+slideH1+'px'}, '700');
	 $('#but_03').animate({'left': '+='+slideH1+'px'}, '800');
	 $('#but_04').animate({'left': '-='+slideH2+'px'}, '600');
	  $('#but_05').animate({'left': '-='+slideH2+'px'}, '700');
	 $('#but_06').animate({'left': '-='+slideH2+'px'}, '800');   
	 $('#top_menu').animate({'top': '-=100px'}, '800');
	 menu_open = 0;
	 setTimeout("center_buttons();",800);	 
	 set_sbut();
	 }
 }
 function set_sbut(but) {
	document.getElementById('sbut_01').style.marginTop ='0px';
	document.getElementById('sbut_01_text').className = 'sbut_text';	
	document.getElementById('sbut_02').style.marginTop ='0px';
	document.getElementById('sbut_02_text').className = 'sbut_text';		
	document.getElementById('sbut_03').style.marginTop ='0px';
	document.getElementById('sbut_03_text').className = 'sbut_text';	
	document.getElementById('sbut_04').style.marginTop ='0px';
	document.getElementById('sbut_04_text').className = 'sbut_text';	
	document.getElementById('sbut_05').style.marginTop ='0px';
	document.getElementById('sbut_05_text').className = 'sbut_text';	
	document.getElementById('sbut_06').style.marginTop ='0px';	
	document.getElementById('sbut_06_text').className = 'sbut_text';	
	if (but !='') {
		document.getElementById(but).style.marginTop ='-10px';	
		document.getElementById(but+'_text').className = but+'_text_hover';
	}
 }
 var slideHmemo = 800;
 var buttons_disabled = 0;
 function set_topic(but) {

	if (buttons_disabled !=1) {
		$("#mcr_loading").fadeIn("slow");
	buttons_disabled = 1;		
	set_sbut(but);
	 if (mainContentOpen == 1) {
	
			$('#main_content').hide("blind", { direction: "vertical" }, 500);

		panel_dont_slide = 0;
		  if (but == 'sbut_01') {
		 setTimeout("mcr_pub.loadContent('/web30/firma.php');",550);	 
		 } else  if (but == 'sbut_02') {
		 setTimeout("mcr_pub.loadContent('/web30/oferta.php');",550);
		 } else  if (but == 'sbut_06') {
		 setTimeout("mcr_pub.loadContent('/web30/kontakt.php');",550);	 
		 } else  if (but == 'sbut_03') {
		 setTimeout("mcr_pub.loadContent('/web30/klienci.php');",550);	
		 } else  if (but == 'sbut_04') {
		 setTimeout("mcr_pub.loadContent('/web30/panel.php');",550);
		 } else  if (but == 'sbut_05') {
		 setTimeout("mcr_pub.loadContent('/web30/faq.php');",550);		
		 } else if (but == 'rekrutacja_2010-05') {
		 setTimeout("mcr_pub.loadContent('/web30/forms/rekrutacja_2010-05.php');",550);	
		 } else if (but != 'sbut_02') {
		 setTimeout("mcr_pub.loadContent('/web30/test.php');",550);
				 
		 } else {
		 setTimeout("mcr_pub.loadContent('/web30/test2.php');",550);	 		 
		 }
	//setTimeout('alert(slideHmemo);',950);
//	 setTimeout("$('#main_content').animate({'top': '+="+slideHmemo+"px'}, '800');",1000);
	 }
	 mainContentOpen = 1;
	// addHistoryEvent();
	}
 }

function adaptCH() {
		if (document.getElementById('content_holder').offsetHeight < 1000) {
			var chHeight = 1000;
		} else {
			var chHeight = document.getElementById('content_holder').offsetHeight;
		}
		$('#main_content').animate({height:chHeight+'px'},400);
	
}


function pl_afterload() {
	$("#mcr_loading").fadeOut("slow");
	//setTimeout("document.getElementById('main_content').style.height = document.getElementById('content_holder').offsetHeight+'px';",510);
	 	if (panel_dont_slide == 0){
			 
	
			$('#main_content').show('blind', { direction: 'vertical' }, 500);
			
			
		} else {
			$("#main_content").fadeIn("slow");	
			//setTimeout("slideHmemo = document.getElementById('content_holder').offsetHeight;",800);
		}
		if (document.getElementById('content_holder').offsetHeight < 1000) {
			var chHeight = 1000;
		} else {
			var chHeight = document.getElementById('content_holder').offsetHeight;
		}
		setTimeout("adaptCH();",1000);
		//document.getElementById('main_content').style.height = document.getElementById('content_holder').offsetHeight+'px';
		setTimeout("buttons_disabled = 0;",1000);
}

 function panelLoader(notificationType, notifier, data) {
	if (notificationType == "onPostUpdate") {
		setTimeout("pl_afterload();",100);
	}
	if (notificationType == "onPreLoad") {

			if (document.getElementById('content_holder')) {
			slideHmemo = document.getElementById('content_holder').offsetHeight;
			// alert(slideHmemo);
			}

	}
 }
 
 function loadPanel(url){
	$("#main_content").fadeOut("slow");
	//alert('fade');
	panel_dont_slide = 1;
	setTimeout("mcr_pub.loadContent('"+'/web30/'+url+"');",650);
		
 }
 var mcr_pub = new Spry.Widget.HTMLPanel("main_content");
 mcr_pub.addObserver(panelLoader);



$(document).ready(function() {
	$(window).resize(function() {
	 mcr_window_resize();
	});
	$("#central_b1").fadeOut("fast");
	setTimeout("document.getElementById('central_b1').style.visibility = 'visible';",400);
	setTimeout('$("#mcr_loading").fadeOut("slow");',500);	
	setTimeout('$("#central_b1").fadeIn("slow");',550);
	
	
});

window.onload = function() {
	mcr_window_resize();
	//initialize our DHTML history

	
};
