// JavaScript Document

window.onresize = function () {
	var topmenu = gebi('topmenu');
	topmenu.style.display = 'none';
	topmenu.style.display = 'block';
}

window.onload = placeSubmenuDiv;

var shouldHide = true;

var hideTimer = null;
var showTimer = null;

function showMenu() {
	shouldHide = false;
	window.clearTimeout(hideTimer);
	var div = gebi('services-submenu');
	div.style.visibility = 'visible';
	var speedFactor = 5;
	if (div.xOpacity == 0.0) {
		showTimer = window.setInterval('adjustOpacity()', 1);
	}
}

function adjustOpacity() {
	var div = gebi('services-submenu');
	if (div.xOpacity < 1) {
		div.xOpacity = div.xOpacity + 0.1;
		updateOpacity(div)	
	} else {
		window.clearInterval(showTimer);
	}
}


function hideMenu() {
	shouldHide = true;
	hideTimer = window.setTimeout(hide, 1000);
}

function hide() {
	if (shouldHide) {
		var div = gebi('services-submenu');
		div.style.visibility = 'hidden';
		div.xOpacity = 0.0;
		updateOpacity(div);
	}
}

function updateOpacity(div) {
	div.style.opacity = div.xOpacity;
	div.style.MozOpacity = div.xOpacity;
	div.style.filter = 'alpha(opacity=' + (div.xOpacity*100) + ')';	
}

function gebi(id) {
	return document.getElementById(id);
}

function absPos(element) {
	var coords = {x: 0, y: 0};
	while (element) {
		coords.x += element.offsetLeft;
		coords.y += element.offsetTop;
		element = element.offsetParent;
	}
	return coords;
}

function placeSubmenuDiv() {
	var sli = gebi('services-nav');
	var div = gebi('services-submenu');	
	
	var sliCoords = absPos(sli);
	var divCoords = absPos(div);
	
	hide();

	var difY = sliCoords.y - divCoords.y + 30;
	var difX = sliCoords.x - divCoords.x - 177;
	div.style.position = 'relative';
	
	div.style.top = difY + 'px';
	div.style.left = difX + 'px';
}

function goTo(url) {
	window.location = url;
}