// JavaScript Document

var contentMin=20;
var contentWidth=800;
var contentHeight=305;

var posX=0;
var poxY=0;
var disabledMainmenu=false;

$(document).ready(function(){
	$('div.textbox').css({'opacity':0.85});
	
	//obliczam contentHeight czyli wysokosc karteczki
	var navHeight = $(window).height();
	contentHeight=navHeight-200;
	if(contentHeight>420)contentHeight=420;
	$('.mcs_container').css({height:contentHeight-45}); //260
	$('.dragger_container').css({height:contentHeight-55}); //250
	
	
	
	$('div.mainmenu a').click(function(event){	
		event.preventDefault();					
		if(disabledMainmenu)return;
		disabledMainmenu=true;
		
		var href=$(this).attr('href');							   
		$("div.mainmenu a").removeClass("selected");							   
	    $(this).addClass("selected");
		
		if($("div.textcontainer:visible").length>0){
			closeContentPage(showContentPage);
		}else
	   		showContentPage();
	
	});
	
	$("a.textboxclose").click(function(event){
		event.preventDefault();						
		$("div.mainmenu a").removeClass("selected");	
		$("div.mainmenu a").eq(2).addClass("selected");
		 closeContentPage(null);
	});
	
});

function setPagePosition(){
	if($('div.textcontainer:visible').length>0){
		var navWidth = $(window).width();
		var navHeight = $(window).height();
		posX=(navWidth-contentWidth)/2;	
		posY=(navHeight-contentHeight)/2;
		$('div.textbox:visible').css({left:posX,top:posY});
		$('div.textcontainer:visible').css({left:posX,top:posY,width:contentWidth,height:contentHeight});
	}
}

function showContentPage(){
		var href=$("div.mainmenu a.selected").attr('href');
		if(href.length==0){disabledMainmenu=false; return; }
		var navWidth = $(window).width();
		var navHeight = $(window).height();
		posX=(navWidth-contentWidth)/2;	
		posY=(navHeight-contentHeight)/2+15;
		
		$('div.textbox').css({left:posX}).show().animate({top:posY},500,"expoEaseIn", function(){
				$('div.textbox').animate({width:contentWidth,height:contentHeight},500,"expoEaseIn", function(){
						$('div.textcontainer.'+href).css({left:posX,top:posY,width:contentWidth,height:contentHeight}).show();
						mCustomScrollbars();
						disabledMainmenu=false;
				});	
		});	
}

function closeContentPage(callback){
		$('div.textcontainer').stop(false,true);
		$('div.textbox').stop(false,true);
		
		$('div.textcontainer').hide();
		$('div.textbox').animate({width:20,height:20},400,"expoEaseIn", function(){
				$('div.textbox').animate({top:-20},200,"expoEaseIn",callback);																	   
		});
}

function blockMainMenu(){
		
}
