// JavaScript Document

var ns4, op5, op6, agt, mac, ie, mac_ie;


function secondaryNavHighlight(){
	
	if(document.getElementById('siteSecondaryNav')){
		theSecondaryNav = document.getElementById('siteSecondaryNav');
		theLinks = theSecondaryNav.getElementsByTagName('a');
		
		matchFound = false;
		
		//Detect browser
		sniffBrowsers();
		
		currentUrl = document.location.href;
		
		for(i=0;i<theLinks.length;i++){
			//alert(cleanUrl(theLinks[i].href) + " : " +cleanUrl(currentUrl));
			cleanNavLink = cleanUrl(theLinks[i].href);
			cleanCurrentUrl = cleanUrl(currentUrl);
			
			if(cleanNavLink==cleanCurrentUrl || cleanCurrentUrl.indexOf(cleanNavLink)>-1){
				activeLink = theLinks[i];
				
				matchFound=true;
				
			}
		}
		
		//activeLink = theLinks[1];
		
		//IF MATCHING NAV LINK IS FOUND
		if(matchFound){
			activeLink.className = "active";				
			
		}
		
		//POSITION THE SECONADRY NAV DEPENDING ON HEIGHT
		if(theSecondaryNav.getElementsByTagName('ul').length>0){
			theList = theSecondaryNav.getElementsByTagName('ul')[0];
			theHeight = findHeight(theList);
			if(theHeight<30){
				theList.style.position="relative";
				theList.style.top="21px";
			}
			if(theHeight>50){
				//theList.style.fontSize="8px";	
				theSecondaryNav.style.height=(theHeight+10)+"px";
			}
		}
	}
}




function navHighlight(){

	theNav = document.getElementById('siteNav');
	theLinks = theNav.getElementsByTagName('a');
	
	matchFound = false;
	
	//Detect browser
	sniffBrowsers();
	
	currentUrl = document.location.href;
	
	for(i=0;i<theLinks.length;i++){
		//alert(cleanUrl(theLinks[i].href) + " : " +cleanUrl(currentUrl));
		cleanNavLink = cleanUrl(theLinks[i].href);
		cleanCurrentUrl = cleanUrl(currentUrl);
		
		if(cleanNavLink==cleanCurrentUrl || cleanCurrentUrl.indexOf(cleanNavLink)>-1){
			activeLink = theLinks[i];
			
			matchFound=true;
			
		}
	}
	
	//activeLink = theLinks[1];
	
	//IF MATCHING NAV LINK IS FOUND
	if(matchFound){
		activeLink.className = "active";		
		
		activeNavImage = activeLink.childNodes[0];
		
		if(activeNavImage.src.lastIndexOf('-over.gif')<=0){
			activeNavImage.src = activeNavImage.src.substr(0,activeNavImage.src.lastIndexOf('.gif'))+"-over.gif";
			
		}
			activeNavImage.onmouseover=function(){};
			activeNavImage.onmouseout=function(){};
		
	}
	//alert(findPos(theLinks[0]));
}

//cleans a url for better comparison
function cleanUrl(theLink){
	if(theLink.indexOf('http:')>-1){
		theLink	= theLink.substr(theLink.indexOf('http:')+5, theLink.length);
	}
	if(theLink.indexOf('index.html')>-1){
		theLink	= theLink.substr(0,theLink.indexOf('index.html'));
	}
	if(theLink[theLink.length-1]=='/'){
		theLink = theLink.substr(0, theLink.length-1);	
	}
	
	return theLink;
}




function inputStyles(){
	pageInputs = document.getElementsByTagName('input');
	
	
	//style buttons
	for(pi=0;pi<pageInputs.length;pi++){
		if(pageInputs[pi].type=='submit' || pageInputs[pi].type=='reset' || pageInputs[pi].type=='button'){
			pageInputs[pi].className="input-button";
		}else if(pageInputs[pi].type=="checkbox" || pageInputs[pi].type=="radio"){
			pageInputs[pi].className="input-checkbox";	
		}
	}
	
}




function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function findHeight(obj) {
		
		if (op5) {
			yPos = obj.style.pixelHeight;
		} else {
			yPos = obj.offsetHeight;
		}
		return yPos;
	
}



function findWidth(obj) {
		
		if (op5) {
			xPos = obj.style.pixelWidth;
		} else {
			xPos = obj.offsetWidth;
		}
		return xPos;
	
}


function sniffBrowsers() {
	ns4 = document.layers;
	op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
		||(navigator.userAgent.indexOf("Opera/5")!=-1);
	op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
		||(navigator.userAgent.indexOf("Opera/6")!=-1);
	agt=navigator.userAgent.toLowerCase();
	mac = (agt.indexOf("mac")!=-1);
	ie = (agt.indexOf("msie") != -1); 
	mac_ie = mac && ie;
	
}