// NEW DECLARATIONS //
var isIE = false, isIEver= -1;
var boxFoldImgOn, boxFoldImgOff;
var dbug = 0;
var liquidTZone = 0, liquidBZone = 30, liquidBTop = 35, liquidBBot = 43;

// IMPORTED DECLARATIONS //
var pageLock = 0;

function pageSetup(){
	var temCalc = -1, temHeight = 0, temObj;

	//DETERMINE IE AND VERSION	
	isIEver = navigator.userAgent.toString();
	temCalc = isIEver.indexOf('MSIE ');
	if(temCalc != -1){
		isIE = true;
		isIEver = parseInt(isIEver.substring(temCalc + 5, isIEver.indexOf(';', temCalc + 5)), 10)
	
	}else{
		isIE = false;
		isIEver = -1;
		
	}

	//SETUP PAGELOCK REFRESH ON SCROLL
	//window.onscroll = function(){doPageLock(-1);}
	//window.onscroll = function(){return false;}

	//SETUP LIQUID FIX AND OTHER ON RESIZE FUNCTIONS
	window.onresize = function(){liquidFix(); doPageLock(-1);}

	//SETUP WINDOW ONCLICK
	document.onmousedown = function(){storeLCDPos(1);}

	//MISCELLANEOUS STYLE ADJUSTMENTS
	//SET UP GLASS LOCKOUT PANE'S TRANSPARENCY
	temObj = document.getElementById('glassPane');
		temObj.style.opacity = '0.8';
		temObj.style.filter = 'alpha(opacity=80)';

}

function liquidFix(){
	//FIX LAYOUT TO CONTENT SIZES OR PAGE (IF SMALLER)
	var tema, temMenuMid = document.getElementById('menuMid'), temBlurb = document.getElementById('blurbCont'), temTable = document.getElementById('bgTable');
	var temFBot = document.getElementById('bgFlareBot'), temGrad = document.getElementById('bgGradientCont'), temBlurbMid = document.getElementById('blurbMid');
	
	//GET VIEWPORT HEIGHT
	var temPageHeight = window.innerHeight;
	
	//SET LIQUID TOP ZONE TO TOP OF MAIN CONTENT
	liquidTZone = temBlurb.offsetTop;

	//COMPARE PAGE AND CONTENT HEIGHT, ASSIGN LARGER VALUE
	tema = Math.max(temPageHeight - liquidTZone - liquidBZone - liquidBTop - liquidBBot , temBlurbMid.clientHeight);

	//APPLY LIQUID FIXES

	if(temBlurbMid.clientHeight + liquidTZone + liquidBZone + liquidBTop + liquidBBot < temPageHeight){
		//ONLY ADJUST BLURB HEIGHT IF IT IS LOWER THAN PAGE + LIQUID MARGINS
		temBlurbMid.style.height = (tema) + 'px';
		
	}
	temMenuMid.style.height = temBlurbMid.clientHeight + 'px';
	//IF BLURB IS LESS THAN MENU HEIGHT, SET IT TO IT
	if(temBlurb.clientHeight < temMenuMid.parentNode.parentNode.clientHeight){
		temBlurbMid.style.height = (temBlurbMid.clientHeight + (temMenuMid.parentNode.parentNode.clientHeight - temBlurb.clientHeight)) + 'px';
		temMenuMid.style.height = temBlurbMid.clientHeight + 'px';
		
	}

	temTable.style.height = (tema + liquidTZone + liquidBZone + liquidBTop + liquidBBot) + 'px';
	temFBot.style.top = (temTable.clientHeight - temFBot.clientHeight) + 'px';


	temGrad.style.height = temTable.clientHeight + 'px';

	temFBot.style.visibility = 'visible';

}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
	
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}

function repeatString(temReps){
	var i, temStr = '';
	
	for(i=0; i<temReps; i++){
		temStr = temStr + lcdMsgPadChar;
		
	}
	return temStr;
	
}

function inputScrub(temObj){
	//CLEAR INPUT BOX CONTENT ONCLICK, ONCE ONLY
	if(temObj.scrubFlag != 1){
		temObj.value = '';
		temObj.scrubFlag = 1;
		temObj.style.color = '';
		
	}
	
}

function inputAlpha(temObj){
	//FIX INPUT FIELD TO ALPHANUMERIC ONLY
	temObj.value = temObj.value.toString().toUpperCase().replace(/[^A-Z 0-9]+/g,'');
	
}

///////////////////////////////////
// IMPORTED FUNCTIONS BELOW HERE //
///////////////////////////////////

