var minTop = 0;
var minLeft = 0;
var minHeight = 680;
var TheLeftEdge = 0;
var idealWidth = 778;
var bottomOffset = 40;
var topOffset = 44;
var theMinimumHeight = minHeight-topOffset-bottomOffset-295;
var M_contentJax ;
var imageJax ;
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var moz=document.getElementById&&!document.all
var homeOn = 1;

function reBox() {
	var TheCheat = document.getElementById('cheater');
	var TheCBox = document.getElementById('truC');
	var RealSizeH = TheCheat.offsetHeight;
	var RealSizeW = TheCheat.offsetWidth;
	var RealCSizeH = TheCBox.offsetHeight;
	var RealCSizeW = TheCBox.offsetWidth;
	var TheMiddle = (RealSizeW / 2);	
	TheLeftEdge = (TheMiddle - (idealWidth / 2));
	var TheRightEdge = (TheMiddle + (idealWidth / 2));
	var TheContentHeight = (RealSizeH - bottomOffset - topOffset - 10-10-100-30-10-125-30-10); // margin,margin,titlebar,navbar,margin,toprow,doctitle,margin
	if (TheLeftEdge <= minLeft) {
		TheLeftEdge = 0;
		TheRightEdge = idealWidth;
		theMiddle = idealWidth / 2;
	}	
	document.getElementById('blackBox').style.left = TheLeftEdge+"px";
	document.getElementById('blackBox').style.top = topOffset+"px";	
	document.getElementById('CFrame').style.left = TheLeftEdge+20+"px";
	document.getElementById('bigTit').style.left = TheLeftEdge+270+"px";
	document.getElementById('bigTit').style.top = topOffset+289+"px";
	document.getElementById('homePage').style.top = topOffset+150+"px";
	document.getElementById('homePage').style.left = TheLeftEdge+20+"px";
	
		document.getElementById('homePage').style.height = minHeight - topOffset-bottomOffset-170+"px";
	 if( (RealCSizeH < theMinimumHeight) || ( homeOn == 1)) {  
	 //  document.getElementById('addressB').innerHTML = "MODE: IF_"+RealCSizeH+" < "+TheContentHeight+"___||___ "+RealCSizeH+"  <  "+theMinimumHeight;
		document.getElementById('blackBox').style.height = minHeight - topOffset-bottomOffset+"px";
		document.getElementById('whiteBox').style.height = minHeight - topOffset-bottomOffset-20+"px";
		document.getElementById('CFrame').style.height = minHeight - topOffset-bottomOffset-100-30-40+"px";
		document.getElementById('copyright').style.top = minHeight - bottomOffset+"px";
		document.getElementById('copyright2').style.top = minHeight - bottomOffset+"px";
	 
	 } else {//  document.getElementById('addressB').innerHTML = "MODE: ELSE";
	 	document.getElementById('CLeftCol').style.height = RealCSizeH+"px";
		document.getElementById('blackBox').style.height = RealCSizeH+10+10+100+30+10+125+10+10+"px";
		document.getElementById('whiteBox').style.height = RealCSizeH+10+10+100+30+10+125+"px";
		document.getElementById('CFrame').style.height = RealCSizeH+10+100+25+"px";
		document.getElementById('copyright').style.top = document.getElementById('blackBox').offsetHeight+topOffset+"px";
		document.getElementById('copyright2').style.top = document.getElementById('blackBox').offsetHeight+topOffset+"px";
	 }
	document.getElementById('addressA').style.width = 290+"px";
	document.getElementById('addressB').style.width = 290+"px";
	document.getElementById('copyright').style.width = 390+"px";
	document.getElementById('addressB').style.left = TheRightEdge-300+"px";
	document.getElementById('addressB').style.top = 1+"px";
	document.getElementById('addressA').style.left = TheLeftEdge+10+"px";
	document.getElementById('addressA').style.top = 1+"px";
	document.getElementById('copyright').style.left = TheRightEdge-400+"px";
	document.getElementById('copyright2').style.left = TheLeftEdge+10+"px";
}

