var myOffsetH = 500;
var myOffsetW = 740;
var minTop = 0;
var minLeft = 0;
function ieSetup() { window.onresize = reBox; }
function reBox() {
	var TheCheat = document.getElementById('cheater');
	var TheCBox = document.getElementById('truC');
	var TheLNBox = document.getElementById('LNRuler');
	var RealLNH = TheLNBox.offsetHeight;
	var RealSizeH = TheCheat.offsetHeight;
	var RealSizeW = TheCheat.offsetWidth;
	var RealCSizeH = TheCBox.offsetHeight;
	var RealCSizeW = TheCBox.offsetWidth;
	var idealWidth = 900;
	var TheMiddle = (RealSizeW / 2);
	var TheLeftEdge = (TheMiddle - (idealWidth / 2));
	var TheRightEdge = (TheMiddle + (idealWidth / 2));
	if (TheLeftEdge <= minLeft) {
		TheLeftEdge = 0;
		TheRightEdge = idealWidth;
		TheMiddle = idealWidth / 2;
	}
	var bottomOffset = 30;
	var topOffset = 40;
	var topBar = 100;
	var leftNav = 175;
	var TheContentHeight = (RealSizeH - bottomOffset - topOffset - topBar - 33);
	var theMinimumHeight = RealLNH + 20;
	
	document.getElementById('brownBG').style.left = TheLeftEdge+"px";
	document.getElementById('blackBG').style.left = TheLeftEdge+1+"px";
	document.getElementById('whiteBGb').style.left = TheLeftEdge+2+"px";
	document.getElementById('topBar').style.left = TheLeftEdge+2+"px";
	document.getElementById('CFrame').style.left = TheLeftEdge+leftNav+2+"px";
	document.getElementById('CFrame').style.width = idealWidth-leftNav-6+"px";
	document.getElementById('truC').style.width = idealWidth-leftNav-26+"px";
	document.getElementById('leftNav').style.left = TheLeftEdge+2+"px";
	document.getElementById('leftNav').style.width = leftNav+"px";
	document.getElementById('navBox1').style.left = TheLeftEdge+1+"px";
	document.getElementById('navBox2').style.left = TheLeftEdge+2+"px";
	
	// document.getElementById('copyright').innerHTML = theMinimumHeight+" > "+TheContentHeight;
	
	if ((theMinimumHeight+30) > TheContentHeight ) { //  alert ("ping");
		document.getElementById('brownBG').style.height  = theMinimumHeight+topOffset+bottomOffset+topBar+"px";
		document.getElementById('blackBG').style.height  = theMinimumHeight+topOffset+bottomOffset+topBar-7+"px";
		document.getElementById('whiteBGb').style.height = theMinimumHeight+topOffset+bottomOffset+topBar-9+"px";
		document.getElementById('CFrame').style.height   = theMinimumHeight+"px";
		document.getElementById('leftNav').style.height  = theMinimumHeight+20+"px";
		document.getElementById('copyright').style.top = theMinimumHeight+topOffset+bottomOffset+topBar+35+"px";
		document.getElementById('khaoMS').style.top = theMinimumHeight+topOffset+bottomOffset+topBar+50+"px";
		
	} else if (RealCSizeH > TheContentHeight ) { 
		document.getElementById('brownBG').style.height  = RealSizeH-topOffset-bottomOffset+"px";
		document.getElementById('blackBG').style.height  = RealSizeH-topOffset-bottomOffset-2+"px";
		document.getElementById('whiteBGb').style.height = RealSizeH-topOffset-bottomOffset-4+"px";
		document.getElementById('CFrame').style.height   = RealSizeH-topOffset-bottomOffset-topBar-65+"px";
		document.getElementById('leftNav').style.height  = RealSizeH-topOffset-bottomOffset-topBar-65+20+"px";
		document.getElementById('copyright').style.top = RealSizeH-30+"px";
		document.getElementById('khaoMS').style.top = RealSizeH-15+"px";
	} else { // I COULD use this to lock the bottom panel to the max height of the content.......but right now... I'm not
		document.getElementById('brownBG').style.height  = RealSizeH-topOffset-bottomOffset+"px";
		document.getElementById('blackBG').style.height  = RealSizeH-topOffset-bottomOffset-2+"px";
		document.getElementById('whiteBGb').style.height = RealSizeH-topOffset-bottomOffset-6+"px";
		document.getElementById('CFrame').style.height   = RealSizeH-topOffset-bottomOffset-topBar-65+"px";
		document.getElementById('leftNav').style.height  = RealSizeH-topOffset-bottomOffset-topBar-65+20+"px";
		document.getElementById('copyright').style.top = RealSizeH-30+"px";
		document.getElementById('khaoMS').style.top = RealSizeH-15+"px";
	}
	document.getElementById('address').style.width = 290+"px";
	document.getElementById('address').style.left = TheRightEdge-300+"px";
	document.getElementById('address').style.top = 1+"px";
	document.getElementById('copyright').style.width = 450+"px";
	document.getElementById('copyright').style.left = TheRightEdge-460+"px";
	document.getElementById('khaoMS').style.width = 300+"px";
	document.getElementById('khaoMS').style.left = TheLeftEdge+10+"px";
	document.getElementById('cheater').style.zIndex = 1;
}
//Confirm Delete
function confirmdelete() { if (confirm("Are you sure you want to delete? - Delete is PERMANENT")) { return true; } else { return false;}}

