
// Sniff for the two major browsers
	var ie  = (document.all)? true:false
	var ns6 = ((document.getElementById)&&(!ie))? true:false

// Sniff for Mac, used for IE Mac browsers
	var mac = (navigator.userAgent.toUpperCase().indexOf("MAC") > -1)? true:false

// Sniff for AOL, used in certain cases where AOL won't pop open a window the size we want it
	var aol = (navigator.userAgent.toUpperCase().indexOf("AOL") > -1)? true:false

// Used to test if a value is 'undefined'.  What 'undefined' represents is different for each
// browser, but any variable that has not been defined a value IS 'undefined' in all browsers.
// So, we'll test against this variable to see if another is 'undefined'.
	var undef;

	var bgXcoord = 0;

	var HideText = "";

// var is declared in universal nav offsite code, used to define full path.
// we don't want to hose the value, so we'll check if it has one.
	if (T1navPath == undef) {
		var T1navPath = "";
	}

	var PreloadComplete = false;
	var HomePreloadComplete = false;

	var MouseOverColor = "#999999";
	var MouseOffColor = "#CCCCCC";

// Global Variables, used to set which model page we're on
	var gVCmodel =  "index";
	var gModelName = "";
	var gLegacyAbbrev = "";
	var gBrochurePDAAbbrev = "";
	var gPageName = "";


// These links are considered absolute links at this point.
// Adjust topNavMacWidth[] when the contents of this nav change.
	var topNavMenu = new Array();

	topNavMenu["Welcome0"] = new Array("The Saint Patrick Difference", "/welcome/index.htm");
	topNavMenu["Welcome1"] = new Array("Spiritual Life", "/welcome/spirituallife.htm");
	topNavMenu["Welcome2"] = new Array("Testimonials", "/welcome/testimonials.htm");
	topNavMenu["Welcome3"] = new Array("Saint Patrick's Entry in ScareCrow Contest", "/OzSlideShow.html");


	topNavMenu["Admissions0"] = new Array("Admission Policy", "/admissions/index.htm");
	topNavMenu["Admissions1"] = new Array("Tuition", "/admissions/tuition.htm");

	topNavMenu["Academics0"] = new Array("Curriculum", "/academics/index.htm");
	topNavMenu["Academics1"] = new Array("Student Programs", "/academics/studentcouncil.htm");
	topNavMenu["Academics2"] = new Array("Special Events", "/academics/christmas.htm");
//	topNavMenu["Academics3"] = new Array("Facilities", "/academics/facilities.htm");

	topNavMenu["SchoolLife0"] = new Array("Calendar", "/life/calendar.pdf");
	topNavMenu["SchoolLife1"] = new Array("School Hours", "/life/hours.htm");
	topNavMenu["SchoolLife2"] = new Array("Clubs and Sports", "/life/chessdebate.htm");
	topNavMenu["SchoolLife3"] = new Array("Dress Code", "/life/dresscode.htm");
//	topNavMenu["SchoolLife4"] = new Array("Homework Help", "/life/index.htm");
//	topNavMenu["SchoolLife5"] = new Array("Parent to Teacher", "/life/index.htm");

//	topNavMenu["News0"] = new Array("Announcements", "/news/index.htm");
	topNavMenu["News0"] = new Array("Newsletters", "/news/newsletters.asp");
	topNavMenu["News1"] = new Array("In the Press", "/news/press.asp");

	topNavMenu["CommunitySupport0"] = new Array("Alumni", "/community/index.htm");
	topNavMenu["CommunitySupport1"] = new Array("Business Support", "/community/business.htm");

	topNavMenu["ContactUs0"] = new Array("Phone & Address", "/contact/index.htm");
//	topNavMenu["ContactUs1"] = new Array("Feedback", "/contact/feedback.htm");

	var topNavContents = new Array();
	topNavContents["Welcome"] = "";
	topNavContents["Admissions"] = "";
	topNavContents["Academics"] = "";
	topNavContents["SchoolLife"] = "";
	topNavContents["News"] = "";
	topNavContents["CommunitySupport"] = "";
	topNavContents["ContactUs"] = "";

	var topNavMacWidth = new Array();
	topNavMacWidth["Welcome"] = "130";
	topNavMacWidth["Admissions"] = "175";
	topNavMacWidth["Academics"] = "125";
	topNavMacWidth["SchoolLife"] = "175";
	topNavMacWidth["News"] = "175";
	topNavMacWidth["CommunitySupport"] = "175";
	topNavMacWidth["ContactUs"] = "175";


