/* 
 * Script for determining how much space is found on the left side
 * of each page, depending on which browser you're using
 */

var ieTop = 0;
var mozTop = 0;
var layLeft = 0;

function rollrow(name, stat) {
	var lnk = document.getElementById(name);
	if (stat == "on") {
		lnk.style.backgroundImage = "url(images/lt_menu_rollunder.gif)";
	} else {
		lnk.style.backgroundImage = "";	
	}
}

 function checkBrowser() {
	// Default browser is Netscape/Mozilla
	var curBrowser = "Netscape";
	var ffVersion = new Array();
	var splitFfVersion;
	if (navigator.userAgent.indexOf("Mac OS") > -1) {		// Check for a Macintosh running something other than IE
		curBrowser = "Mac";
        if (navigator.userAgent.indexOf("Firefox") > -1) { 	// Check for Firefox on a Mac and parse out the version
			splitFfVersion = navigator.userAgent.substr((navigator.userAgent.indexOf("Firefox")+8));
			ffVersion = splitFfVersion.split(".");
			if (ffVersion[1] >= 5) {
				curBrowser = "MacFox1.5";
			} else {
				curBrowser = "MacFox"
			}
		}
		
	} else if (navigator.userAgent.indexOf("Firefox") > -1) {	// Check for a Firefox and parse out the version
		splitFfVersion = navigator.userAgent.substr((navigator.userAgent.indexOf("Firefox")+8));
		ffVersion = splitFfVersion.split(".");
		if (ffVersion[1] >= 5) {
			curBrowser = "Firefox1.5";						// 1.5 and higher behave differently from earlier versions
		}
	} else if (navigator.userAgent.indexOf("MSIE") > -1) {	// Check for IE and if a Mac is running it.
		curBrowser = "IE";
		if (navigator.userAgent.indexOf("Mac") > -1) { curBrowser = "MacIE"; }
	}
	return curBrowser;
 }
 
 function activeRow() {		 		// Moves the tree icon to the correct row
	var actPg = document.URL;		// The basis for moving is on the URL of the individual pages
    var actSlash = actPg.lastIndexOf("/")+1;	// Strip the page name from the URL (take off everything but the .asp
    var actDot = actPg.lastIndexOf(".");
    var actLen = actDot - actSlash;
	actPg  = actPg.substr(actSlash, actLen);
	var tree = new Image(17,50);
	if ((checkBrowser().indexOf("IE")) > -1 || (checkBrowser().indexOf("Mac") > -1))  {
		tree.src = "images/lt_menu_tree_ie.gif";
	} else {
  		tree.src = "images/lt_menu_tree.gif";
	}
	switch (actPg) {
		case "calendar":
			document.images.calendar_pic.src = tree.src;
			break;		
		case "services":
			document.images.service_pic.src = tree.src;
			break;		
		case "about_us":
			document.images.history_pic.src = tree.src;
			break;
		case "directions":
			document.images.direction_pic.src = tree.src;
			break;
		case "contact_us":
			document.images.contact_pic.src = tree.src;
			break;		
		case "sendemail":
			document.images.contact_pic.src = tree.src;
			break;		
		case "photo_tour":
			break;
		default:
			document.images.welcome_pic.src = tree.src;
			break;
	}
}
 
 function ltMargin() {				// calculates the width of the left margin if the page is bigger than 1024 pixels
	 var winWidth;
	 var lt;
	 if ((checkBrowser() == "IE") || (checkBrowser() == "MacIE")) {
		 winWidth = document.body.clientWidth;
	 } else {
		 winWidth = window.innerWidth;
	 }
	 if (winWidth > 1016) {
		 lt = Math.round((winWidth-1016)/2);
	 } else {
		 lt = 0;
	 }
	 return lt;
 }
 
 function spaceLayer(layName, indent, shiftTop) { 	// moves the given layer to the correct relative location
	var lt = ltMargin();				// the indent variable designates that a layer is not left-justified, but somewhere else on the page
	var top = mozTop;					// the shiftTop variable moves the layer vertically (usually only used for textbox layers)
	var layer = document.getElementById(layName);
	if (indent) { lt = lt + layLeft - 2; }
	switch (checkBrowser()) {			// the layers are positioned depending on the browser, each of which has a different positioning scheme.
		case "Firefox1.5":
			lt += 3;
			break;
		case "IE":
			if (ltMargin() > 0) {
				lt += 8;
			} else {
				lt +=3;
			}
			top = ieTop;
			break;
		case "Mac":
			if (ltMargin() > 0) {
				lt += 10;
			} else {
				lt += 3;
			}
			break;
		case "MacIE":
			if (ltMargin() > 0) {
				lt += 8;
			} else {
				lt += 3;
			}
			top = ieTop;
			break;
		case "MacFox":
			lt += 3;
			break;
		case "MacFox1.5":
			lt += 3;
			break;
		case "Netscape":
			lt += 3;
			break;
	}
	if (shiftTop) { layer.style.top = top +"px"; }
	layer.style.left = lt +"px";
 }
 
 function layShifter() {			// function to trigger a reload command
	 if (document.getElementById("textbox")) {
		 spaceLayer("textbox", true, true);
	 }
	 if (document.getElementById("ltMenu")) {
		 spaceLayer("ltMenu", false, false);
	 }
	 activeRow();
 }
 
if (!document.getElementById) {			// Checks to see if the browser can handle the JavaScript Code
	window.location = "browser.asp?err=true";
}
