/**
 * @author chasevida
 */

var divElement;
var divElementNotch;
var previousBackgroundColor;

var hoverColor = "#FFCC00";

//function divClick(event) {
function divClick(link) {
	//alert("link: " + link);
	//var divId = this.getAttribute("id");
	//var hereTd = document.getElementById(divId);
	//var hereHref = hereTd.getElementsByTagName('a')[0].href;
	
	window.location = link;
}


//function divOver(event) {
function divOver(newID) {
	
	var divId = newID;
	//alert(divId);
	//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 divOut(event) {
function divOut(newID) {
	var divId = newID;
	divElement = document.getElementById(divId);
	divElement.style.backgroundColor = previousBackgroundColor;
	divElementNotch.style.borderLeftColor = previousBackgroundColor;
}

function disableLinksByElement(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 addButtonHoverListeners() {
	
	var buttonArray = new Array("hoverDivOne", "buyersRegister", "sellersRegister");
	var checkedArrays = new Array();
	
	var count = 0;
	var arrayLength = buttonArray.length;
	for ( var i = 0; i < arrayLength; ++ i ) {
		
		var checkElement = document.getElementById(buttonArray[i]);
		if (checkElement != null) {
			checkedArrays[count] = buttonArray[i];
			count ++;
		}
	}
	
	var arrayLength = checkedArrays.length;
	for (i = 0; i < checkedArrays.length; i ++) {
		
		com_chasevida.EVENTS.addEventHandler(document.getElementById(checkedArrays[i]), "mouseover", divOver, false);
		com_chasevida.EVENTS.addEventHandler(document.getElementById(checkedArrays[i]), "mouseout", divOut, false);
		com_chasevida.EVENTS.addEventHandler(document.getElementById(checkedArrays[i]), "click", divClick, false);
		
		disableLinksByElement(checkedArrays[i]);
	}
}

function initButtonHover(event) {
	addButtonHoverListeners();
}

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