<!-- //

var contractTimeout = 200;

/* LeftMenu */
function expandLeftMenu() {
	leftmenudiv = document.getElementById('leftMenu_prod');
	if (leftmenudiv.style.display == 'none') {
		leftmenudiv.style.display = 'block';
	} else if (leftmenudiv.style.display == 'block') {
		leftmenudiv.style.display = 'none';
	}
}

/* Function to find position of elems */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// Get window width (browser compliant
function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

/* Expand menu function */
function expandMenu(caller, category) {
	
	collapseAll('menuSub'); // Collapse all - ignore timer

	if (window.timer) { clearTimeout(window.timer); }

	var callerPos = findPos(caller);
	var menuDiv = document.getElementById('menuSub' + category);
	var browser = usedBrowser();

	var offsetWidthLeft = (getWindowWidth() - 980) / 2 + 39; // 39 - margins and paddings
	

	menuDiv.style.left = callerPos[0] - offsetWidthLeft + 'px';
	menuDiv.style.top = (callerPos[1] - 2) + 'px';

	// Show It
	menuDiv.style.display='block';
}

/* Contract menu function */
function contractMenu(caller, category) {
	var divCategory = document.getElementById('menuSub' + category);
	divCategory.style.display='none';
}

/* Id browser */
function usedBrowser() {
	var userAgent = navigator.userAgent;
	if (userAgent.indexOf('Firefox') != -1) {
		return "Firefox";
	} else if (userAgent.indexOf('MSIE') != -1) {
		return "Internet Explorer";
	} 
}

/* Set the timer */
function setTimer(obj,category) {
	window.timer = setTimeout(function() { contractMenu(obj,category); },contractTimeout);
}

/* Reset the timer */
function resetTimer() {
	if (window.timer) {
		clearTimeout(window.timer);
	}
}

/* Collapse all menus */
function collapseAll(menuSub) {
	var submenus = document.getElementsByTagName("div");
	var retvalue = new Array();
	var i, j;
	for (i=0,j=0;i<submenus.length;i++) {
		var c = " " + submenus[i].className + " ";
		if (c.indexOf(" " + menuSub + " ") != -1) submenus[i].style.display='none';
	}
}
	
// -->