var lastRequest = "index.cfm";
// starting main contetnt grabber
var M_contentJax
function doM_Content(DocID) {  // engine for pulling Documents
	M_contentJax=GetXmlHttpObject();
	var url="CMS/apps/_content.cfm";
	url=url+"?docid="+DocID;
	url=url+"&randInt="+Math.random();
	lastRequest = url;
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}
function doUpContent(DocID) {  // engine for pulling Documents from within Documents
	M_contentJax=GetXmlHttpObject();
	var url="_content.cfm";
	url=url+"?docid="+DocID;
	url=url+"&randInt="+Math.random();
	lastRequest = url;
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}
function doM_FContent(FID) { // engine for pulling Folders
	M_contentJax=GetXmlHttpObject();
	var url="CMS/apps/_content.cfm";
	url=url+"?fid="+FID;
	url=url+"&randInt="+Math.random();
	lastRequest = url;
	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.
	M_contentJax=GetXmlHttpObject();
	if (DocID.indexOf('?') == -1){	var url=DocID+"?randInt="+Math.random(); } else { var url=DocID+"&randInt="+Math.random(); }
	lastRequest = url;
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}

/*
var comJax
function addCom(DocID) { 
	comJax=GetXmlHttpObject();
	var url="CMS/apps/_addCom.cfm";
	url=url+"?docid="+DocID;
	url=url+"&randInt="+Math.random();
	comJax.onreadystatechange=doAddComView;
	comJax.open("GET",url,true);
	comJax.send(null);
}
function doAddComView() { 
	if (comJax.readyState==4) { 
		document.getElementById("addComBox").innerHTML=comJax.responseText;
	}
}
*/
function addCom(DocID) { 
	document.getElementById("addComBox").innerHTML="<hr>Provide Your Comment:<br><iframe src='CMS/apps/_addCom.cfm?docid="+DocID+"' frameborder='0' style='width: 650px; height: 275px; margin: 0px; padding: 0px;'></iframe>";
}
function editCom(com) { 
	document.getElementById("comment_"+com).innerHTML="<hr>Change Your Comment:<br><iframe src='CMS/apps/_editCom.cfm?com="+com+"' frameborder='0' style='width: 650px; height: 275px; margin: 0px; padding: 0px;'></iframe>";
}
/*
function doI_Content(DocID,ItemID) { 
	M_contentJax=GetXmlHttpObject();
	var url="CMS/apps/UGalDataReturn.cfm";
	url=url+"?docid="+DocID+"&id="+ItemID+"&randInt="+Math.random();
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",url,true);
	M_contentJax.send(null);
}
*/
function loadContent(thisLink) {
	M_contentJax=GetXmlHttpObject();
	M_contentJax.onreadystatechange=doContentView;
	M_contentJax.open("GET",thisLink,true);
	M_contentJax.send(null);
}

//std pop up script
var newwin;
function launchWin(winurl,winname,winfeatures){
		thisFList = "location=1,status=1,scrollbars=1,resizable=1,height=600,width=800";
         newwin = window.open(winurl,winname,thisFList);
         setTimeout('newwin.focus();',250);        
 }
