/*
 * Image Rollovers using event listeners
 *
 * This function will loop through all the images in a page
 * and add rollovers by adding onmouseover and onmouseout events.
 * 
 *
 * Usage:
 * Add an "rollover" class to the image tag.
 * The rollover image must be in the same directory as the default
 * image and suffixed with "_over".
 */
function initRollovers() {
	if (!document.getElementById) return
	
	var aPreLoad = new Array();
	var sTempSrc;
	var aImages = document.getElementsByTagName('img');

	for (var i = 0; i < aImages.length; i++) {		
		if (aImages[i].className.split(' ').has("rollover")) {
			var src = aImages[i].getAttribute('src');
			var ftype = src.substring(src.lastIndexOf('.'), src.length);
			var hsrc = src.replace(ftype, '_over'+ftype);
		
			//Preload the rollover
			aImages[i].setAttribute('hsrc', hsrc);
			aPreLoad[i] = new Image();
			aPreLoad[i].src = hsrc;
			
			//Attach the rollover event
			aImages[i].onmouseover = function() {
				sTempSrc = this.getAttribute('src');
				this.setAttribute('src', this.getAttribute('hsrc'));
			}	
			
			//Attach the rolloff event
			aImages[i].onmouseout = function() {
				if (!sTempSrc) sTempSrc = this.getAttribute('src').replace('_over'+ftype, ftype);
				this.setAttribute('src', sTempSrc);
			}
		}
	}
}

/*
 * Add Link Titles
 *
 * This function will loop through all the elements in a page and add
 * a title attribute to all anchor tags.  For anchor tags with a className
 * of "external" the title will be "New Window:" followed by the link text.
 * For all anchor tags just the link text will be used for the title.  
 *
 * To override this functionality, just specify a title in the anchor tag.  
 * Anchors with defined titles will be ignored.
 * 
 */
addTitles = function(sContextPath) {
	var allLinks = document.getElementsByTagName("a");
	for (i=0; i<allLinks.length; i++) {
		var linkClass=allLinks.item(i).className		
		if (allLinks.item(i).title.length == 0) { 
			var innerHTML = allLinks.item(i).innerHTML;
			innerHTML = innerHTML.replace('&amp;','&');			
			if(linkClass.split(' ').has("external"))
			{allLinks.item(i).title = "New Window: " + innerHTML}			
			else if(linkClass.split(' ').has("pdf"))
			{allLinks.item(i).title = "New Window: " + innerHTML}		
			else{allLinks.item(i).title = innerHTML}					
		}
	}
}
/*
 * Style Odd/Even Table Rows
 *
 * This function will build an array of all HTML tables on a page with a
 * classname of "stripe". It will then set the classname to "even" for 
 * even rows in the table.  Styles for the odd rows should be done using
 * the default values for the td.
 * 
 */
	var stripe = function() {
		var tables = document.getElementsByTagName("table");	

		for(var x=0;x!=tables.length;x++){
			var table = tables[x];
			if (! table) { return; }
			
			var tableClass=tables[x].className
			var tbodies = table.getElementsByTagName("tbody");
			
			if(tables[x].className.split(' ').has("stripe")){
				for (var h = 0; h < tbodies.length; h++) {
					var even = true;
					var trs = tbodies[h].getElementsByTagName("tr");
					
					for (var i = 0; i < trs.length; i++) {

						if(even)
							trs[i].className += " even";
						
						even = !even;
					}
				}
			}
		}
	}