// go home on logo click
function do_goHome(sumVar) { window.location.href="index.cfm"; return true; }
// place main Nav
function navLeft(){ return TheLeftEdge+20; }
// Confirm Delete
function confirmdelete() { if (confirm("Are you sure you want to delete? - Delete is PERMANENT")) { return true; } else { return false;}}
// hide the splash page
function doHome() { 	if ( homeOn == 1) { document.getElementById('homePage').style.zIndex=3; homeOn = 0; reBox();} }

// ###############################
// AJAX interactivity
// ###############################
function doM_Content(DocID) {  // engine for pulling Documents
	 doSubNav('up');
	fadeContent();
	M_contentJax=GetXmlHttpObject();
	var url="CMS/apps/_content.cfm";
	url=url+"?docid="+DocID;
	url=url+"&randInt="+Math.random();
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}

function doM_FContent(FID) { // engine for pulling Folders
	// doSubNav('up');
	fadeContent();
	M_contentJax=GetXmlHttpObject();
	var url="CMS/apps/_content.cfm";
	url=url+"?fid="+FID;
	url=url+"&randInt="+Math.random();
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}
 function doF_Content(DocID) { // engine for pulling a path from anywhere to the main content window.
	// doSubNav('up');
	fadeContent();
	M_contentJax=GetXmlHttpObject();
	if (DocID.indexOf('?') == -1){	var url=DocID+"?randInt="+Math.random(); } else { var url=DocID+"&randInt="+Math.random(); }
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}

// check AJAX and define an AJAX object.
function GetXmlHttpObject() {
	var MyAjax=null;
	try {// Firefox, Opera 8.0+, Safari
  		MyAjax=new XMLHttpRequest();
  	}
	catch (e) {	// Internet Explorer
  		try { MyAjax=new ActiveXObject("Msxml2.XMLHTTP"); }
  		catch (e) { MyAjax=new ActiveXObject("Microsoft.XMLHTTP"); }
  	}
	return MyAjax;
} 