// Layer Build functions.  The IF verifies that, if a layer doesn't exist
// the function will return null instead of a JavaScript error.
	function refLayer(layerName) {
		var LAYref;
		if (ie) {
			if (document.all[layerName]) {
				document.all[layerName].layerWidth = function() { return this.scrollWidth; };
				LAYref = document.all[layerName];
				HideText = "hidden";
			} else {
				LAYref = null;
			}
		} else {
		    // default to NS6+
			if (document.getElementById(layerName)) {
				HTMLElement.prototype.layerWidth = function() { return this.offsetWidth; };
				LAYref = document.getElementById(layerName);
					HideText = "hidden";
			} else {
				LAYref = null;
			}
		}
			return LAYref;
	}


// Functions to determine browser window width/height
	function getInsideWindowWidth() {
		if (ie) {
			return document.body.scrollWidth
		} else {
			return document.width
		}
	}

	function getInsideWindowHeight() {
		if (ie) {
			return document.body.scrollHeight
		} else {
			return document.height
		}
	}


// Calculate Offsets from current item.
	function eventXoffset(nsEvt) {
		if (ie) {
			return document.body.scrollLeft - document.body.clientLeft + event.clientX - event.offsetX;
		} else {
			return nsEvt.pageX - nsEvt.layerX;
		}
	}

	function eventYoffset(nsEvt) {

		if (ie) {
			return document.body.scrollTop - document.body.clientTop + event.clientY - event.offsetY;
		} else {
			return nsEvt.pageY - nsEvt.layerY
		}
	}

	function layerWidth(LAYer) {
		if (ie) {
			return LAYer.scrollWidth;
		} else {
			return LAYer.offsetWidth;
		}
	}
	
// Create the objects
	function menuInit() {
		LAYtopNavMenu = refLayer("topNavDIV");
		LAYarrowHL = refLayer("arrowHL");
		PreloadComplete = true;
	}


//****************************************
//** Top Nav DHTML Menu Functions START **
//****************************************

	var NotInMenuNow = true;

	function topNavBuild(menuName) {
		var i, menuHTML, linkURL;
// Build Menu Contents.  Should only be done once.
		i = 0;
		menuHTML = "";

		while (topNavMenu[menuName + i]) {
		//	menuHTML += '<DIV CLASS="menuSpacer" STYLE="width:52px; height:1px;"></DIV>\n';

// If this is a JavaScript command, just use it instead of trying a document.location.href.
			if (topNavMenu[menuName + i][1].toLowerCase().indexOf("javascript:") == 0) {
				linkURL = topNavMenu[menuName + i][1].substr(11);
			} else if (topNavMenu[menuName + i][1].toLowerCase().indexOf("http") == 0) {
				linkURL = "top.location.href='"+topNavMenu[menuName+i][1]+"'";
			} else {
				linkURL = "top.location.href='"+T1navPath+topNavMenu[menuName+i][1]+"'";
			}
			menuHTML += '<DIV CLASS="menuItem" onClick="'+linkURL+'" style="cursor: pointer ;" onMouseOver="changeBGcolor(this, MouseOverColor)" onMouseOut="changeBGcolor(this, MouseOffColor)"'

			if (ie && mac) {
				menuHTML += ' STYLE="width:'+topNavMacWidth[menuName]+'px;"'
			}
			menuHTML += '><NOBR>'+topNavMenu[menuName + i][0]+'&nbsp;</NOBR></DIV>\n';
			i++;
		}

		return menuHTML;
	}



