// roll_test_V1 - W3C rollovers 
// roll_test_V2 - IE rollovers 
// roll_test_V3 - consolidate functions into obj lit.

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}

window.onload=init;

function init() {
	stripeTable.getTheTables();
	}
var stripeTable={
	//methods to set up the table when the page loads
	getTheTables:function () {
    // this browser is too old to stripe the table so exit
		if (!document.getElementsByTagName) {return false;} 
		var theTables=document.getElementsByTagName("table");
		for (var i=0; i < theTables.length; i++) { // loop through them
      // if this table has the required class
			if (theTables[i].className == "stripe_table") {
        // call the striping method on it 
				stripeTable.addStripes(theTables[i]); 
			}
		}
	},
  // adds stripes (the "odd" class) to alternate table rows
	addStripes:function (theTable) { 
    // get the table body 
		var theTableBody = theTable.getElementsByTagName("tbody"); 
    //add events to the tbody tag  
    // add the mouse event listeners to the table body
		addEvent(theTableBody[0],'mouseover', stripeTable.checkEventSource); 
    // note: don't use mouseleave - it doesn't work : )
		addEvent(theTableBody[0],'mouseout', stripeTable.checkEventSource);
		//stripe the table rows
    // get the table body's rows
		var theTableRows = theTableBody[0].getElementsByTagName("tr");
    // set rowCount to the number of rows 
		var rowCount=theTableRows.length
    // add rollover event handlers and 'odd' classs for stripes 
		for (var i=0; i < rowCount; i++) { 
      // add the odd class to every other row 
			theTableRows[i].className = "odd"; 
			i++; // incrementing counter here skips a row
		}  
	},
  // called when the user mouses over the table rows
	checkEventSource:function(e) {
    // set up cross-browser event obj names
		var evt = e || window.event; 
		var evtTarget = evt.target || evt.srcElement;
//document.getElementById("display").innerHTML = evtTarget.nodeName;

    // if the event didn't happen to the tr
		while (evtTarget.nodeName.toLowerCase() !== "tr") {
      // move up from any child element to the tr 
			evtTarget=evtTarget.parentNode;  
		}
    // then respond the the event type
		switch (evt.type) { 
			case'mouseover':
				stripeTable.oldClass = evtTarget.className 
        // store the current class - either 'odd' or undefined
        // change it to the hilite class - table row hilites
				evtTarget.className="row_hilite";   
				break;
			case'mouseout':
        // restore the orginal class - table row returns to original appearance
				evtTarget.className=stripeTable.oldClass; 
				break;
		}
	}
} // end stripe_table object
