var tobasketinaction = true;
var _X = 0;
var _Y = 0;
var emailactive = false, opinionactive=false;

var retoldTimer, retoldmessageTimer, addopinionTimer;

var delay = 600000;

function mouseXY(e) {
	var x = 0, y = 0;

	if (!e) e = window.event;

	if (e.pageX || e.pageY) {
		x = e.pageX;
		y = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	return {"x": x, "y": y};
}

function initi() {
	if ($('costdown1')) {
		costownspans = $('costdown1').getElementsByTagName('span');
		for (i = 0; i < costownspans.length; i++) {
			costownspans[i].onmouseover = function () {
				for (j = 0; j < costownspans.length; j++) {
					costownspans[j].style.backgroundImage = "url('/imgs/blank.gif')";
				}
			}
			costownspans[i].onmouseout = function () {
				for (j = 0; j < costownspans.length; j++) {
					costownspans[j].style.backgroundImage = "url('/imgs/dash2.gif')";
				}
			}
		}
	}
	if ($('costdown1')) {
		$('costdown1').onclick = function () {
			$('costdown1').style.visibility = "hidden";

			$('message').style.left = '-5px';
			$('message').style.top = '0px';
			$('topMessage').style.backgroundColor = grabColor(this.parentNode.parentNode.parentNode.className);
			$('midMessage').style.backgroundColor = grabColor(this.parentNode.parentNode.parentNode.className);
			$('message').style.display = 'block';
			if($('costdown2')) {
				$('bottom5').style.display = "none";
				$('bottom6').style.display = "none";
				$('bottom7').style.display = "none";
				$('bottom8').style.display = "none";
				$('costdown2').style.visibility = "visible";
				$('message2').style.display = 'none';
			}

			clearTimeout(retoldmessageTimer);
			retoldmessageTimer = setTimeout("retoldmessage()",delay);

			return false;
		}
	}

	if ($('costdown2')) {
		$('costdown2').onclick = function () {
			$('costdown2').style.visibility = "hidden";

			$('message2').style.left = '-5px';
			$('message2').style.top = '0px';
			$('topMessage2').style.backgroundColor = grabColor(this.parentNode.parentNode.parentNode.className);
			$('midMessage2').style.backgroundColor = grabColor(this.parentNode.parentNode.parentNode.className);
			$('message2').style.display = 'block';
			if($('costdown1')) {
				$('bottom1').style.display = "none";
				$('bottom2').style.display = "none";
				$('bottom3').style.display = "none";
				$('bottom4').style.display = "none";
				$('costdown1').style.visibility = "visible";
				$('message').style.display = 'none';
			}

			clearTimeout(retoldmessageTimer);
			retoldmessageTimer = setTimeout("retoldmessage()",delay);

			return false;
		}
	}

	Event.observe(document, 'mousemove', _XY);
	Event.observe(document, 'click', retoldall);

}

function _XY (e) {
	_X = mouseXY(e).x - parseInt(e.offsetX || e.layerX) - 3;
	_Y = mouseXY(e).y - parseInt(e.offsetY || e.layerY) - 3;
}

function retold(item) {
	tobasketinaction = true;
	if ($('bottom1')) $('bottom1').style.display = "none";
	if ($('bottom2')) $('bottom2').style.display = "none";
	if ($('bottom3')) $('bottom3').style.display = "none";
	if ($('bottom4')) $('bottom4').style.display = "none";
	if ($('bottom5')) $('bottom5').style.display = "none";
	if ($('bottom6')) $('bottom6').style.display = "none";
	if ($('bottom7')) $('bottom7').style.display = "none";
	if ($('bottom8')) $('bottom8').style.display = "none";
}

function retoldmessage() {
	if (emailactive == false) {
		if($('costdown1')) {
			$('costdown1').style.visibility = "visible";
			$('message').style.display = "none";
			$('bottom1').style.display = "none";
			$('bottom2').style.display = "none";
			$('bottom3').style.display = "none";
			$('bottom4').style.display = "none";
		}

		if($('costdown2')) {
			$('costdown2').style.visibility = "visible";
			$('message2').style.display = "none";
			$('bottom5').style.display = "none";
			$('bottom6').style.display = "none";
			$('bottom7').style.display = "none";
			$('bottom8').style.display = "none";
		}
	} else {
		clearTimeout(retoldmessageTimer);
		retoldmessageTimer = setTimeout("retoldmessage()", delay);
	}
}

function retoldall (e) {
	try {
		if (_event(e).parentNode.parentNode.id!="costdown1"&&_event(e).parentNode.parentNode.id!="costdown2"&&_event(e).parentNode.className!="message"&&_event(e).parentNode.parentNode.className!="message"&&_event(e).parentNode.parentNode.parentNode.className!="message"&&_event(e).parentNode.parentNode.parentNode.parentNode.className!="message"&&_event(e).parentNode.className!="message2"&&_event(e).parentNode.parentNode.className!="message2"&&_event(e).parentNode.parentNode.parentNode.className!="message2") {
			retold ();
			retoldmessage();
		}
	}
	catch(err) {
		
	}
}


function emailisactive () {
	emailactive = true;
}
function emailnoactive () {
	emailactive = false;
}
function opinionisactive () {
	opinionactive=true;
}
function opinionnoactive () {
	opinionactive=false;
}
function _event (evt) {
	if (!evt) {
		evt = event;
	}
	var ev = (evt.srcElement) ? evt.srcElement : evt.target;
	return ev;
}

function disableSelection(element) {
	element.onselectstart = function() {
		return false;
	};
	element.unselectable = "on";
	element.style.MozUserSelect = "none";
	element.style.cursor = "default";
}
function grabColor(parentItem) {
	if (parentItem.indexOf("maroon") >= 0) {
		if ($('bottom1')) $('bottom1').style.display = "block";
		if ($('bottom5')) $('bottom5').style.display = "block";
		return "#c06";
	}

	if (parentItem.indexOf("green") >= 0) {
		if ($('bottom2')) $('bottom2').style.display = "block";
		if ($('bottom6')) $('bottom6').style.display = "block";
		return "#4db848";
	}

	if (parentItem.indexOf("blue") >= 0) {
		if ($('bottom3')) $('bottom3').style.display = "block";
		if ($('bottom7')) $('bottom7').style.display = "block";
		return "#09f";
	}

	if (parentItem.indexOf("orange") >= 0) {
		if ($('bottom4')) $('bottom4').style.display = "block";
		if ($('bottom8')) $('bottom8').style.display = "block";
		return "#f60";
	}

	/*default color*/
	return "black";
}


Event.observe(window, 'load', initi, false);