// Top Nav Dropdown functions
// Check PreloadComplete on these just in case
	function showTopNavDD() {
		if (PreloadComplete) {
			NotInMenuNow = false;
			LAYtopNavMenu.style.visibility = "inherit";
		}
	}

	function hideTopNavDD(FirstTry) {
		if (PreloadComplete) {
			if (FirstTry) {
				NotInMenuNow = true;
				setTimeout("hideTopNavDD(false)", 50);
			} else if (NotInMenuNow) {
				LAYtopNavMenu.style.visibility = "hidden";
			}
		}
	}


	function revealTopNavDD(menuName, xCoord, evt) {
		var MenuEdge, MDxCoord, MDyCoord;

		if (PreloadComplete) {
		    //** Hide menu and move it off the page.  This resolves menu flicker. **
			NotInMenuNow = true;
			hideTopNavDD(false);
			LAYtopNavMenu.style.left = -200;
			LAYtopNavMenu.style.top = -200;

// If we haven't viewed this menu before, write out its contents and store in array.
			if (topNavContents[menuName] == "") {
				topNavContents[menuName] = topNavBuild(menuName);
			}

			LAYtopNavMenu.innerHTML = topNavContents[menuName];

// Calculate right edge of menu.  If it's past the edge of the centered table, align it so it is.
// This layer is in a table cell, which triggers an IE5 Mac positioning bug.
// To fix it, set these vars to 0.
			if (ie && mac) {
				MDxCoord = 0;
				MDyCoord = 0;
			} else {
				MDxCoord = eventXoffset(evt);
				MDyCoord = eventYoffset(evt);
			}

			LeftPageStart = (getInsideWindowWidth()-778)/2;
			MenuEdge = MDxCoord + xCoord + layerWidth(LAYtopNavMenu) - LeftPageStart;

			if (MenuEdge > 778) {
// The right edge of the menu is beyond the designed-for
// 778 pixel page width.  Adjust MDxCoord appropriately.
				MDxCoord -= (MenuEdge-776);
			}

		    //** Set left & top coordinates. **
			LAYtopNavMenu.style.left = MDxCoord + xCoord-220;
			LAYtopNavMenu.style.top = MDyCoord + 32 - 18;

			showTopNavDD();
//			setTimeout("showTopNavDD()", 50);
		}
	}


	function changeBGcolor(LAYer, hexColor) {
		if (PreloadComplete) {
			LAYer.style.backgroundColor = hexColor;
		}
	}


//**************************************
//** Top Nav DHTML Menu Functions END **
//**************************************

//**************************************
//** Nav DHTML Arrows Functions START **
//**************************************

	var ArrowHLURL = "";
	var ArrowHLmodel = "";

	function moveArrowHL(AHxOffset, AHyOffset, evt) {
		var AHxCoord, AHyCoord;

		if (PreloadComplete) {
			AHxCoord = eventXoffset(evt);
			AHyCoord = eventYoffset(evt);

			if (ie) {
				AHyCoord = AHyCoord - 1;
			}

			LAYarrowHL.style.left = AHxCoord + AHxOffset;
			LAYarrowHL.style.top = AHyCoord + AHyOffset;

			showArrowHL();
		}
	}

	function showArrowHL() {
		if (PreloadComplete) {
			LAYarrowHL.style.visibility = "inherit";
		}
	}

	function hideArrowHL() {
		if (PreloadComplete) {
			LAYarrowHL.style.visibility = "hidden";
		}
	}

	function clickArrowHL() {
		if (ArrowHLURL != "") {
			top.location.href = ArrowHLURL;
		}
	}


//************************************
//** Nav DHTML Arrows Functions END **
//************************************

//*****************************************
//** Nav Rollover Arrows Functions START **
//*****************************************

	plArrowHL = new Image();
	plArrowHL.src = "/assets/arrow_highlight.gif";
	plArrowGR = new Image();
	plArrowGR.src = "/assets/arrow_gray.gif";
	plArrowBK = new Image();
	plArrowBK.src = "/assets/arrow_current.gif";

	plArrowUpHL = new Image();
	plArrowUpHL.src = "/assets/arrow_up_highlight.gif";
	plArrowUpGR = new Image();
	plArrowUpGR.src = "/assets/arrow_up_gray.gif";

	CurArrowGroup = new Array();

	function arrowHL(imgName) {
		if (document.images[imgName]) {
			document.images[imgName].src = plArrowHL.src;
		}
	}

	function arrowHLBK(imgName, lastImg) {
		if (document.images[imgName]) {
			if (imgName != CurArrowGroup[lastImg]) {
				document.images[imgName].src = plArrowHL.src;
			}
		}
	}

	function arrowGR(imgName) {
		if (document.images[imgName]) {
			document.images[imgName].src = plArrowGR.src;
		}
	}

	function arrowGRBK(imgName, lastImg) {
		if (document.images[imgName]) {
			if (imgName == CurArrowGroup[lastImg]) {
				document.images[imgName].src = plArrowBK.src;
			} else {
				document.images[imgName].src = plArrowGR.src;
			}
		}
	}

	function arrowBK(imgName, lastImg) {
		if (CurArrowGroup[lastImg] != "-1") {
			if (document.images[CurArrowGroup[lastImg]]) {
				document.images[CurArrowGroup[lastImg]].src = plArrowGR.src;
			}
		}

		if (document.images[imgName]) {
			document.images[imgName].src = plArrowBK.src;
			CurArrowGroup[lastImg] = imgName;
		}
	}


	function arrowUpHL(imgName) {
		if (document.images[imgName]) {
			document.images[imgName].src = plArrowUpHL.src;
		}
	}

	function arrowUpGR(imgName) {
		if (document.images[imgName]) {
			document.images[imgName].src = plArrowUpGR.src;
		}
	}

