//Dreamweaver Behaviors
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// function called by pageLocator when a link on the page matches the document URL
function styleCurPage (curPageLinkIndex) {
var numFooterLinks = 1;
var listArray=document.getElementsByTagName("li");
	//alert("begin styling");
	// get the corresponding list item position from the end the listArray
	//alert("curPageLinkIndex: "+curPageLinkIndex);
	//alert("document.links.length: "+document.links.length);
	var posFromEnd = document.links.length - curPageLinkIndex - numFooterLinks;
	//alert("posFromEnd: "+posFromEnd);
	//alert("listArray.length: "+listArray.length);
	var curPageListIndex = listArray.length - posFromEnd;
	//alert("curPageListIndex: "+curPageListIndex);
	if (curPageListIndex>=0) {
		var targetList = listArray[curPageListIndex];
		// set the class attribute of the current page's list item to selected to style in CSS
		targetList.setAttribute("class", "selected");
	}
			
	// for IE and other browsers that can't set the class and respond to the style, just set the link's background color
		document.links[curPageLinkIndex].style.backgroundColor="#DEDEDE";
}

// Current Page Locator
function pageLocator() {
// Mark subnavigation
var endIndex;
var currentURL;
var submenuArray;
var curPageLinkIndex = -1;
var posFromEnd;
var docURL = document.URL;
//var docURL = "http://www.crosscomm.net/plantpath/extension/commodities/hay.htm#1";

// URLs to directories and default pages will be stripped down before comparison with links
// if the URL is a directory
if (docURL.lastIndexOf(".htm")<0) { 
	//alert(docURL.lastIndexOf("index.htm"));
	//alert("Directory URL becomes " + docURL.substr(0, docURL.lastIndexOf("/")));
	currentURL=docURL.substr(0,docURL.lastIndexOf("/"));
// if the URL is a default page (index.htm or index.html)
} else if (docURL.lastIndexOf("index.htm")>0) {
	//alert("Default Page URL becomes " + docURL.substr(0, docURL.lastIndexOf("/index.htm")));
	currentURL=docURL.substr(0,docURL.lastIndexOf("/index.htm"));

// other page URLs must be stripped of page anchors (#) and queries (?)
// if the URL is any other .html page
} else if (docURL.lastIndexOf(".html")>0) {
	//alert("Other HTML URL is " + docURL.substr(0,docURL.lastIndexOf(".htm")+5));
	currentURL=docURL.substr(0,docURL.lastIndexOf(".htm")+5);
// if the URL is any other .htm page
} else {
	//alert("Other HTM URL is " + docURL.substr(0,docURL.lastIndexOf(".htm")+4));
	currentURL=docURL.substr(0,docURL.lastIndexOf(".htm")+4);
}

// loop through all the links and compare URLs
for (i=document.links.length-1; i>=0; i--) {
	//alert("link"+i);
	var myLink = document.links[i].href;
	// if the link is to a directory
	if (myLink.lastIndexOf(".htm")<0) {
		// if the link ends in /, strip it of the / before comparing URLs
		if (myLink.lastIndexOf("/")==myLink.length) {
			var strippedLink=myLink.substr(0,myLink.lastIndexOf("/"));
			//alert("strippedLink: "+strippedLink);
			// if the URLs match, record the index number of the link array
			if (currentURL.lastIndexOf(strippedLink)>=0) { 
				curPageLinkIndex=i; 
				//alert("I found a match at link #"+i);
				styleCurPage(curPageLinkIndex);
				break;
			}
		// if the link does not end in /, just compare URLs
		} else {
			// if the URLs match, record the index number of the link array
			if (currentURL.lastIndexOf(myLink)>=0) { 
				curPageLinkIndex=i; 
				//alert("I found a match at link #"+i);
				styleCurPage(curPageLinkIndex);
				break;
			}
		}
	// if the link is to a default page (index.htm or index.html)
	} else if (myLink.lastIndexOf("index.htm")>0) {
		// strip it of the last / and default page name
		var strippedLink=myLink.substr(0,myLink.lastIndexOf("/index.htm"));
		if (currentURL.lastIndexOf(strippedLink)>=0) { 
			curPageLinkIndex=i; 
			//alert("I found a match at link #"+i);
			styleCurPage(curPageLinkIndex);
			break;
		}
	// if the link is to any other .htm or .html page
	} else {
		if (currentURL.lastIndexOf(myLink)>=0) { 
			curPageLinkIndex=i; 
			//alert("I found a match at link #"+i);
			styleCurPage(curPageLinkIndex);
			break;
		}
	}
	
// end for loop
}
// end function
}

//Preload main menu buttons
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function preloadMenu() {
	if (document.images) {
		menu_home2 = newImage("/images/menu-home2.gif");
		menu_academics2 = newImage("/images/menu-academics2.gif");
		menu_extension2 = newImage("/images/menu-extension2.gif");
		menu_research2 = newImage("/images/menu-research2.gif");
		menu_people2 = newImage("/images/menu-people2.gif");
		menu_seminars2 = newImage("/images/menu-seminars2.gif");
		menu_activities2 = newImage("/images/menu-activities2.gif");
		menu_calendar2 = newImage("/images/menu-calendar2.gif");
	}
}