var cur_menu;
var cur_item;

var Menu = {timer : null, current : null};
Menu.getStyle = function(name){
	if(document.getElementById) { 
		return document.getElementById(name).style;
	} else if(document.all) {
		return document.all[name].style;
	} else if(document.layers) { 
		return document.layers[name];
	}
	
	return null;
	
}
Menu.show = function(id){
	// another menu may be visible so hide
	Menu.doHide();
	
	if(this.timer) clearTimeout(this.timer);
	this.current = id;

	cur_menu = document.getElementById(id + "_menu");
	cur_item = document.getElementById(id + "_item");

	// check if there is a submenu for this item
	if ( cur_menu != null )
	{
		cur_menu.style.visibility = "visible";
		cur_menu.style.left = getPageOffsetLeft(cur_item) + "px";
		cur_menu.style.top = (getPageOffsetTop(cur_item) + 22) + "px";
	}
	
	/*if(cur_menu.style.opacity == 0 || cur_menu.style.MozOpacity == 0 ){
		opacity(id + "_menu", 0, 100, 500);	
	}*/
	
	// hilite product menu link
	this.rollOverItem(cur_item);

}
Menu.hide = function(){
	this.timer = setTimeout("Menu.doHide()",100);
}
Menu.doHide = function(){
	if(this.current){

		// hilite product menu link
		this.current = null;
		if ( cur_menu != null )
		{
			cur_menu.style.visibility = "hidden";
		}
		this.rollOutItem(cur_item);
		
		cur_menu = null;
		cur_item = null;
	}
}

Menu.rollOverItem = function(item) {
	item.className = "menu_item_active";
}

Menu.rollOutItem = function(item) {
	item.className = "menu_item";
}

Menu.rollOverSubItem = function(item) {
	item.className = "sub_menu_item_active";
}

Menu.rollOutSubItem = function(item) {
	item.className = "sub_menu_item";
}

function getPageOffsetLeft(el) {
  var x;
  // Return the x coordinate of an element relative to the page.
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);
  return x;
}

function getPageOffsetTop(el) {
  var y;
  // Return the x coordinate of an element relative to the page.
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}

/* menu fade script */


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
