// Javascript to style odd/even table rows
// Derived from 'Zebra Tables' by David F. Miller (http://www.alistapart.com/articles/zebratables/)
// Modified by Jop de Klein


// this function is needed to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
 var result = false;
 if (obj.getAttributeNode("class") != null) {
	 result = obj.getAttributeNode("class").value;
 }
 return result;
}

function stripe() {
	var even = true;
	var tables = document.getElementsByTagName("table");	
	
	for(x=0;x!=tables.length;x++){
		table = tables[x];
		if (! table) { return; }
		
		var tbodies = table.getElementsByTagName("tbody");
		
		for (var h = 0; h < tbodies.length; h++) {
			var trs = tbodies[h].getElementsByTagName("tr");
			
			for (var i = 0; i < trs.length; i++) {
				
				if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
					trs[i].className = even ? "even" : "odd";
				}
				// flip from odd to even, or vice-versa
				even =  ! even;
			}
		}
	}
}

// addEvent cross-browser event handling for IE5+, NS6 and Mozilla
// By Scott Andrew
addEvent = function(elm, evType, fn, useCapture) {	
	if (elm.addEventListener) {
	  elm.addEventListener(evType, fn, useCapture); 
	  return true;
	} else if (elm.attachEvent) {
	  var r = elm.attachEvent('on' + evType, fn);
	  return r;
	} else {
	  elm['on' + evType] = fn;
	}
};

function startList() {
	if (document.all&&document.getElementById) {
		setupList(document.getElementById('nav'));
		
		//For admin section
		if(document.getElementById('nav2')) {
			setupList(document.getElementById('nav2'));
		}
	}
}

function setupList(navRoot) { 
	for (var i=0; i<navRoot.childNodes.length; i++) {
		var node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
			node.onmouseover=function() {
				this.className += " over";
			}
			node.onmouseout=function() {
				this.className=this.className.replace(/\bover\b/, '');
			}
		} 
	}
	// now go through again and set the style for the last nav item so it doesn't spill right
	var i = navRoot.childNodes.length - 1;
	var set = false;
	while(i >= 0 && set == false) {
	
		var node = navRoot.childNodes[i];
	
		if (node.nodeName=="LI") {
			var ul = node.getElementsByTagName('ul');
			if (ul.length) {
				ul[0].style.right = '0';
				set = true;
			}
		} 
	
		i--;
	}
}

addEvent(window, "load", startList, false);