// ##############################
//  MAIN CONTENT FLIP
// ##############################
function doContentView() { 
	doHome();
	if (M_contentJax.readyState == 1) { doSubNav("up"); document.getElementById('bigTit').innerHTML="Loading...";
	} else if (M_contentJax.readyState == 2) { document.getElementById('bigTit').innerHTML="Requesting...";
	} else if (M_contentJax.readyState == 3) { document.getElementById('bigTit').innerHTML="Receiving...";
	} else if (M_contentJax.readyState == 4) { 
		if ( M_contentJax.responseText.indexOf('<!-- split -->') != -1 ) {
			theSplit = M_contentJax.responseText.split('<!-- split -->');
			if (theSplit.length == 5){
				document.getElementById("bigTit").innerHTML=theSplit[0];
				document.title = "Lofty Living - "+theSplit[0];
				document.getElementById("CImageL").innerHTML=theSplit[1];
				document.getElementById("CImageR").innerHTML=theSplit[2];
				document.getElementById("CLeftCol").innerHTML=theSplit[3];
				document.getElementById("truC").innerHTML=theSplit[4];
				if (theSplit[2].indexOf('<!-- imamap -->') > -1) { loadMap(); }
			}  else {
			document.getElementById("truC").innerHTML = "an error occured with the request, please retry. If this problem persists, please contact a site administrator<br><br>102b - bad data return: "+M_contentJax.responseText; 
			}
		} else {
			document.getElementById("truC").innerHTML = "an error occured with the request, please retry. If this problem persists, please contact a site administrator<br><br>102a - bad data return:<br> "+M_contentJax.responseText;
		}
		fadeContent('up');
		initRNav();
		doSubNav();
	}  else {
		 document.getElementById("truC").innerHTML = "an error occured with the request, please retry. If this problem persists, please contact a site administrator<br><br>102c - Bad return code";
	}
}
// older and 'bit' rollover action
function doMe(myDiv,myID){
	if(myID == 1){ myDiv.style.background=overColor; myDiv.style.color=txtOnCol;  // might be unused....
	} else if (myID == 2){	myDiv.style.background="#cee1ad"; myDiv.style.color="#FFFFFF";	myDiv.style.cursor="pointer"	/* // Used for Calendar day overs.
	
	} else if (myID == 3){	myDiv.style.backgroundImage = "url('images/LnavItemOn.gif')"; undoFMe();						// Used for Left Navigation Buttons	
	} else if (myID == 4){	myDiv.style.color="#990000";	myDiv.style.cursor="pointer";									// Used for bottom of Calendar Buttons
	} else if (myID == 5){	myDiv.style.background="#ffffcd"; myDiv.style.color="#000000";									// Used for LeftNav Subs
	} else if (myID == 6){	myDiv.style.background="#ebe8c2"; myDiv.style.border="#990000 1px solid"; 						// Used for Folder View
	} else if (myID == 7){	myDiv.src="images/bak_on.gif";																	// Used for Back Roll Over
	} else if (myID == 8){	myDiv.src="images/fwd_on.gif";																	// Used for FWD Roll Over
	} else if (myID == 9){	myDiv.src="images/login_on.gif";											*/					// Used for LOGIN Roll Over
	}
}
function undoMe(myDiv,myID){
	if(myID == 1){ myDiv.style.background=baseColor; myDiv.style.color=txtOffCol;
	} else if (myID == 2){	myDiv.style.background="#ffffff"; myDiv.style.color="#336699";				/*					// Used for Calendar day overs.
	
	} else if (myID == 3){	myDiv.style.backgroundImage = "url('images/LnavItemOff.gif')"; undoFMe();						// Used for Left Navigation Buttons
	} else if (myID == 4){	myDiv.style.color="#FFFFFF";																	// Used for bottom of Calendar Buttons
	} else if (myID == 5){	myDiv.style.background="#e7e3ad"; myDiv.style.color="#666666";									// Used for LeftNav Subs
	} else if (myID == 6){	myDiv.style.background="#ffffff"; myDiv.style.border="0px"; 									// Used for Folder View
	} else if (myID == 7){	myDiv.src="images/bak_off.gif";																	// Used for Back Roll Off
	} else if (myID == 8){	myDiv.src="images/fwd_off.gif";																	// Used for FWD Roll Off
	} else if (myID == 9){	myDiv.src="images/login_off.gif";											*/ 					// Used for LOGIN Roll Off
	}
}


// ##############################
//  START ANIMATIONS
// ##############################


// ##############################
// Main & Content Frame Animation
// ##############################


function fadeContent(move) { 
	elem = document.getElementById('truC');
	if (move == 'up') { 
		// alert('p');
		elem.currentAlpha = 0;
		toAlpha = 100; 
		fromAlpha=0; 
		elem.style.filter = "alpha(opacity=0."+fromAlpha+")";
		elem.style.KHTMLOpacity = fromAlpha/100;
		elem.style.MozOpacity = fromAlpha/100;
		elem.style.opacity = fromAlpha/100;
	} else { 
		toAlpha = 0; 
		fromAlpha=100;
	}	
	doAlphaChange(document.getElementById("truC"),fromAlpha,toAlpha,130,10,1); 
}