//***************************************
//** Nav Rollover Arrows Functions END **
//***************************************

//****************************
//** Flash Sniffing START ****
//****************************

	// Check for Flash, set vars if T/F
		var Flash4 = false;
		var Flash5 = false;
		var Flash6 = false;
		var FlashEnabled = false;
	// Default is False, so we only need to set it as True.
		if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] ) {
			// Check for Flash in Netscape
			var nsFlash = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
			if (nsFlash) {
				var FlashVer = parseInt(nsFlash.description.substring(nsFlash.description.indexOf(".")-1));
				if (FlashVer >= 6) {
					Flash6 = true;
				} else if (FlashVer == 5) {
					Flash5 = true;
				} else if (FlashVer == 4) {
					Flash4 = true;
				}
			}
		} else if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
			var f4Inst;
			var f5Inst;
			var f6Inst;

			eval('try { f4Inst = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.4"); f5Inst = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.5"); f6Inst = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); } catch (e) { }');

			if (f6Inst != null) {
				Flash6 = true;
			} else if (f5Inst != null) {
				Flash5 = true;
			} else if (f4Inst != null) {
				Flash4 = true;
			}

			f4Inst = null;
			f5Inst = null;
			f6Inst = null;
		}

		if (document.location.search == "?flash=disabled") {
			Flash4 = false;
			Flash5 = false;
			Flash6 = false;
			// FlashEnabled default is false
		} else if (Flash5 || Flash6) {
			FlashEnabled = true;
		}


//**************************
//** Flash Sniffing END ****
//**************************

//**************************
//** Misc Functions START **
//**************************

	function newCursor(imgName, curName) {
		if (PreloadComplete) {
			document.images[imgName].style.cursor = curName;
		}
	}

	//****************************************************
	//** Popup function Fixes IE making popup windows   **
	//** 20px higher than specified when menubar is on  **
	//** Parameters can be passed in as necessary 	    **
	//** returns a reference to the	window if needed    **
	//****************************************************
	
	function popup(popupurl,winName,w,h,params) {
	    // Build parameter list manually.  This lets us override individual defaults as needed.

		var paramList = "";
		if (params == undef) {
			params = "";
		}
		params = params.toLowerCase();
		if (params.indexOf("menubar=no") != -1) {
			paramList = paramList + ",menubar=no";
		} else {
		    // default
			paramList = paramList + ",menubar=yes";
		    // IE adds to the height with a menubar; subtract to keep height the same.
			if (ie && !mac) {
				h = h - 20;
			}
		}
		if ((params.indexOf("scrollbars=no") != -1) || (params.indexOf("scrollbar=no") != -1)) {
			paramList = paramList + ",scrollbars=no";
		} else {
		    // default
			paramList = paramList + ",scrollbars=yes";
		    // IE needs extra space to allow for the phantom scrollbar, or we'll get horizontal scrollbars too.
		    // IE 6.x needs 4px more than IE 5.x, but IE 5.x's width needs vary a lot.  So, we'll set all
		    // IE browsers to use the wider IE 6.x size.
			if (ie) {
				w = w + 17;
			} else {
				w = w + 15;
			}
		}
		if (params.indexOf("resizable=yes") != -1) {
			paramList = paramList + ",resizable=yes";
		} else {
		    // default
			paramList = paramList + ",resizable=no";
		}
		if ((params.indexOf("toolbar=yes") != -1) || (params.indexOf("toolbars=yes") != -1)) {
			paramList = paramList + ",toolbar=yes";
		} else {
		    // default
			paramList = paramList + ",toolbar=no";
		}
//alert(paramList);
		return window.open(popupurl,winName,"top=35,left=130,width=" + w + ",height=" + h + paramList);
	}

//************************
//** Misc Functions END **
//************************
