/**
 * @author chasevida
 */

var divElement;
var divElementNotch;
var previousBackgroundColor;

var hoverColor = "#FFCC00";

function divTableClick(event) {
	
	var divId = this.getAttribute("id");
	alert("Sort Table By: " + divId);
}

function sortTable(whichTable, whichColumn, whichDirection) {
	
}


function divTableOver(event) {
	var divId = this.getAttribute("id");
	divElement = document.getElementById(divId);
	
	previousBackgroundColor = divElement.style.backgroundColor;
	divElement.style.backgroundColor = hoverColor;
	divElement.style.cursor = "pointer";
	divElement.style.cursor = "hand";
	
	var children = document.getElementById(divId).childNodes;
	
	for (i = 0; i < children.length; i ++) {
		
		if (children[i].className == "notch") {
			divElementNotch = children[i];
			divElementNotch.style.borderLeftColor = hoverColor;
			divElementNotch.style.cursor = "pointer";
			divElementNotch.style.cursor = "hand";
		}
	}
}

function divTableOut(event) {
	
	divElement.style.backgroundColor = previousBackgroundColor;
	divElementNotch.style.borderLeftColor = previousBackgroundColor;
}

function disableTableLinksByElement(el) {
	
	if (document.getElementById && document.getElementsByTagName) {
		
		if (typeof(el) == 'string') {
			el = document.getElementById(el);
		}
		var anchors = el.getElementsByTagName('a');
		
		for (var i = 0, end = anchors.length; i < end; i ++) {
			
			//anchors[i].removeAttribute("href");
			anchors[i].onclick = function() {
		        return false;
		    }
		}
	}
}


function addTableButtonHoverListeners() {
	
	var buttonArray = new Array("tableLatest","tablePrice","tableLocation");
	
	for (i = 0; i < buttonArray.length; i ++) {
		
		com_chasevida.EVENTS.addEventHandler(document.getElementById(buttonArray[i]), "mouseover", divTableOver, false);
		com_chasevida.EVENTS.addEventHandler(document.getElementById(buttonArray[i]), "mouseout", divTableOut, false);
		com_chasevida.EVENTS.addEventHandler(document.getElementById(buttonArray[i]), "click", divTableClick, false);
		
		disableTableLinksByElement(buttonArray[i]);
	}
}

function initTableButtonHover(event) {
	addTableButtonHoverListeners();
}

com_chasevida.EVENTS.addEventHandler(window, "load", initTableButtonHover, false);
