// some vars

var numhoverimages = 0;

//slides the element with class "menu_body" when paragraph with class "menu_head" is clicked

$(document).ready(function()
{	
	var positionX = new Array()
		positionX["designPage"]=0;
		positionX["managementPage"]=1;
		positionX["fabricationPage"]=2;
		positionX["scenicartPage"]=3;
		positionX["installationPage"]=4;
		positionX["backgroundPage"]=0;
		positionX["contactPage"]=1;
		positionX["operaPage"]=0;
		positionX["theatrePage"]=1;
		positionX["museumsPage"]=2;
		positionX["environmentsPage"]=3;
		positionX["homePage"]=0;
			
	var positionY = new Array()
		positionY["designPage"]=0;
		positionY["managementPage"]=0;
		positionY["fabricationPage"]=0;
		positionY["scenicartPage"]=0;
		positionY["installationPage"]=0;
		positionY["backgroundPage"]=1;
		positionY["contactPage"]=1;
		positionY["individualsPage"]=1;
		positionY["faqPage"]=1;
		positionY["operaPage"]=2;
		positionY["theatrePage"]=2;
		positionY["museumsPage"]=2;
		positionY["environmentsPage"]=2;
		positionY["homePage"]=3;
	
 

	// function for accordian menu:

	$("#firstpane p.menu_head").click(function()
	{
	   $(this).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("normal"); 
	});
	
	// this function handles clicks to portfolio hovers
	
	$(".hoverDetail").click(function()
	{		
		clickedImage = $(this).attr("id");

		 var callurl = "portfolio_detail.php?project=" + clickedImage;
					 
		 var html = $.ajax({
				   url: callurl,
				   async: false
				 }).responseText;
		 
		 /* Set the content of the main area to the response */
									 
		$("#hoverContent").html(html);
		
		
		 var callurl = "portfolio_detail_text.php?project=" + clickedImage;
					 
		 var html = $.ajax({
				   url: callurl,
				   async: false
				 }).responseText;
		 
		 /* Set the content of the main area to the response */
									 
		$("#hoverContentText").html(html);
		
		
		var callurl = "portfolio_detail_counter.php?project=" + clickedImage;
					 
		numhoverimages = $.ajax({
				   url: callurl,
				   async: false
				 }).responseText; 
				 
		newLeft = "0px";
		
		$("#hoverContent").animate({"left":newLeft},"normal");


		$("#hoverbox").fadeIn("fast");
		
		if(parseInt(numhoverimages) < 2)
		{
			$("#portF").fadeOut();
		}
		else
		{
			$("#portF").fadeIn();
		}

	});
	
	
	// this function handles clicks to the portfolio next
	
	$("#portF").click(function()
	{
		hoverSlider = $("#hoverContent");
		curLeft = parseInt(hoverSlider.css("left"));
		
		maxLeft = -(numhoverimages-1) * 482;
		
		if(curLeft == maxLeft)
		{
			newLeft = 0;
		}
		else
		{
			newLeft = curLeft - 482;
		}
		
		newLeft = newLeft + "px";
		
		hoverSlider.animate({"left":newLeft},"normal");
		
	});
	
	// this function handles clicks to the close portfolio x
	
	$("#closeHoverbox").click(function()
	{
		$("#hoverbox").fadeOut("fast");
	});
	
	// handle clicks to the menu
	
	$("#menu a").click(function()
	{
		$("#hoverbox").fadeOut("fast");
		
		clickedID = $(this).attr("id");
	
		if(clickedID == 'home')
		{
			$("div.menu_body").slideUp("normal");
		}
	
		// go ahead and start loading that page if it isn't loaded
		
		var pageName = clickedID + "Page";
		
		var pageRef = "#" + pageName;
			
		if(clickedID != 'services' && clickedID != 'company' && clickedID != 'portfolio')
		{		
			 movetopage(pageName);
		}
		
	});


	// function for moving from current location to new location	
	
	function movetopage(pageName) {
		
		var pageRef = "#" + pageName;
		
		pagesArea = $("#pagesarea");
		
		// find the position x and y of the current thing
		curTop = pagesArea.css("top");
		curLeft = pagesArea.css("left");
		
		// find the pos x and y of the next thing
		
		clickedID = $(this).attr("id");
		
		newTop = - positionY[pageName] * 644;
		newLeft = - ((positionX[pageName] * 750) - 2);
		
		if(newLeft == 2)
		{
			newLeft = 0;
		}
		
		newTop = Math.floor(newTop) + "px";
		newLeft = Math.floor(newLeft) + "px";
		
		// animate the transition
		
		if(newTop == curTop)
		{
			pagesArea.animate({"left":newLeft},500);
		}
		else
		{
			// now, if we're going right or left, go back left first
			
			pagesArea.animate({"left":0},500);
			
			pagesArea.animate({"top":newTop},500);
			pagesArea.animate({"left":newLeft},500);
		}
	}
	
	// functions for moving to specific pages based on clicks to the front page
	
	$("#clicktohome").click(function()
	{
		movetopage("homePage");
		$("div.menu_body").slideUp("normal");
	});
	
	$(".clicktomuseums").click(function()
	{
		movetopage("museumsPage");
		$("#portfolioAccord").slideToggle(300).siblings("div.menu_body").slideUp("normal");
	});
	
	$(".clicktoenviron").click(function()
	{
		movetopage("environmentsPage");
		$("#portfolioAccord").slideToggle(300).siblings("div.menu_body").slideUp("normal");
	});
	
	$(".clicktoopera").click(function()
	{
		movetopage("operaPage");
		$("#portfolioAccord").slideToggle(300).siblings("div.menu_body").slideUp("normal");
	});
	
	$(".clicktotheatre").click(function()
	{
		movetopage("theatrePage");
		$("#portfolioAccord").slideToggle(300).siblings("div.menu_body").slideUp("normal");
	});
	
});