//Printable document pop up script
var newwin;
function printable(){
		thisFList = "location=0,menubar=1,status=1,scrollbars=1,resizable=1,height=600,width=800";
		var thisPrint = lastRequest.replace(/_content/,"_printable");
         newwin = window.open(thisPrint,"printablePage",thisFList);
         setTimeout('newwin.focus();',250);        
 }

function loadScript(scriptURL) {
 	var scriptElem = document.createElement('SCRIPT');
 	scriptElem.setAttribute('language', 'JavaScript');
 	scriptElem.setAttribute('src', scriptURL);
 	document.body.appendChild(scriptElem);
 }
function doContentView() { 
	if (M_contentJax.readyState==4) { 
//	document.getElementById("M_Content").style.background="#FFFFFF";
	
		if (M_contentJax.responseText.indexOf('<!--imCalEditor-->') > -1) {
			//loadScript(scriptURL);

			document.getElementById("truC").innerHTML=M_contentJax.responseText;
			
		} else if (M_contentJax.responseText.indexOf('<!--imaOpenTable-->') > -1) {
			
			
		} else if (M_contentJax.responseText.indexOf('<!--imalink-->') > -1) { 
			linkArr = M_contentJax.responseText.split('~');
			if (linkArr[2] == 1) { window.open(linkArr[1],'_blank')    // launchWin(linkArr[1],'popUp');
			} else if (linkArr[2] == 0) { window.parent.location="loadContent(linkArr[1])" // loadContent(linkArr[1]);
			}
		} else {
			document.getElementById("truC").innerHTML=M_contentJax.responseText;
		}
	}
}
// check that AJAX is possible 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;
} 

var hottColor="#EEEEEE";
var baseColor="#EEEEEE";
var overColor="#FFFFFF";
var txtOnCol="#851d1c";
var txtOffCol="#000000";
var txtHotCol="#579493";
var idone = null;

// 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="#ebe8c2"; myDiv.style.color="#990000";	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
	}
}
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="#000000";									// 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="#000000";																	// 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
	}
}

// Left Navigation Scripts
var LNObject = "";
var LNOffObject = "";
//  LNtop_lg
function doFMe(myObj,wutVar,offVar) { 
	if (LNObject != myObj) {
 		undoFMe();
		LNObject = myObj;
		LNOffObject = offVar;
		myObj.innerHTML = wutVar;
		reBox();
	}
}
function undoFMe() { 
	if (LNObject != "") {
		LNObject.innerHTML = LNOffObject ;
		LNObject = "";
		LNOffObject = "";
		reBox();
	}
}

// Photogallery large image open script. - NOT IN USE
var imageJax
function placePhoto(DocID,myID) {	

	imageJax=GetXmlHttpObject();
	var url="CMS/apps/PGalDataReturn.cfm";
	url=url+"?docid="+DocID;
	url=url+"&id="+myID;
	url=url+"&randInt="+Math.random();
	imageJax.onreadystatechange=doImageView;
	imageJax.open("GET",url,true);
	imageJax.send(null);
	
	var TheCheat = document.getElementById('cheater');
	var RealSizeH = TheCheat.offsetHeight;
	var RealSizeW = TheCheat.offsetWidth;
	document.getElementById('spareDiv1').style.width = RealSizeW+"px";
	document.getElementById('spareDiv1').style.height = RealSizeH+"px";
	document.getElementById('spareDiv1').style.background = "#eeeeee";
	document.getElementById('spareDiv1').style.filter = "alpha(opacity=50)";
	document.getElementById('spareDiv1').style.KHTMLOpacity = ".50";
	document.getElementById('spareDiv1').style.MozOpacity = ".50";
	document.getElementById('spareDiv1').style.opacity = ".50";
	document.getElementById('spareDiv1').style.zIndex = "1001";
	document.getElementById('spareDiv2').style.zIndex = "1002";
		document.getElementById('spareDiv1').style.left = minLeft+"px";
		document.getElementById('spareDiv2').style.left = minLeft+"px";
		document.getElementById('spareDiv1').style.top = 10+"px";
		document.getElementById('spareDiv2').style.top = "20px";
	//	document.getElementById('spareDiv2').style.background = "#000000";
	document.getElementById('spareDiv2').style.height = RealSizeH-200+"px";
	document.getElementById('spareDiv2').style.width = RealSizeW-200+"px";
}
function doImageView() { 
	if (imageJax.readyState==4) { 
	document.getElementById('spareDiv2').innerHTML = imageJax.responseText;
	}
}
// Hide Photo.<div></div>
function hidePhoto() {	
	document.getElementById('spareDiv1').style.width = "1px";
	document.getElementById('spareDiv2').style.width = "1px";
	document.getElementById('spareDiv1').style.height = "1px";
	document.getElementById('spareDiv2').style.height = "1px";
	document.getElementById('spareDiv1').style.background = "#579493";	
//	document.getElementById('spareDiv2').style.background = "#579493";
	document.getElementById('spareDiv1').innerHTML = "&nbsp;";
	document.getElementById('spareDiv2').innerHTML = "&nbsp;";
	document.getElementById('spareDiv1').style.top = "1px";
	document.getElementById('spareDiv2').style.top = "1px";
	document.getElementById('spareDiv1').style.left = "1px";
	document.getElementById('spareDiv2').style.left = "1px";
}

