/*

	Tablecloth
	written by Alen Grakalic, provided by Css Globe (cssglobe.com)
	please visit http://cssglobe.com/lab/tablecloth/

*/

document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
};

this.tablecloth = function(){

	// CONFIG

	// if set to true then mouseover a table cell will highlight entire column (except sibling headings)
	var highlightCols = false;

	// if set to true then mouseover a table cell will highlight entire row	(except sibling headings)
	var highlightRows = false;

	// if set to true then click on a table sell will select row or column based on config
	var selectable = false;

	// this function is called when
	// add your own code if you want to add action
	// function receives object that has been clicked
	this.clickAction = function(obj){
		//alert(obj.innerHTML);

	};



	// END CONFIG (do not edit below this line)


	var tableover = false;
	this.start = function(){
		var tables = document.getElementsByClassName("cool");
		for (var i=0;i<tables.length;i++){
			tables[i].onmouseover = function(){tableover = true};
			tables[i].onmouseout = function(){tableover = false};
			rows(tables[i]);
		};
	};

	this.rows = function(table){
		var css = "";
		var tr = table.getElementsByTagName("tr");
		for (var i=0;i<tr.length;i++){
			css = (css == "odd") ? "even" : "odd";
			tr[i].className = css;
			var arr = new Array();
			for(var j=0;j<tr[i].childNodes.length;j++){
				if(tr[i].childNodes[j].nodeType == 1) arr.push(tr[i].childNodes[j]);
			};
			for (var j=0;j<arr.length;j++){
				arr[j].row = i;
				arr[j].col = j;
				if(arr[j].innerHTML == "&nbsp;" || arr[j].innerHTML == "") arr[j].className += " empty";
				arr[j].css = arr[j].className;
				arr[j].onmouseover = function(){
					over(table,this,this.row,this.col);
				};
				arr[j].onmouseout = function(){
					out(table,this,this.row,this.col);
				};
				arr[j].onmousedown = function(){
					down(table,this,this.row,this.col);
				};
				arr[j].onmouseup = function(){
					up(table,this,this.row,this.col);
				};
				arr[j].onclick = function(){
					click(table,this,this.row,this.col);
				};
			};
		};
	};

	this.check1 = function(obj,col){
		return (!(col == 0 && obj.className.indexOf("empty") != -1));
	}
	this.check2 = function(active,obj){
		return (!(active.tagName == "TH" && obj.tagName == "TH"));
	};
	this.check3 = function(obj){
		return (obj.className) ? (obj.className.indexOf("selected") == -1) : true;
	};

	start();

};

/* script initiates on page load. */
window.onload = tablecloth;

