﻿//loads all the page items in the correct order

/*----------------------
	Move Curtain Down 
----------------------*/

//Move the Curtain Down if the previous page was one without Curtain

    var animated = false 					//Set if the menu is animating
	var bWasClosed = true					//Is the Curtain Down?
	var bClosed = false						//Is this a skin with a closed curtain?
	var sMenuId = "#skinmenu"				//Id of Menu div
	var sCurtainId = "#skincontent"			//Id of the "Curtain"
	var sContentUpId = "#skinpanes"			//Id of up content
	var sCurtainContentId = "#skinpanes"	//ID of the panes
	
	var bContentVisible = true
	
	var iBgShowTime = 500
	var iMenuShowTime = 500
	var iCurtainShowTime = 500
	var iContentShowTime = 500
	
	var iCurtainSlideTime = 500
	
	var iBgHideTime = 200
	var iMenuHideTime = 200
	var iCurtainHideTime = 200
	var iContentHideTime = 200
	
	var aImgs = new Array //Array to load images in to 

	function setInterface(_closed){ 

	bClosed = _closed
	
		//createBgImgArray()
				
	    if (bClosed){
		//If the curtain SHOULD be closed at the end
			if (undefined == readCookie("CurtainDown")|| readCookie("CurtainDown") == "false" ){ 
	        // If the Curtain was Up
				bWasClosed = false
			}
			else{
			// If the Curtain was already Down
			}		
			// Write the cookie that the curtain is down
			createCookie ("CurtainDown", "true")
		}
		else{
			//If the curtain should be OPEN in the end
			createCookie ("CurtainDown", "false")
		}
		
		checkLoaded()

	}
	
/*----------------------
	Hide and show elements 
----------------------*/
	
	
	function checkLoaded(){
		
		if (bClosed){
		//For skins with the curtain down
			jQuery(sCurtainContentId).css("visibility", "hidden");
			if (bWasClosed) {

			}
			else{
				jQuery(sCurtainId).css("height", "0");
			}
			setTimeout(showCurtainDown, iBgShowTime)
		}
		else{
		//For skins with the curtain up
			setTimeout(showCurtainUp, iBgShowTime)
		}

	}

	
	function showCurtainDown(){
		//Will fade all the items in oArray with the time from the array
		showItem(sMenuId, iMenuShowTime, 0)	//Show the menu
		if (bWasClosed) {
			showItem(sCurtainId, iCurtainShowTime, 0)	//Fade the Curtain
			setTimeout(afterMoveDown, iCurtainShowTime + 100 )
		}
		else{
			setTimeout(CurtainShow, iMenuShowTime)	//Slide the Curtain
		}
				
	}
	
	function showCurtainUp(){
		showItem(sMenuId, iMenuShowTime, 0)	//Show the menu
		
			if (jQuery.browser.msie){ //If IE
				setTimeout(function(){jQuery(sContentUpId).removeClass("HideMe")}, iMenuShowTime + 200)
			}
			else{ //If not IE
			jQuery(sContentUpId).fadeTo(0, 0);
			jQuery(sContentUpId).removeClass("HideMe");
			showItem(sContentUpId, iCurtainShowTime, iMenuShowTime)	//Show the content
			}
		
	}
	
	function showItem(ItemId, ItemTime, iWait){
		setTimeout(function(){jQuery(ItemId).fadeTo(ItemTime, 1)}, iWait)
	}
	
	function hideItem(ItemId, ItemTime, iWait){
		setTimeout(function(){jQuery(ItemId).fadeTo(ItemTime, 0)}, iWait)
	}
	
	function createBgImgArray (){
		//Fill the images to check array
		aImgs[0] = new Image();
		aImgs[0].src = _bgImg;
		aImgs[1] = new Image();
		aImgs[1].src = _bgImgTop;
		aImgs[2] = new Image();
		aImgs[2].src = _bgImgBot;
	}


