// stvincent.org DHTML Javascript Library 
// Created 6/20/2004

// Global Variables
var menusArray1, menusArray2, x, y, winW, winH, imageSelect; 
var Timer1, Timer2, Timer3, Timer4, Timer5, Timer6
js = (document.images)? true:false 
is = new Browser()	// The "is" object is used in browser identification

//*********************************************************************
// init: Call this function in the body tag using onLoad="init();" to 
// initialize javascript requirements
//*********************************************************************

function init3() {
	//Track mouse coordinates 
	initMouseEvents();

	//Set top menu art (imgStay and imStaySRC are set in topMenuLogicNew.js)
	setMenu(imgStay,imgStaySRC) 
	imageSelect = imgStay
} 

//*********************************************************************
// The browser function determines the version and type of browser   
// being used to view the web page (used extensively).
//*********************************************************************
function Browser() { 
	//alert(navigator.appName);
	//alert(navigator.appVersion);
	var b=navigator.appName;
	if (b.indexOf('Netscape')!=-1) this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) alert('Unidentified browser.\nThis browser is not supported,');
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ns4=(this.b=="ns" && this.v==4);
	this.ns6=(this.b=="ns" && this.v>=5);
	this.ie=(this.b=="ie" && this.v>=4);
	this.ie4=(this.version.indexOf('MSIE 4')>0);
	this.ie5=(this.version.indexOf('MSIE 5')>0);
	this.ie55=(this.version.indexOf('MSIE 5.5')>0);
	this.ie6=(this.version.indexOf('MSIE 6.0')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	this.def=(this.ie||this.dom); // most used browsers, for faster if loops
	var ua=navigator.userAgent.toLowerCase();
	if (ua.indexOf("win")>-1) this.platform="win32";
	else if (ua.indexOf("mac")>-1) this.platform="mac";
	else this.platform="other";
}



//*********************************************************************
// The following functions are primarily used to position  
// elements on web pages.
//*********************************************************************

function windowWH() {
	winW = (is.ns)? window.innerWidth-16 	: document.body.offsetWidth -20
	winH = (is.ns)? window.innerHeight 		: document.body.offsetHeight
	//status = "Window Height:"+winH+" Window Width:"+winW
}

function initMouseEvents() {
	if (is.ns) document.captureEvents(Event.MOUSEMOVE)
	document.onmousemove = captureMouseCoord 
}

// captureMouseCoord assigns mouse coordinates to x and y for
// both Netscape and IE ... (e) is necessary for Netscape 
function captureMouseCoord(e) { 
	x = (is.ns)? e.pageX : event.clientX+document.body.scrollLeft 
	y = (is.ns)? e.pageY : event.clientY+document.body.scrollTop 
	if  (is.ns && e.target!=document) routeEvent(e)
	//status = "x:"+x+" y:"+y
	//debugger
	return true 
} 

// setXY sets coordinates of a positionable object based on X and Y 
// or the position of mouse (x and y)
// usage: setXY(javascript object representing the div tag, X coordinates, Y coordinates)
function setXY(obj,X,Y) { 

	if (is.ie) { 
	
		if (X) {
			obj.style.pixelLeft = X 
		} 
		else 
		{ 
			if(document.load) {
				// captureMouseCoord()	// IE needed for some reason to get last mouse coordinate(?)
				obj.style.pixelLeft = x
			}
		}

		if (Y) {
			obj.style.pixelTop = Y
		} 
		else 
		{
			if(document.load) {
				obj.style.pixelTop = y
			}
		}
		
	}
	if (is.ns) {

		if (X) {
			obj.style.left = X 
		} else {
			obj.style.left = x
		}
		
		if (Y) {
			obj.style.top = Y
		} else { 
			obj.style.top = y
		}
	}
}







//*********************************************************************
// writeLayer:
// This function is used to re-write the content of the element id 
// (usually a div tag) using the passed text.
//*********************************************************************

function writeLayer(id,nestref,text) {
	//lyrObj = getDiv(id);
	if (is.ie) {
		//lyrObj.innerHTML=text;
		document.all[id].innerHTML=text
	} 
	if (is.ns4) {
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
		lyr.open()
		lyr.write(text)
		lyr.close()
	}
	if (is.ns6) {
		//lyrObj.innerHTML=text;
		document.getElementById(id).innerHTML=text
	} 
}



// The following two functions are used by the top pop-up menu 
// MouseOver function
function rewriteSubMenu(divObj,c,imgName,imgSRC,X,Y) { 
	hideTopMenuImages();							// Reset all Top Menu Images to default
	imageChange(imgName,imgSRC);					// Change the rollover art 
	imageChange('textPopup','textPopup'+ imgName);	// Change the matching textPopup art 
 	writeLayer(divObj.id,null,c);					// Write contents of c to the div object
	setXY(divObj,X,Y);								// Set the X and Y coordinates of the div object 
	show(divObj.id);								// Show the div object 
	sh('block');									// Hide/Show <select> form items
}

