/* GENERAL FUNCTIONS
-----------------------------------------------------*/

function classRows() {
	var myTABLES = $$('table');	//Only cycle through rows in the table body
	for (var x=0;x<myTABLES.length;x++) {
	   var myTR = myTABLES[x].getElementsByTagName('tr');
	   for (var i=0;i<myTR.length;i++) {
		   if (myTR[i].className == '') {		//Only add a class if there isn't already a class
			   if (i%2) {
				   myTR[i].className = 'even';	//Add even class to even rows
			   } else {
				   myTR[i].className = 'odd';	//Add odd class to odd rows
			   }
		   }
	   }
	}
}


function classAnchors() {
	var externalFiles = new Array('doc', 'pdf', 'jpg');
	var myANCHORS = document.getElementsByTagName('a');
	var baseHREF = document.getElementsByTagName('base')[0].href;
	
	for (var i=0;i<myANCHORS.length;i++) {
	   if (myANCHORS[i].className == '') {		//Only add a class if there isn't already a class
		   if (myANCHORS[i].getAttribute('href') == location.pathname || ('/'+myANCHORS[i].getAttribute('href')) == location.pathname || myANCHORS[i].getAttribute('href') == location.href) {
			   myANCHORS[i].className = 'current';	//Add selected class to anchors going to the current page
		   }
			var k=0;
			while (externalFiles[k]) {
				if (myANCHORS[i].getAttribute('href').slice(-3) == externalFiles[k] || (myANCHORS[i].getAttribute('href').substr(0,4) == 'http' && myANCHORS[i].getAttribute('href').substr(0,baseHREF.length) != baseHREF)) {	
					myANCHORS[i].target = '_blank';
				}
				k++;
			}
	   }
	}
}


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

window.onload=function(){
	classRows();
	classAnchors();
	/* This will set the matches to the largest height. */
	var h = new Array;
	var i = 0;
	var tops = 0;
	var list = $$('#content .match');
	if (list.length>1) {
		list.each(function(element) {
			if (tops < element.offsetHeight) tops = element.offsetHeight;
			h[i] = element.offsetHeight;
			i++;	   
		});
		var list = $$('#content .match');
		list.each(function(element) {
			element.setStyle('min-height', tops-20+'px');
			if (this.ie6) element.setStyle('height', tops-20+'px');
		});
	}
}
