// Title: tigra tables
// URL: http://www.softcomplex.com/products/tigra_tables/
// Version: 1.1
// Date: 08/15/2005
// Notes: Permission given to use this script in any kind of applications if
//    header lines are left unchanged.


function tigra_tables (str_tableid) {

	str_tableid		= "product";
	num_header_offset 	= 1;
	num_footer_offset 	= 0;
	str_odd_color 		= "#FFFFFF";
	str_even_color 		= "#DFF0F1";
	str_mover_color 	= "#7FD0D8";
	str_onclick_color 	= "#26AFBD";
	str_onlick_text_color	= "#B5530D";

	// validate required parameters
	if (!str_tableid) return alert ("No table(s) ID specified in parameters");
	var obj_tables = (document.all ? document.all(str_tableid) : document.getElementById(str_tableid));
	if (!obj_tables) return alert ("Can't find table(s) with specified ID (" + str_tableid + ")");

	// set defaults for optional parameters
	var col_config = [];
	col_config.header_offset = (num_header_offset ? num_header_offset : 1);
	col_config.footer_offset = (num_footer_offset ? num_footer_offset : 0);
	col_config.odd_color = (str_odd_color ? str_odd_color : '#ffffff');
	col_config.even_color = (str_even_color ? str_even_color : '#ccccff');
	col_config.mover_color = (str_mover_color ? str_mover_color : '#ffccff');
	col_config.onclick_color = (str_onclick_color ? str_onclick_color : '#cc99ff');

	// init multiple tables with same ID
	if (obj_tables.length)
		for (var i = 0; i < obj_tables.length; i++)
			tt_init_table(obj_tables[i], col_config);
	// init single table
	else
		tt_init_table(obj_tables, col_config);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Lines Added BY Jorel This Works Mainly in Non-IE Browsers                                                    //
// This makes the div containing the table the same width as the table                                          //
// For rounded corners to work                                                                                  //
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (count==0)  // IE - This is first table, cant use array because only one exists.
{
	document.all.prodtables.style.width = document.all.product.width;
	count = count + 1;
}
else 	if (document.all.prodtables[count]) // IE - These are more tables, use array because more than one exists.
	{ 
		document.all.prodtables[count].style.width = document.all.product[count].width;
		count = count + 1;
	}
	else  // Mozilla
		document.getElementById('prodtables').style.width = document.getElementById('product').width;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

}


function tt_init_table (obj_table, col_config) {
	var col_lconfig = [],
		col_trs = obj_table.rows;
	if (!col_trs) return;
	for (var i = col_config.header_offset; i < col_trs.length - col_config.footer_offset; i++) {
		col_trs[i].config = col_config;
		col_trs[i].lconfig = col_lconfig;
		col_trs[i].set_color = tt_set_color;
		col_trs[i].onmouseover = tt_mover; 
		col_trs[i].onmouseout = tt_mout;
		col_trs[i].onmousedown = tt_onclick;
		col_trs[i].order = (i - col_config.header_offset) % 2;
		col_trs[i].onmouseout();
	}
}
function tt_set_color(str_color) {
	this.style.backgroundColor = str_color;
}

// event handlers
function tt_mover () {
	if (this.lconfig.clicked != this)
		this.set_color(this.config.mover_color);
}
function tt_mout () {
	if (this.lconfig.clicked != this)
		this.set_color(this.order ? this.config.odd_color : this.config.even_color);
}
function tt_onclick () {
	if (this.lconfig.clicked == this) {
		this.lconfig.clicked = null;
		this.onmouseover();
	}
	else {
		var last_clicked = this.lconfig.clicked;
		this.lconfig.clicked = this;
		if (last_clicked) last_clicked.onmouseout();
		this.set_color(this.config.onclick_color);
////////////////////////////////////////////////////////////////////
		//this.style.color=str_onlick_text_color;
		//this.style.fontStyle="italic";
		//this.style.fontVariant="small-caps";
////////////////////////////////////////////////////////////////////
	}
}