function restoreSubMenu(divObj,I) { 
	//var newObj = divObj; 
	if (I == 1) { 
		// MouseOver function
		clearTimeout(Timer1);	//Clear all timeouts set by calling this function with "2"
		clearTimeout(Timer2); 
		clearTimeout(Timer3); 
		clearTimeout(Timer4); 
		clearTimeout(Timer5); 
		clearTimeout(Timer6); 
	} 
	if (I == 2) { 
		// MouseOut function
		Timer1=setTimeout("writeLayer('" + divObj.id + "',null,'')",1); 
		Timer2=setTimeout("hideTopMenuImages()",1); 
		Timer3=setTimeout("imageChange(imgStay,imgStaySRC)",1); 
		Timer4=setTimeout("imageChange('textPopup','textPopupnone')",1); 
		Timer5=setTimeout("hide('" + divObj.id + "')"),1;
		Timer6=setTimeout("sh('none')");
	} 
}

// This function is used by the left-hand menu system to hide or cancel the 
// hidding of a left-hand menu div object
function restoreSubMenu2(divObj,I) { 
	//var newObj = divObj; 
	if (I == 1) { 
		if (1 == 1) {
		clearTimeout(Timer1); 
		}
	} 
	if (I == 2) { 
		Timer1=setTimeout("hide('" + divObj.id + "')"),100;
	} 
}

// This function will hide all select and object tags in the document 
// by setting the body tag class to use "fix" (found in stv.css style sheet)
function sh(sDisplay) {

	if (sDisplay=="block" && document.all) 
	{
		document.body.className = "fix"; 
		//document.getElementById(sId).style.display = "none";
	}
	else if (document.all) 
	{
		document.body.className = "";
		//document.getElementById(sId).style.display = "block";
	}  
	
}

//function sh2(sId,sDisplay) {
//	var selectColl = document.getElementsByTagName("select"); 
//
//	if (sDisplay=="block" && document.all) 
//	{
//		for (i = 0; i < selectColl.length; i++) 
//		{
//			document.getElementById(selectColl[i].id).style.display = "none";
//		}
//		document.body.className = "fix"; 
//	}
//	else if (document.all) 
//	{
//		for (i = 0; i < selectColl.length; i++) 
//		{
//			document.getElementById(selectColl[i].id).style.display = "block";
//		}
//		document.body.className = ""; 
//	}  
//}







// toggleMenu determines and sets obj's visibility. It is used mainly  
// by the "CMS Menu" drop-down activated in the edit website(s)
function toggleMenu(obj) {
	if (is.ie) {
		if (document.all[obj].style.display == "") {
			document.all[obj].style.display = "none"
		} 
		else if (document.all[obj].style.display == "none") {
			document.all[obj].style.display = ""
		}
	}

	if (is.ns6) {
		if (document.getElementById(obj).style.display == "") {
			document.getElementById(obj).style.display = "none"
		} 
		else if (document.getElementById(obj).style.display == "none") {
			document.getElementById(obj).style.display = ""
		} 
	} 
} 



function hideMenusArray1() { 
	numMenus = menusArray1.length 
	for (i=0;i<numMenus;i++) 
	{
		menuX = menusArray1[i] 
		hide(menuX)
	}
}

// usage: show("the name of the div tag")
function show(obj) {								
	divObj = getDiv(obj);							// lookup the div object 
	divObj.style.visibility 	= "visible";		// show the div object
}

// usage: hide("the name of the div tag")
function hide(obj) {								
	divObj = getDiv(obj);							// lookup the div object 
	divObj.style.visibility = "hidden";				// hide the div object
}







//*********************************************************************
// The following functions are used to preload images, set the sections
// image and provide rollover functionality for the top Menu system.
//*********************************************************************

function preload(img,imgSrc) {	// preload loads images to make them available to Javascript
	if (js) {
		eval(img+' = new Image()')
		eval(img+'.src = "'+imgSrc+'"')
	}
}

function imageChange(imgName,imgObj) {
	// selection recorded in imageSelect will not rollover 
	//if (imgName != imageSelect) { 			
		document.images[imgName].src = eval(imgObj+".src")
	//}
}

function hideTopMenuImages() { 
	numImages = menuTopImagesArray.length 
	for (i=0;i<numImages;i++) 
	{
		imageX = menuTopImagesArray[i] 	
		//if (imageX != imageSelect) { 
			document.images[imageX].src = eval('main'+imageX+'.src')
		//}
	}
}

function setMenu(imgName,imgObj) { 
	if (imgName != null) { 
		document.images[imgName].src = eval(imgObj+".src") 
	} 
}







//*********************************************************************
// The following functions are used to capture items such as img and 
// div tags into javascript objects (for javascript programming opps)
//*********************************************************************

// usage: getDiv("the name of the div tag") 
// Returns a javascript object representing the div tag
function getDiv(name) {

	if(is.ie)
		return eval('document.all.' + name);
	if(is.ns6) 
		return findDiv(name, document);
	return null;
}

// Helper function for getDiv
function findDiv(name, doc) {

  var i, layer, divColl;  
  divColl = document.getElementsByTagName("div"); 

  for (i = 0; i < divColl.length; i++) 
  {
    layer = doc.getElementById(divColl[i].id);
    if(layer.id == name) 
		return layer;
  }
  return null;
}



// usage: getImage("the name of the image id") 
// Returns a javascript object representing the div tag
function getImage(name) {

	if (is.ie)
		return eval('document.all.' + name);
	if (is.ns6) {
		return findImage(name, document);
	}

	return null;
}

// Helper function for getImage
function findImage(name, doc) {

	var i, img, imgColl;
	imgColl = document.getElementsByTagName("img"); 

	for (i = 0; i < imgColl.length; i++)
	{
		img = doc.getElementById(imgColl[i].id);
		if(img.id == name) 
			return img;
	}
	return null;
}