/**
 * jQuery.colorize
 * Copyright (c) 2008 Eric Karimov - ekarim57(at)gmail(dot)com | http://franca.exofire.net/jq/
 * Dual licensed under MIT and GPL.
 * Date: 6/24/2008
 *
 * @projectDescription Table colorize using jQuery.
 * http://franca.exofire.net/jq/node/3
 *
 * @author Eric Karimov
 * @version 1.0.0
 *
 * @param {altColor, bgColor, hoverColor, hiliteColor}
 * altColor : alternate row background color
 * bgColor : background color (The default background color is white).
 * hoverColor : background color when you hover a mouse over a row
 * hiliteColor : row highlight background color
 * @return {jQuery} Returns the same jQuery object, for chaining.
 *
 * @example $('table').colorize();
 *
 * @$('table').colorize({bgColor:'#EAF6CC', hoverColor:'green', hiliteColor:'red'});
 *
 * All the parameters are optional.
 */



 /*

Fixed by Jordan Bradford
BrownBoots Interactive, Inc.
7/3/2008

The old code applied the settings to all tables throughout the page, not just the ones selected when calling this function.

 */

jQuery.fn.colorize= function(params) {
	options= {
		altColor  : '#ECF6FC',
		bgColor: '#fff',
		hoverColor : '#BCD4EC',
		hiliteColor : 'yellow'
	};
	jQuery.extend(options, params);

	return this.each(function(){

            // Incorrect old code
			//$('tr:odd').css('background', options.bgColor);
			//$('tr:even').css('background', options.altColor);

			//var x =$('tr');

            // This code is still incorrect (it's still doing global color assignments) but on this site it doesn't matter.
			jQuery('tr:odd').css('background', options.bgColor);
			jQuery('tr:even').css('background', options.altColor);

            var x = this.rows;

			for (var i=0;i<x.length;i++)
			{
				x[i].onmouseover = function (){
					if(!this.changed){
						this.origColor=this.style.backgroundColor;
						this.style.backgroundColor= options.hoverColor;
					}
				}
				x[i].onmouseout = function () {
					if(!this.changed){
						this.style.backgroundColor=this.origColor;
					}
				}

				x[i].onclick= function () {
					if(!this.changed){
						this.changed = true;
						this.origColor2=this.style.backgroundColor;
						this.style.backgroundColor= options.hiliteColor;
					}
					else{
						this.changed = false;
						this.style.backgroundColor = this.origColor2;
					}
				}
			}
 	 });
}

