var Slddm = new Array();


Slddm.timeout               = 500;
Slddm.closetimer            = 0;
Slddm.ddmenuitem            = 0;
Slddm.containerClassName    = 'slddm';



// -------------------------------------
// open the needed layer
// -------------------------------------
Slddm.mopen = function(id){   
    // cancel close timer
    Slddm.mcancelclosetime();

    // close old layer
    if(Slddm.ddmenuitem) Slddm.ddmenuitem.style.visibility = 'hidden';

    // get new layer and show it
    Slddm.ddmenuitem = document.getElementById(id);
    Slddm.ddmenuitem.style.visibility = 'visible';
}

// --------------------------------------
// close showed layer
// --------------------------------------
Slddm.mclose = function(){
    if(Slddm.ddmenuitem) Slddm.ddmenuitem.style.visibility = 'hidden';
}

// --------------------------------------
// go close timer
// --------------------------------------
Slddm.mclosetime = function(){
    Slddm.closetimer = window.setTimeout(Slddm.mclose, Slddm.timeout);
}

// --------------------------------------
// cancel close timer
// --------------------------------------
Slddm.mcancelclosetime = function(){
    if(Slddm.closetimer){
        window.clearTimeout(Slddm.closetimer);
        Slddm.closetimer = null;
    }
}
// --------------------------------------
// configure a navigation level
// --------------------------------------
Slddm.configureNavigationLevel = function(level){
    if(level!=null){
        //get the submenu
        var divs = level.getElementsByTagName('div');
        //only if the submenu is there, install the event handlers
        if(divs!=null && divs.length>0){
            //check if the submenu has also links
            var submenuitems = divs[0].getElementsByTagName('a');
            if(submenuitems!=null && submenuitems.length>0){
	            //get the link
	            var as = level.getElementsByTagName('a');
	            if(as && as.length){
	                as[0].onmouseover      = function(){
	                    // cancel close timer
	                    Slddm.mcancelclosetime();
	                
	                    // close old layer
	                    if(Slddm.ddmenuitem) Slddm.ddmenuitem.style.visibility = 'hidden';
	                
	                    // get new layer and show it
	                    if(divs[0]){
	                        Slddm.ddmenuitem = divs[0];
	                        Slddm.ddmenuitem.style.visibility = 'visible';
	                    }
	                };
	                
	                as[0].onmouseout       = Slddm.mclosetime;
	                divs[0].onmouseover    = Slddm.mcancelclosetime;
	                divs[0].onmouseout     = Slddm.mclosetime;
	            }
            }
        }
    }
}

// --------------------------------------
// configure a navigation
// --------------------------------------
Slddm.configureNavigation = function(navigation){
    if(navigation!=null){
        var lis = navigation.getElementsByTagName('li');
        if(lis && lis.length){
            for(var i=0; i<lis.length; i++){
                Slddm.configureNavigationLevel(lis[i]);            
                //alert('one to li ' + lis[i].innerHTML);    
            }
        }
    }
}

// --------------------------------------
// init the configuration
// add this function at the end of the page or
// like an event of the load document
// --------------------------------------
Slddm.init = function(){
    //get the menu item containers
    var uls = document.getElementsByTagName('ul');
    if(uls && uls.length){
        for(var i=0; i<uls.length; i++){
            if(uls[i].className == Slddm.containerClassName){
                Slddm.configureNavigation(uls[i]);
                //alert('one to document ' + uls[i].innerHTML);
            }
        }
    }
}

// close layer when click-out
// document.onclick = Slddm.mclose; 