/*
 *	Wicketeer DataView, version 1.0
 *  (c) 2007 Tauren Mills
 *	
 */

// Create the package namespace com.wicketeer.components
if (!com) {
	var com = {};
}
if (!com.wicketeer) {	
	com.wicketeer = {};
}
if (!com.wicketeer.components) {
	com.wicketeer.components = {};
}

// Create DataView
com.wicketeer.components.DataView = function() {

	// private properties and functions

	// public properties and functions
	var _public = {

		// adds rollover events to all table rows that have a class of "odd" or "even"
		// adds rollover events to all table headers that have a wicket sort ordering class
		initialize: function() {
			var tr = document.getElementsByTagName("tr");
			for(var i=0;i<tr.length;i++) {
				var ocn = tr[i].className;
				if (ocn == "odd") {
					tr[i].onmouseover = function() { this.className = "selected" };
					tr[i].onmouseout = function() { this.className = "odd" };
				}
				else if ( ocn == "even") {
					tr[i].onmouseover = function() { this.className = "selected" };
					tr[i].onmouseout = function() { this.className = "even" };
				} 
				else {
				}
			}	
			var th = document.getElementsByTagName("th");
			for(var i=0;i<th.length;i++) {
				var ocn = th[i].className;
				if (ocn == "wicket_orderNone") {
					th[i].onmouseover = function() { this.className = "wicket_orderNoneSelected" };
					th[i].onmouseout = function() { this.className = "wicket_orderNone" };
				}
				else if ( ocn == "wicket_orderDown") {
					th[i].onmouseover = function() { this.className = "wicket_orderDownSelected" };
					th[i].onmouseout = function() { this.className = "wicket_orderDown" };
				} 
				else if ( ocn == "wicket_orderUp") {
					th[i].onmouseover = function() { this.className = "wicket_orderUpSelected" };
					th[i].onmouseout = function() { this.className = "wicket_orderUp" };
				} 
				else {
				}
			}	
		},
		
		// add an event to window.onload without overriding other events already set
		addLoadEvent: function(func) {
			var oldonload = window.onload;
			if (typeof window.onload != 'function') {
				window.onload = func;
			} else {
				window.onload = function() {
					if (oldonload) {
						oldonload();
					}
					func();
				};
			}
		}

	};

	return _public;

}();

// Add initialize event to window.load
com.wicketeer.components.DataView.addLoadEvent(function() {
	com.wicketeer.components.DataView.initialize();
});		

