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 = "images/";
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);
	}
}

// When function needs to be added inline (e.g. dynamically added content) KM
function rolloverInline(imgId,type) {
	var imgObj = _gel(imgId);
	var imgSrc = getObjectAttribute(imgObj,'src');
	var newImgSrc;	

	if (type == 'over'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		imgObj.setAttribute('src',newImgSrc);
	}

	

	else if (type == 'out') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		imgObj.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 *****/

/*** drop down menu ***/
//Drop-down menu script
mhover = function() {
	var navUL = _gel('primary-menu');
	var sfEls = navUL.getElementsByTagName("li");
	if((versionInfo.match(IE6) != null)){
						  
	for (var i=0; i<sfEls.length; i++) {
		
	    if(sfEls[i].getAttribute('className').match("first")) {
		    sfEls[i].onmouseover=function() {
			    this.className+=" mhover-first";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" mhover-first\\b"), "");
		    }
		 }
	    else if(sfEls[i].getAttribute('className').match("last")) {
		    sfEls[i].onmouseover=function() {
			    this.className+=" mhover-last";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" mhover-last\\b"), "");
		    }
		 }
		 else {
		    sfEls[i].onmouseover=function() {
			    this.className+=" mhover";
		    }
		    sfEls[i].onmouseout=function() {
			    this.className=this.className.replace(new RegExp(" mhover\\b"), "");
		    }
		 }
	}
	}
}

if (window.attachEvent) window.attachEvent("onload", mhover);