/*----------------------
	Move Curtain Down
----------------------*/
	
	function startCurtainShow() {
		//Will start the curtain animation if all images are loaded
	    if (checkImages()){
    	    CurtainShow()
	    }
	    else
	    {
    	 setTimeout (startCurtainShow , 100)
	    }
	}
	
	
	function checkImages (){ 
		// Check if all the images are loaded
		if (aImgs[0].complete && aImgs[1].complete && aImgs[2].complete){
			return true
		}
		else{
			return false
		}
	}	
	
	function CurtainShow(){
		// Will show the curtain by sliding it down
		jQuery(sCurtainId).fadeTo(0, 1)
		if (animated == false){
		animated = true
		jQuery(sCurtainId).animate({ height: '400px' }, iCurtainSlideTime, "" , function() {afterMoveDown()});
		}
	}

    
    function afterMoveDown(){
		jQuery(sCurtainContentId).css("visibility", "visible");
        stopAnimation()
    }
    
	function stopAnimation(){
        animated = false
    }  
	

/*----------------------
	Move Curtain Up 
----------------------*/

	function handleMenuLink(sLink, sSkin){ 
		// Handle menu link click (the link in the menu is passing this using Javascript)
		//Checks if the new page has another skin then the current, if not it slides the curtain up.
		if (bClosed){
			 if (sSkin.search(/closed/i) == -1){
			 
				hideItem(sCurtainContentId, 0, 0)	//Hide the content
				curtainSlideUp()	//Hide the Curtain				
				hideItem(sMenuId, iMenuHideTime, iCurtainSlideTime)	//Hide the menu
				setTimeout(function(){pageRedirect(sLink)}, iMenuHideTime + iCurtainSlideTime)
				
			 }
			 else
			 {
				hideItem(sCurtainContentId, 0, 0)	//Hide the content
				hideItem(sMenuId, iMenuHideTime, 0)	//Hide the menu
				hideItem(sCurtainId, iMenuHideTime, 0)	//Hide the Curtain
				setTimeout(function(){pageRedirect(sLink)}, iMenuHideTime)
				
			 }
		}
		else{ //This is a skin with the curtain up
				hideItem(sCurtainContentId, 0, 0)	//Show the menu
				hideItem(sMenuId, iMenuHideTime, 0)	//Show the menu
				if (jQuery.browser.msie){ //If IE
					setTimeout(function(){jQuery(sContentUpId).addClass("HideMe")}, iMenuHideTime + 200)
				}
				else{
					hideItem(sCurtainId, iMenuHideTime, 0)	//Fade the Curtain
				}
				
				setTimeout(function(){pageRedirect(sLink)}, iMenuHideTime)
		}

	}
	
	
	function curtainSlideUp(){
		// Will hide the curtain by sliding it up and then redirect to the passed page
		jQuery(sCurtainId).animate({ height: 0 }, iCurtainSlideTime, "");
	}
	
	function pageRedirect (sLink){
		//Redirect to the page passed before by the menu
		window.location=sLink;
	}
	
/*----------------------
	Set Scrollpanes
----------------------*/

	function setScrollAll(){
		setScroll('.c_contentfooter');
		setScroll('#TimoDesignSubMenu');
		setScroll('#ProjectContent');
	}

	function setScroll(sElement){
		jQuery(function()
		{
			// this initialises the scollpanes on the page.
			jQuery(sElement).jScrollPane({showArrows:true, scrollbarWidth: 17});
		});
	}
	
	function reSetScroll(sElement){
		jQuery(sElement).jScrollPane({showArrows:true, scrollbarWidth: 17});
	}
	
/*------------------------------------------------*/

	jQuery(document).ready(function (){ 
		checkLoaded(); 
		setScrollAll();
		})
	

	
/*----------------------
	Show Bg
----------------------*/
function ShowBg(oLink){
	if (bContentVisible == true){
		jQuery("#skincontainercontent").fadeOut(500);
		jQuery(oLink).toggleClass("Active");
		bContentVisible = false
	}
	else{
		jQuery("#skincontainercontent").fadeIn(500);
		jQuery(oLink).toggleClass("Active");
		bContentVisible = true
	}

}




