/*
* Menu
* @Author: Alexander Gavazov
* @Site: www.studio.bg
*/


var Menu = function(menu) {
	if (!menu) {
		return;
	}

	this.menu = menu;
	this.actionsTime = .4;
	this.setBehaviour();
}

Menu.prototype.setBehaviour = function() {
	this.menu.select('LI').each(function(node) {
		var subMenu = node.select('UL')[0];
		if (subMenu) {
			subMenu.hide();
			node.observe('mouseover', this.show.bind(this, subMenu));
			node.observe('mouseout', this.hide.bind(this, subMenu));
		}
	}.bind(this));
}

Menu.prototype.show = function(targetElement) {
	clearTimeout(targetElement.actionTimer);

	targetElement.actionTimer = setTimeout(this.doShow.bind(this, targetElement), 300);
}

Menu.prototype.doShow = function(targetElement) {
	if (targetElement.Effect) {
		return;
	}

	targetElement.show();
	targetElement.style.display = 'block';
	targetElement.up().addClassName('hover');
}

Menu.prototype.hide = function(targetElement) {
	clearTimeout(targetElement.actionTimer);

	targetElement.actionTimer = setTimeout(this.doHide.bind(this, targetElement), 500);
}

Menu.prototype.doHide = function(targetElement) {
	targetElement.hide();
	targetElement.up().removeClassName('hover');
}
