var chosenSubpage = "#subpage1";

function windowHeight()
{
	if(jQuery.browser.opera) return document.documentElement.clientHeight;
	else if(jQuery.browser.msie) return document.documentElement.clientHeight;
	else return window.innerHeight;
}
function windowWidth()
{
	if(jQuery.browser.opera) return document.documentElement.clientWidth;
	else if(jQuery.browser.msie) return document.documentElement.clientWidth;
	else return window.innerWidth;
}


function moveSubpageLead(newPos, btn, subpage)
{
	$("#inner2-subpageLead ul").animate({"top": newPos }, "normal" );
		
	$(chosenSubpage).fadeOut("fast", function(){$(subpage).fadeIn("fast")});
	chosenSubpage = subpage;
	
	$(".subpageBtn1").removeClass("active");
	$(".subpageBtn2").removeClass("active");
	$(".subpageBtn3").removeClass("active");
	$(".subpageBtn4").removeClass("active");
	$(".subpageBtn5").removeClass("active");
	$(".subpageBtn6").removeClass("active");
	
	btn.addClass("active");
	
	
}

function changeProjectGallerySize()
{
	var newHeight = Math.round(windowHeight() - $("#projectDetailsDescription").height() - 20);
	//alert(newHeight);
	if(newHeight < 580)
	{
		$("#projectGallery img").each(function()
										   {
											   newWidth = Math.round((newHeight/$(this).height()) * $(this).width());
											   //alert($(this).width());
											   //$(this).width(newWidth);
											   $(this).height(newHeight);
										   }
								  );
		$("#projectGallery").css({"top": "10px" })
	}
	else
	{
		$("#projectGallery img").each(function()
										   {
											   $(this).height(580);
										   }
								  );
		
		var newTopPos = (windowHeight() - $("#projectDetailsDescription").height() - 580) / 2;
		$("#projectGallery").css({"top": newTopPos + "px" })
	}
	
}

function hideProjectGallery()
{
	$("#projectDetails .bg").hide();
	$("#projectDetailsDescription").css({"bottom": -$("#projectDetailsDescription").height()-20});
	$("#projectDetails .nav").css({"right": -$("#projectDetails .nav").width()-40});
	$("#projectGallery").hide();
}

function showProjectGallery(projId)
{
	
	
	$("body").append("<div id=\"projectDetails\"></div>");
	
	$("#projectDetails").load("../layout/projectDetails.php", {'projId':projId}, function(){						
							
					//    ZASTAP LOAD GET!!!!!!!!!
							
	//changeProjectGallerySize();
	hideProjectGallery();
	
	$("#projectGallery").show();
	$("#projectGallery ul").css({"left": windowWidth()+"px"});
	$("#projectDetails .bg").fadeIn("slow", function(){ $("#projectDetailsDescription").animate( { bottom:"0px" }, 600 ); setTimeout(function(){$("#projectGallery ul").animate( { left:"0px" } , 1000 ) }, 600); changeProjectGallerySize(); setTimeout(function(){$("#projectDetails .nav").animate( { right:"0px" } , 1000 )  }, 1600) })
																		   
	$("#projectDetails .exitBtn").click( function(){ hide2ProjectGallery() } );
	$("#projectDetails .nextBtn").click( function(){ $("#projectGallery ul").animate( { left: $("#projectGallery ul").position().left - $("#projectGallery ul img").width() } , 1000 ) } );
	$("#projectDetails .prevBtn").click( function(){ $("#projectGallery ul").animate( { left: $("#projectGallery ul").position().left + $("#projectGallery ul img").width() } , 1000 ) } );
																		   
																		   });
	
}


function hide2ProjectGallery()
{
	setTimeout(function(){$("#projectDetailsDescription").animate( { bottom:-$("#projectDetailsDescription").height()-20 }, 600 )}, 500);
	$("#projectGallery ul").animate( { left: windowWidth()+"px" } , 700 )
	$("#projectDetails .nav").animate( { right: -$("#projectDetails .nav").width()-40 } , 700 )
	setTimeout(function(){$("#projectDetails .bg").fadeOut(800)}, 1000);
	setTimeout(function(){$("#projectGallery").hide()}, 2000);
}


$(
	function()
	{
		//if($("#portfolioCont")) portfolio = true;
		
		$("#mainMenu>ul>li>a").click(function(){  } );
		$(".subpageBtn1").click( function(){ moveSubpageLead("0", $(this), "#subpage1") } );
		$(".subpageBtn2").click( function(){ moveSubpageLead("-245px", $(this), "#subpage2") } );
		$(".subpageBtn3").click( function(){ moveSubpageLead("-490px", $(this), "#subpage3") } );
		$(".subpageBtn4").click( function(){ moveSubpageLead("-735px", $(this), "#subpage4") } );
		$(".subpageBtn5").click( function(){ moveSubpageLead("-980px", $(this), "#subpage5") } );
		$(".subpageBtn6").click( function(){ moveSubpageLead("-1225px", $(this), "#subpage6") } );
		
		//$("#portfolioCont li a").click( function(){ $(this).hide("slow") } );
		//$("#showAll").click( function(){$("#portfolioCont li a").fadeIn("slow");} )
		
		
		$("#portfolioCont li a").click( function(){ showProjectGallery($(this).attr('href')) } );
		
		$(window).resize(function(){
			changeProjectGallerySize();
		});
		//changeProjectGallerySize();
		
				
		$(".printPage").click( function(){ window.print() } );
		$(".changeFontSize .normal").click( function(){ $("#subpageCont *").css("fontSize", "100%").css("marginBottom", "3%"); $("#subpageCont h3").css("fontSize", "20px").css("marginBottom", "10px"); $("#subpageCont h4").css("fontSize", "16px").css("marginBottom", "10px") } );
		$(".changeFontSize .medium").click( function(){ $("#subpageCont *").css("fontSize", "110%").css("marginBottom", "4%"); $("#subpageCont h3").css("fontSize", "24px").css("marginBottom", "3%"); $("#subpageCont h4").css("fontSize", "20px").css("marginBottom", "3%") } );
		$(".changeFontSize .big").click( function(){ $("#subpageCont *").css("fontSize", "120%").css("marginBottom", "6%"); $("#subpageCont h3").css("fontSize", "30px").css("marginBottom", "3%"); $("#subpageCont h4").css("fontSize", "24px").css("marginBottom", "3%") } );
		
		$("#newsModule .news").click( function(){ $("#newsDetailsModule .news[title!="+$(this).attr("title")+"]").hide("slow"); $("#helloModule").hide("slow"); $( "#newsDetailsModule ." + $(this).attr("title") ).show("slow"); } )
		
	}
)