var timeout	= 300;
var closetimer	= 0;
var ddmenuitem	= 0;
this.cartActive = false;
this.alertTimerId = 0;
this.justAddedProduct = 0;


// open hidden layer
function openCart(id)
{	
	cancelTimer();
	cartPreview();
}
// close showed layer
function closeCart()
{
	cartHide();
//	if(ddmenuitem) ddmenuitem.style.display = 'none';
}

// go close timer
function clearTimer()
{
	closetimer = window.setTimeout(closeCart, timeout);
}

// cancel close timer
function cancelTimer()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function addQuot() {
	if (document.SearchForm.q.value != "") {
		document.SearchForm.submit();
		return true;
	} else {
		alert("Please fill-in the search box");
		document.SearchForm.q.focus();
		return false;
	}
}

function joinEmailBox(mouseState) {
	if (document.getElementById) {
		this.joinBox = $('topNavJoin');
		this.searchBox = $('topNavSearch');
		
		if(mouseState == 'over') {
			this.joinBox.style.display = 'block';
			this.searchBox.style.display = 'none';
		} else if (mouseState == 'out') {
			this.joinBox.style.display = 'none';
			this.searchBox.style.display = 'block';
		}
	}
}

function cartPreview() {
	if(this.cartActive == false && this.alertTimerId == 0) {
		this.cartBtnActive = $('cartBtnActive');
		this.cartBtnDeactive = $('cartBtnDeactive');

		Effect.SlideDown('topNavCartReview', { duration: 0.2 });
	 	this.cartActive = true;
		this.alertTimerId = 1;
	 	//this.alertTimerId = setTimeout ( "cartHide()", 5000 );
	}
	
	if(this.justAddedProduct == 1)
		setTimeout ( "cartHide()", 3000 );
}

function cartHide() {
	if(this.alertTimerId != 0 && this.cartActive == true) {
		Effect.SlideUp('topNavCartReview', { duration: 0.2 });
	 	this.btnTimerId = setTimeout ( "activateBtn()", 100 );
		this.cartActive = false;
		this.alertTimerId = 0;
		this.justAddedProduct = 0;
	}
}

function activateBtn() {
//	this.cartBtnActive.style.display = 'inline';
//	this.cartBtnDeactive.style.display = 'none';
}

function displayCart() {
	this.alertTimerId = 0;
	this.cartActive = false;
}

function isMouseLeaveOrEnter(e, handler) {
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function mouseOutCart() {
	this.alertTimerId = 1;
	this.cartActive = true;
	cartHide();
}