// DEPRECATED HERE //
function runPageLock(){
	// DEPRECATED!!
	alert('runPageLock() - deprectated');
	return false;

}

// REUSED HERE //
function doPageLock(temMode){
	var tema, temGlassMsg = document.getElementById('glassMsg'), temGlassPane = document.getElementById('glassPane');
	
/*	if(temMode == 1){
		//SHOW GLASS PANE
		tema = parseInt((document.body.clientHeight - temGlassMsg.clientHeight) / 2, 10);
		temGlassMsg.style.top = tema + 'px';
		temGlassMsg.style.display = 'block';
		temGlassPane.style.display = 'block';
		pageLock = 1;
		
	}else if((temMode == -1) && (pageLock == 1)){
		//UPDATE POSITION ONLY
		tema = parseInt((document.body.clientHeight - temGlassMsg.clientHeight) / 2, 10);
		temGlassMsg.style.top = tema + 'px';
	
	}else{
		//HIDE GLASS PANE
		temGlassMsg.style.display = 'none';
		temGlassPane.style.display = 'none';
		pageLock = 0;
		
	}	*/
	
	if(temMode == 1){
		//SHOW GLASS PANE
		temGlassPane.style.display = 'table-cell';
		
		tema = parseInt((document.body.clientHeight - temGlassMsg.clientHeight) / 2, 10) - parseInt(temGlassMsg.clientHeight/2) -60;
		temGlassMsg.style.top = tema + 'px';
		temGlassMsg.style.display = 'block';
		pageLock = 1;
		
	}else{
		//HIDE GLASS PANE
		temGlassPane.style.display = 'none';
		temGlassMsg.style.display = 'none';
		pageLock = 0;
		
	}
	
}

function menuHover(temob, temMode, temStatus){
	var temObjOff = document.getElementById(temob.id + 'Img_OFF'), temObjOn = document.getElementById(temob.id + 'Img_ON'), temObjBull = document.getElementById(temob.id + 'Bull');

	if((temMode == 1) && (pageLock == 0)){
		//TURN MENU ITEM TO ON
		temObjOff.style.display = 'none';
		temObjOn.style.display = 'inline';
		temObjBull.style.visibility = 'visible';

	}else if((temMode == 0) && (pageLock == 0)){
		//TURN MENU ITEM TO ON
		temObjOn.style.display = 'none';
		temObjOff.style.display = 'inline';
		temObjBull.style.visibility = 'hidden';
		
	}
}

function menuClick(temUrl){
	if(pageLock == 1){
		window.alert('You are in the middle of a ticket purchase...\nIn order to navigate away from this page you will first need to cancel your booking.');
		
	}else{
		if(temUrl.indexOf('http') != -1){
			//OPEN IN NEW WINDOW AS ADDRESS CONTAINS 'HTTP'
			window.open (temUrl, '');
			
		}else{
			//OPEN IN SAME WINDOW
			location = temUrl;
			
		}
		
	}
}

function boxFold(temBoxId){
	var temCont = document.getElementById('progFoldCont_' + temBoxId);
	var temBlurb = document.getElementById('progFoldBlurb_' + temBoxId);
	var temArr = document.getElementById('progFoldArr_' + temBoxId);
	
	//IF NO boxState HAS BEEN ASSIGNED TO THE ARROW FOR THIS BOX, ASSIGN IT AS 1 (ASSUMING THIS IS OPENING FOR THE FIRST TIME) TO AVOID undefined TYPE ERROR
	if(!temArr.boxState){
		temArr.boxState = 1;
		
	}else{
		temArr.boxState = 1 - temArr.boxState;
		
	}
	
	//CACHE IMAGES IF THEY ARE NOT ALREADY THERE
	if(!boxFoldImgOff){
		boxFoldImgOff = new Image;
		boxFoldImgOff.src = 'gfx/construct/foldArrowSideOn.gif';
		
		boxFoldImgOn = new Image;
		boxFoldImgOn.src = 'gfx/construct/foldArrowDownOn.png';
		
	}

	//ADJUST THE VARIOUS ELEMENTS ACCORDINGLY
	if(temArr.boxState == 0){
		temCont.style.height = '1px';
		temBlurb.style.display = 'none';
		temArr.src = boxFoldImgOff.src;
		
	}else{
		temCont.style.height = 'auto';
		temBlurb.style.display = 'block';
		temArr.src = boxFoldImgOn.src;
		
	}
	
	//MAINTAIN THE LIQUID LAYOUT WHEN BOXES ARE OPENED/CLOSED
	liquidFix();
}
