// JavaScript Document
var dropdowns = new Array();
var ddProps = new Array();

function slideIn(id) {
	if (!scriptready) return;
	if (!dropdowns[id])
	{
		dropdowns[id] = new Fx.Slide(id, {duration: 300});
		document.getElementById(id).style.visibility = "hidden";
		document.getElementById(id).style.display = "block";
		dropdowns[id].hide();
		document.getElementById(id).style.visibility = "visible";
	}
	if (!ddProps[id] || ddProps[id] <= 0)
	{
		ddProps[id] = 0;
		dropdowns[id].slideIn();
		propOpen(id);
		setTimeout("slideOut('"+id+"');", 400);
	}
}
function slideOut(id) {
	if (!dropdowns[id])
		dropdowns[id] = new Fx.Slide(id, {duration: 300});

	if (ddProps[id] == 0)
	{
		//dropdowns[id].slideOut();
		document.getElementById(id).style.visibility = "hidden";
		dropdowns[id].hide();
		document.getElementById(id).style.visibility = "visible";
	}
	else
		setTimeout("slideOut('"+id+"');", 400);
}
function propOpen(id) {
	if (!ddProps[id])
		ddProps[id] = 0;
		
	ddProps[id]++;
}
function unprop(id) {
	if (!ddProps[id])
		ddProps[id] = 0;
	else
		ddProps[id]--;
}

function highlight(elem) {
	elem.className = "indented highlit item";
}

function unhighlight(elem) {
	elem.className = "indented item";
}

 
var SlideMenu = {
    create: function (elementID, menuButton, direction, noevents) {
                var newmenu = Object();
                newmenu.props = 0;
                newmenu.mode = 'vertical';
                if (typeof(direction) != "undefined" && direction != null) newmenu.mode = direction;
               
                //Move the menu off the screen, show the menu, create the Menu, collapse the menu, replace the menu.
                newmenu.menu = $(elementID);
                newmenu.menu.slider = newmenu;
                if (!noevents)
                {
					if (!Browser.Platform.ipod)
					{
						newmenu.menu.addEvent('mouseover', function(){this.slider.prop();});
						newmenu.menu.addEvent('mouseout', function(){this.slider.unprop();});
						if (menuButton)
						{
							$(menuButton).slider = newmenu;
							$(menuButton).addEvent('mouseover', function(){this.slider.show();});
							$(menuButton).addEvent('mouseout', function(){this.slider.unprop();});
							$(menuButton).addEvent('click', function()
							{
								if (this.slider.props > 0) this.slider.unprop();
								else this.slider.show();
							});
						}
					} else {
						if (menuButton)
						{
							$(menuButton).slider = newmenu;
							$(menuButton).addEvent('click', function()
							{
								if (this.slider.props > 0) this.slider.unprop();
								else this.slider.show();
								return false; //stopPropagation
							});
							$(menuButton).addEvent('mouseout', function() { this.slider.unprop(); });
						}
					}
                }
                newmenu.menu.style.visibility = "hidden";
                newmenu.menu.style.display = "block";
                newmenu.menu.style.left = (newmenu.menu.offsetLeft - 1000) + "px";
                newmenu.menu.style.visibility = "visible";
                newmenu.slider = new Fx.Slide(elementID, {duration: 500, mode: newmenu.mode}).hide();
                newmenu.menu.style.left = (newmenu.menu.offsetLeft + 1000) + "px";
               
                newmenu.instanceID = elementID; 
                SlideMenu.instances[newmenu.instanceID] = newmenu;
               
                newmenu.show = function(force) {
                    if (force) this.props = 0;
                    if (this.props == 0)
                    {
                        this.slider.cancel();
                        this.slider.slideIn();
                        this.prop();
                    }
                }
               
                newmenu.hide = function() {
                    if (this.props == 0)
                    {
                        this.slider.cancel();
                        this.slider.slideOut();
                    }
                }
           
                newmenu.prop = function() {
                    this.props++;
                }
           
                newmenu.hideTimer = null;
                newmenu.unprop = function() {
                    if (this.props <= 0)
                        this.props = 0;
                    else
                        this.props--;
                    clearTimeout(this.hideTimer);
                    this.hideTimer = setTimeout("SlideMenu.instances['"+this.instanceID+"'].hide();", 200);
                }
               
                return newmenu;
            },
       
 
    instances: new Array(), //Public static member containing references to all isntances of SlideMenu objects.
   
    //show will show a menu if it is not already shown, prop it open, and set a timeout for it to auto-hide when it is unpropped.
    show:   function (id, force) {
                if (typeof(SlideMenu.instances[id]) == "object")
                    SlideMenu.instances[id].show(force || false);
            },
    //unprop takes the prop off a menu so it can hide the next time it tries.
    unprop: function (id) {
                if (typeof(SlideMenu.instances[id]) == "object")
                    SlideMenu.instances[id].unprop();
            },
    //prop adds another prop to the menu so that it won't hide until it is unpropped.
    prop:   function (id) {
                if (typeof(SlideMenu.instances[id]) == "object")
                    SlideMenu.instances[id].prop();
            }
};
 