﻿


function llx_menu() {


	this.OpenMenu = function(link, menu, direction, x, y) {
		link.onmouseover = "";		
		var o = CreateMenu(link, menu, direction, x, y);


	}

 }




//menu
var menu_cssclass = 'menu'
var menuitem_zIndex=10000
function CreateMenu(link, menu, direction, x, y) {
	var o = document.createElement("div")
	document.body.appendChild(o)
	o.style.visibility = 'hidden'
	o.style.position = 'absolute'
	o.style.overflow = 'hidden'
	o.appendChild(menu)
	StartMenu(link, o, direction, x, y)
	return o
}

function StartMenu(parent, menu, direction, x, y) {
	var closeTimeout = 0;
	var opened = false;
 	$(parent).bind("mouseenter", function(e) { mEnter() })
 	$(parent).bind("mouseleave", function(e) { closeTimeout=setTimeout(mLeave,300) })
 	$(menu).bind("mouseenter", function(e) { clearTimeout(closeTimeout) })
 	$(menu).bind("mouseleave", function(e) { closeTimeout = setTimeout(mLeave, 300) })
 	if (direction == undefined) { direction = 'ud' }
 	if (x == undefined) { x = 0 }
 	if (y == undefined) { y = 0 }
 	mEnter()
 	
 	function mEnter() {
 		clearTimeout(closeTimeout)
 		if (opened == true) {return true }
 		menu.style.visibility = 'visible'
 		menu.childNodes[0].style.display='block'
 		if (direction=='ud') {
 			menu.childNodes[0].style.top = -$(menu.childNodes[0]).height() + "px";
 			menu.style.top = $(parent).offset().top + y + $(parent).height() + 'px';
 			menu.style.width = $(menu.childNodes[0]).width() + 'px';
 			menu.style.left = $(parent).offset().left + x + 'px';
 			menu.style.height = $(menu.childNodes[0]).height() + 'px';
 			menuitem_zIndex += 1;
 			menu.style.zIndex = menuitem_zIndex;
 			$(menu.childNodes[0]).animate({ top: "0px" }, 300, null, function() {opened=true });
 		}
 		if (direction == 'du') {
 			menu.childNodes[0].style.top = $(menu.childNodes[0]).height() + "px";
 			menu.style.left = $(parent).offset().left + x + 'px';
 			menu.style.width = $(menu.childNodes[0]).width() + 'px';
 			menu.style.height = $(menu.childNodes[0]).height() + 'px';
 			menu.style.top = $(parent).offset().top + y - menu.offsetHeight - 1 + 'px';
 			menuitem_zIndex += 1;
 			menu.style.zIndex = menuitem_zIndex;
 			$(menu.childNodes[0]).animate({ top: "0px" }, 300, null, function() { opened = true });
 		 }
 	 }
 	 function mLeave() {
 	 	if (direction == 'ud') {
 	 		opened = false
 	 		$(menu.childNodes[0]).animate({ top: -$(menu.childNodes[0]).height() + "px" }, 300);
 	 	}
 	 	if (direction == 'du') {
 	 		opened = false
 	 		$(menu.childNodes[0]).animate({ top: +$(menu.childNodes[0]).height() + "px" }, 300);
 	 	}
 	 }
 	
 }