// ####################### NEW LEFT NAVIGATION

function initAnims() {	
	var baseHeight = 14;
	var baseHeight2 = 15;
	var bottomPad = 5;
	var animElements = document.getElementById("leftNav").getElementsByTagName("ul")
	for(var i=0; i<animElements.length; i++) {
			animElements[i].onmouseover = heightChange;
		 	animElements[i].onmouseout = heightRestore;
		}
	function heightChange() {
		if (!this.currentHeight) { this.currentHeight = baseHeight2; } 
		if (this.heightChangeMemInt) { window.clearInterval(this.heightChangeMemInt);	 }
		var thisElems = document.getElementById(this.id).getElementsByTagName("li")
		var toHeight = thisElems.length*baseHeight+baseHeight2+bottomPad;
		doHeightChangeMem(this,this.currentHeight,toHeight,200,10,3); // elem,startHeight,endHeight,steps,intervals,powr
		}
	function heightRestore() {
		if (!this.currentHeight) { return; 
		} else { 
			var toHeight = baseHeight2; 
			doHeightChangeMem(this,this.currentHeight,toHeight,100,1,1); } // elem,startHeight,endHeight,steps,intervals,powr    (minValue,maxValue,totalSteps,actualStep,powr)
		}
	var animElements = document.getElementById("leftNav").getElementsByTagName("h6")
	for(var i=0; i<animElements.length; i++) {
		animElements[i].onmouseover = doMex;
		animElements[i].onmouseout = undoMex;
		}
	var animElements = document.getElementById("leftNav").getElementsByTagName("li")
	for(var i=0; i<animElements.length; i++) {
		animElements[i].onmouseover = doMey;
		animElements[i].onmouseout = undoMey;
		}
	function doMex()	{ this.style.backgroundImage = "url('images/LnavItemOn.gif')"; }
	function undoMex()	{ this.style.backgroundImage = "url('images/LnavItemOff.gif')"; }
	function doMey()	{ this.style.background = "#ffffcd"; this.style.color="#000000"; }
	function undoMey()	{ this.style.background = "#e7e3ad"; this.style.color="#666666"; }
}

function doHeightChangeMem(elem,startHeight,endHeight,steps,intervals,powr) {
	if (elem.heightChangeMemInt) window.clearInterval(elem.heightChangeMemInt);
	var actStep = 0;
	elem.heightChangeMemInt = window.setInterval(
		function() {
			elem.currentHeight = easeInOut(startHeight,endHeight,steps,actStep,powr);
			elem.style.height = elem.currentHeight+"px";
			actStep++;
			if ((startHeight-1 >= endHeight) && (actStep > steps)) {
				// elem.style.backgroundImage = "url('../images/LnavItemOff.gif')"				
				window.clearInterval(elem.heightChangeMemInt);
				reBox();
			} else if ((endHeight >= startHeight-1) && (actStep > steps)) {
				// elem.style.backgroundImage = "url('../images/LnavItemOn.gif')"				
				window.clearInterval(elem.heightChangeMemInt);
				reBox();
			} else if (actStep > steps) {
				window.clearInterval(elem.heightChangeMemInt);
			}
		}
		,intervals)
}
// core looper... One of the coolest snippits I've ever seen: Generic Animation Step Value Generator By www.hesido.com
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)
}