// ##############################
// sub Nav Actions
// ##############################
function initRNav() {	
	var baseHeight = 20;
	// alert('boing');
	var animElements = document.getElementById("CLeftCol").getElementsByTagName("div");
	for(var i=0; i<animElements.length; i++) { 
			animElements[i].onmouseover = heightChange;
		 	animElements[i].onmouseout = heightRestore;
		}
	function heightChange() {
		if (!this.currentHeight) { this.currentHeight = baseHeight; } 
		if (this.heightChangeInt) { window.clearInterval(this.heightChangeInt);	 }
			var toHeight = 30;
			doSubNavOver(this,this.currentHeight,toHeight,10,1,1);
		}
	function heightRestore() {
		if (!this.currentHeight) { return; 
		} else { 
			var toHeight = 20; 
			doSubNavOver(this,this.currentHeight,toHeight,10,3,.3); } // (elem,startHeight,endHeight,steps,intervals,powr) (minValue,maxValue,totalSteps,actualStep,powr)
		}
}
function doSubNav(move) {
	if (move == 'up') { toHeight = 1;
		doHeightChange(document.getElementById("CLeftCol"),document.getElementById("CLeftCol").offsetHeight,1,30,10,1);
	} else { 
		if ((document.getElementById("CLeftCol").getElementsByTagName("div").length*20+50) < 150) { toHeight = 150;
		} else { toHeight = document.getElementById("CLeftCol").getElementsByTagName("div").length*20+50;
		} doHeightChange(document.getElementById("CLeftCol"),document.getElementById("CLeftCol").offsetHeight,toHeight,130,10,1);
	}
}
function doSubNavOver(elem,startHeight,endHeight,steps,intervals,powr) {
	if (elem.heightChangeInt) window.clearInterval(elem.heightChangeInt);
	var actStep = 0;
	elem.heightChangeInt = window.setInterval(
		function() {
			elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
			elem.style.height = elem.currentHeight+"px";
			elem.style.lineHeight = elem.currentHeight-2+"px";
			elem.style.fontSize = Math.round((elem.currentHeight-20)/3+14) +"px";
			// elem.innerHTML = elem.currentHeight;
			actStep++;
			if (actStep > steps) { window.clearInterval(elem.heightChangeInt); }
		},intervals)
}

// ##############################
// general Animation scripts
//###############################
function doAlphaChange(elem,startAlpha,endAlpha,steps,intervals,powr) {
	if (elem.alphaChangeInt) window.clearInterval(elem.alphaChangeInt);
	var actStep = 0;
	elem.alphaChangeInt = window.setInterval(
		function() {
			elem.currentAlpha = easeInOut(startAlpha,endAlpha,steps,actStep,powr);
			elem.style.filter = "alpha(opacity="+elem.currentAlpha+")";
			elem.style.KHTMLOpacity = elem.currentAlpha/100;
			elem.style.MozOpacity = elem.currentAlpha/100;
			elem.style.opacity = elem.currentAlpha/100;
			//elem.style.alpha = elem.currentAlpha+"px";
			actStep++;
			if (actStep > steps) { window.clearInterval(elem.alphaChangeInt); reBox();}
		},intervals)
}
function doHeightChange(elem,startHeight,endHeight,steps,intervals,powr) {
	if (elem.heightChangeInt) window.clearInterval(elem.heightChangeInt);
	var actStep = 0;
	elem.heightChangeInt = window.setInterval(
		function() {
			elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
			elem.style.height = elem.currentHeight+"px";
			actStep++;
			if (actStep > steps) { window.clearInterval(elem.heightChangeInt); }
		},intervals)
}
function doWidthChange(elem,startHeight,endHeight,steps,intervals,powr) {
	if (elem.widthChangeInt) window.clearInterval(elem.widthChangeInt);
	var actStep = 0;
	elem.widthChangeInt = window.setInterval(
		function() {
			elem.currentWidth = easeInOut(startWidth,endWidth,steps,actStep,powr);
			elem.style.width = elem.currentWidth+"px";
			actStep++;
			if (actStep > steps) { window.clearInterval(elem.widthChangeInt); }
		},intervals)
}
function easeInOut(minValue,maxValue,totalSteps,actualStep,powr) {
	var delta = maxValue - minValue;
	var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
	return Math.ceil(stepp)
}



// ##############################
// GMap Functions
//###############################
var map1;
var map2;
var markNewWest = new GMarker(new GPoint(-122.908044,49.202894));
var markRichmond = new GMarker(new GPoint(-123.182738,49.125524));
function loadMap() {	// alert("test");
	if (GBrowserIsCompatible()) {
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
		map1 = new GMap(document.getElementById("map1"));
		map1.addControl(new GSmallMapControl(), topRight);	
		map1.centerAndZoom(new GPoint(-122.908044,49.202894), 2); // NEW WEST 
		map1.addOverlay(markNewWest);
		map2 = new GMap(document.getElementById("map2"));
		map2.addControl(new GSmallMapControl(), topRight);	
		map2.centerAndZoom(new GPoint(-123.182738,49.125524), 2); // Richmond 
		map2.addOverlay(markRichmond);
	}
}
	
