// Attach default onload functions
initOnload();

function initOnload(){	
    addEvent(window, 'load',initRollovers);
}

var browser = navigator.appName;
var versionInfo = navigator.appVersion;
var versionNum = parseFloat(versionInfo);
var vendor = navigator.vendor;
var IE = "Microsoft Internet Explorer";
var IE6 = "MSIE 6.0";
var IE7 = "MSIE 7.0";
var safari = "Apple Computer, Inc.";
var imagePath = "/img/";
var classAttribute = classAttr();   //Get the appropriate class attribute to set. IE and Firefox use different attributes for class in the DOM.

/***** Begin preload images *****/
var origImg = new Array();	//Array of images for rollovers
origImg[0] = '';

var overImg = new Array();	// Array of images to preload
overImg[0] = '';

var preloadFlag = false;
function preloadImages() {
	for (i=0; i<overImg.length; i++) {
		var images = new Array();
		images[i] = new Image();
		images[i].src = imagePath + overImg[i];
	}
	preloadFlag = true;
}
/***** End preload images *****/

/***** Begin image rollover funtion *****/
/* Function to initalize rollover */
function initRollovers(){	
	var rollovers = getElementsByClass('rollover',null,null);	//Get elements with a class of "rollover"
	
	if (rollovers.length > 0){		//If there is at least one element with a class "rollover"
		for(var i=0;i<rollovers.length;i++){	//Loop through all elements with class "rollover"
			var classValue = rollovers[i].getAttribute(classAttribute);
			
			if((versionInfo.match(IE6) != null) && (classValue.match('tpng') != null) ){ //If the browser is IE6 and a transparent png				
				addEvent(rollovers[i],'mouseover',rolloverPNG);	//Attach mouseover event
				addEvent(rollovers[i],'mouseout',rolloverPNG);	//Attach mouseout event				
			}
			else {
				addEvent(rollovers[i],'mouseover',rollover);	//Attach mouseover event
				addEvent(rollovers[i],'mouseout',rollover);	//Attach mouseout event
			}
		}		
	}
}

// This function grabs the src attribute and replaces "off" with "on" (for mouseover) or "on" with "off (for mouseout) in the attribute string. KM
function rollover(event) {
	var etype = event.type;
	var imgSrc = getObjectAttribute(this,"src");
	var newImgSrc;
	
	if (etype == 'mouseover'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		this.setAttribute('src',newImgSrc);
	}
	
	else if (etype == 'mouseout') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		this.setAttribute('src',newImgSrc);
	}
}

// IE 6 Transparent PNG rollover function. KM
function rolloverPNG(event) {
	var etype = event.type;
	var imgSrc = getObjectAttribute(this,"name");
	var newImgSrc;
	
	if (etype == 'mouseover'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		this.setAttribute('src',newImgSrc);
	}
	
	else if (etype == 'mouseout') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		this.setAttribute('src',newImgSrc);
	}
}
/***** End image rollover function *****/

/***** Begin pop up functions *****/
function popWindow(href,title,sb,width,height) {
	window.open(href,title,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+ sb +',resizable=0,width='+ width +',height='+ height +',top=150,left=150');
}
/***** End pop up functions *****/

/***** Begin search menu function *****/
function showSearch(mouseaction){
	var utilityMenuObj = $('utility-menu');
	var searchMenuObj = $('search-menu');
	var searchTab = getElementsByClass("last",utilityMenuObj,null)[0].getElementsByTagName('a')[0];
	
	if (mouseaction == 'over'){
		searchMenuObj.style.visibility = "visible";
		searchMenuObj.style.left = "-153px";
		searchTab.style.backgroundColor = "#f3f1c2";
		searchTab.style.color = "#0000ff";
	}
	else if (mouseaction == 'click'){
		searchMenuObj.style.visibility = "hidden";
		searchMenuObj.style.left = "-999px";
		searchTab.style.backgroundColor = "";
		searchTab.style.color = "";
	}
}
/***** End search menu function *****/

