/**
 * 
 * jQuery Basic Table Hover Plugin
 * Copyright(c) 2008, VSA Partners, Inc.
 * http://www.vsapartners.com 
 * 
 * @author Ry Racherbaumer (rracherbaumer@vsapartners.com)
 * @version 0.1
 * 
 */

//
// create closure
//
(function($) {
	//
	// plugin definition
	//
 	$.fn.thover = function(options) {
		// build main options before element iteration
		var opts = $.extend({}, $.fn.thover.defaults, options);
		// iterate and reformat each matched element
		return this.each(function() {
			// get the table element
			var $table = $(this);
			// get the cells to attach hover to
			var cells = $('tbody tr td', $table);
			// get cols
			var cols = $('col', $table);
			var rows = $('tr', $table);
			cells.hover(
				function(){
					var cellIndex = this.cellIndex;
					var row = this.parentNode;
					var rowIndex = row.rowIndex;
					var table = row.parentNode.parentNode;
					for (i = 0; i < table.rows.length; i++) {
						if (table.rows[i].cells.length > 1) {
							if (!$(rows.get(i)).hasClass('tophead'))
								table.rows[i].cells[cellIndex].style.backgroundColor = '#ccebff';
						}
						if (rowIndex == i) {
							for (j = 0; j < table.rows[i].cells.length; j++) {
								if (j == cellIndex) {
									table.rows[i].cells[j].style.backgroundColor = '#82ceff';
								} else {
									table.rows[i].cells[j].style.backgroundColor = '#ccebff';
								}
							}
						}
					}				
				},
				function(){
					var cellIndex = this.cellIndex;
					var row = this.parentNode;
					var rowIndex = row.rowIndex;
					var table = row.parentNode.parentNode;
					for (i = 0; i < table.rows.length; i++) {
						if (table.rows[i].cells.length > 1) {
							if (!$(rows.get(i)).hasClass('tophead')) 
								table.rows[i].cells[cellIndex].style.backgroundColor = '#fff';
						}
						if (rowIndex == i) {
							for (j = 0; j < table.rows[i].cells.length; j++) {
								table.rows[i].cells[j].style.backgroundColor = '#fff';
							}
						}
					}
				}
			);
		});
	};
	//
	// plugin defaults
	//
	$.fn.thover.defaults = {
		rowHoverClass: 'rowHover',
		colHoverClass: 'colHover',
		cellHoverClass: 'cellHover'		
	};
//
// end of closure
//
})(jQuery);