/***** Begin show/hide Flash navigation function *****/
function flashNavigation(state) {
	var fullFlashNav = $('flashNav');
	var htmlNav = $('html-nav');
	
	if (state == 'off'){
		fullFlashNav.style.height="25px";
	}	
	else if (state == 'on'){
		fullFlashNav.style.height="400px";
	}
	else if (state == "noflash"){
		fullFlashNav.style.overflow = "visible";
		htmlNav.style.visibility = "visible";
	}
	else {
	}
}

function fromFlash(page) {
	window.location=page;
}
/***** End show/hide Flash navigation function *****/

/***** Begin tab change functions *****/
function initTabbing(){	
	var tabs = getElementsByClass("tab",null,null);	//Get elements with a class of "tab"
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
	
	if (tabs.length > 0){		//If there is at least one element with a class "tab"
		for(var i=0;i<tabs.length;i++){	//Loop through all elements with class "tab"
			addEvent(tabs[i],"click",tabClick);	//Attach click event
		}		
	}
}

function tabClick(event){    
    var tabs = getElementsByClass("tab",null,null);	//Get tabs
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
    	
	for(var t=0;t<tabs.length;t++){ //Loop through all tabs
	    var tabObj = tabs[t];
	    var tabSectionObj = tabSections[t];
	    	    
	    if(tabObj == this){ //Change clicked tab on
            tabObj.setAttribute(classAttribute, "tab selected");
            tabSectionObj.style.display = "block";
	    }
	    else {	//Change other tabs off	        
            tabObj.setAttribute(classAttribute, "tab");
            tabSectionObj.style.display = "none";		    
	    }
	}
}

/***** End tab change functions *****/

/***** Begin clickable map functions *****/
function initMapClick(){
	var dots = getElementsByClass("map-dot",null,null);
	
	if (dots.length > 0){
		for(var i=0;i<dots.length;i++){
			addEvent(dots[i],"click",mapClick);
		}		
	}
}

function mapClick(event){
	var allLocationsObj = $('location-international');
	var locationID = this.id + "-info";
	var locations = getElementsByClass("location",allLocationsObj,null);
	
	if (locations.length > 0){
		for(var i=0;i<locations.length;i++){
			if(locations[i].id == locationID){
				locations[i].style.display = "block";
			}
			
			else {
				locations[i].style.display = "none";
			}
		}		
	}
}
/***** End clickable map functions *****/

/***** Begin expose element functions *****/
function initExposeElement(){	
	var qs = getElementsByClass("faq-question",null,null);
    var as = getElementsByClass("faq-answer",null,null);
	
	if (qs.length > 0){
		for(var i=0;i<qs.length;i++){
			addEvent(qs[i],"click",exposeElement);
		}		
	}
	
	if(as.length > 0){
		for(var i=0;i<as.length;i++){
			if(as[i].getAttribute(classAttribute).match('selected') != null){
				as[i].style.display = "block";
			}
			else {
				as[i].style.display = "none";		    
			}
		}
	}
}

function exposeElement(event){    
    var q = getElementsByClass("faq-question",null,null);	//Get tabs
    var a = getElementsByClass("faq-answer",null,null);   //Get tab body sections
    	
	for(var i=0;i<q.length;i++){ //Loop through all tabs
	    var qObj = q[i];
	    var aObj = a[i];
	    	    
	    if(qObj == this){
			if(aObj.style.display == "none"){
				qObj.setAttribute(classAttribute, "faq-question selected");
				aObj.style.display = "block";
			}
			else {	        
				qObj.setAttribute(classAttribute, "faq-question");
				aObj.style.display = "none";		    
			}
		}
		/* Remove comments to enable clicking one question to close any open questions. KM
		else {	        
			qObj.setAttribute(classAttribute, "faq-question");
			aObj.style.display = "none";		    
		}*/
	}
}
/***** End expose element functions *****/

/***** Begin inline popup functions *****/
function inlinePopUp(popID){
	var popObj = $(popID);
	
	if(popObj.style.visibility == "visible"){
		popObj.style.visibility = "hidden";
	}
	else {
		popObj.style.visibility = "visible";
	}	
}
/***** End inline popup functions *****/


