/**
* CSShiarchMenu v0.6
*        written by: me[AT]daantje[DOT]nl
*        last update: Sat Nov 26 13:08:45 CET 2005
*
*        Documentation:
*                Build this small script cause all the gpl-ed scripts I found where too big
*                and had too many options I never going to use, or the config for the menu
*                was not easy to set with a PHP routine.
*
*        License:
*                LGPL. (http://www.gnu.org/copyleft/lesser.txt)
*
*        Dontate:
*                Please, when you like my script, click a view banners on
*                http://www.dantje.nl Or use my pay-pal donation button.
*/

//declare
var submenu = new Array();
var tmr = new Array();
var adj = new Array();
var last_zIndex = 10000;
var lastOverId = '';


// CONFIG
var alignSubmenu         = 'bottom';
var useLastItemCSS        = true;
var adjustFirst                = true;
var adjustTop                = 5;
var adjustLeft                = 15;                        //Positive number (10) for right, negative (-10) for left.

function buildSubmenu(obj,align){
        lastOverId = obj.id;
        if(!align)
                align = alignSubmenu;
        menuPath = obj.id.split('_');
        x = "div";
        for(i=0;i<menuPath.length;i++){
                x+= '_' + menuPath[i];
                if(document.getElementById(x)){
                        if(tmr[x])
                                window.clearTimeout(tmr[x]);
                        document.getElementById(x).style.visibility = 'visible';
                }
        }
        if(submenu[obj.id]){                d = obj;
                if(d){
                        L_pos = d.offsetLeft + d.offsetWidth;
                        T_pos = d.offsetTop;
                        while(d.offsetParent){
                                d = d.offsetParent;
                                L_pos+= d.offsetLeft;
                                T_pos+= d.offsetTop;
                        }
                }
                if(obj.className.indexOf('menuItem') < 0 && align == 'bottom'){
                        L_pos-= obj.offsetWidth;
                        T_pos+= obj.offsetHeight;
                }
                if((adjustTop || adjustLeft) && (adjustFirst || (!adjustFirst && obj.className.indexOf('menuItem') >= 0))){
                        L_pos+= adjustLeft;
                        T_pos+= adjustTop;
                }

                if(L_pos > 0 && T_pos >0){
                        c = document.getElementById('div_' + obj.id);
                        if(c){
                                c.style.visibility = 'visible';
                                c.style.zIndex = last_zIndex++;
                                c.style.top = (T_pos - 1) + "px";
                                c.style.left = (L_pos - 1) + "px";
                        }else{
                                subObj = document.createElement('div');
                                subObj.id = 'div_' + obj.id;
                                subObj.className = 'submenu';
                                subObj.style.position = 'absolute';
                                subObj.style.zIndex = last_zIndex++;
                                subObj.style.top = (T_pos - 1) + "px";
                                subObj.style.left = (L_pos - 1) + "px";
                                document.getElementsByTagName('body')[0].appendChild(subObj);
                                content = "";
                                m = submenu[obj.id];
                                for(i=0;i<m.length;i++){
                                        if(m[i][1]){
                                                if(m[i][1].substring(0,11) == 'javascript:'){
                                                        act = m[i][1].substring(11);
                                                }else{
                                                        if(!m[i][2] || m[i][2] == '_self')
                                                                act = "self.location.href='" + m[i][1] + "';";
                                                        else if(m[i][2] == '_top')
                                                                act = "top.location.href='" + m[i][1] + "';";
                                                        else if(m[i][2] == '_parent')
                                                                act = "parent.location.href='" + m[i][1] + "';";
                                                        else if(m[i][2] == '_blank')
                                                                act = "window.open('" + m[i][1] + "');";
                                                        else
                                                                act = "window.frames['"+m[i][2]+"'].location.href='" + m[i][1] + "';";
                                                }
                                        }
                                        content+= "<div onmouseout=\"hideSubmenu(this)\" onmouseover=\"buildSubmenu(this)\" "+ (m[i][1] ? "onclick=\""+ act + "\" " : "") +"class=menuItem" + (i==0 ? 'First' : (i==(m.length -1) && useLastItemCSS ? 'Last' : '')) + " id=\"" + obj.id + "_" + i +"\">" + m[i][0] + "</div>";
                                        adj[i] = obj.id + "_" + i;
                                }
                                subObj.innerHTML = content;
                        }
                }
        }
}

function hideSubmenu(obj){
        //get common part of div id
        closePath = obj.id.split('_');

        x = "div";
        for(i=0;i<closePath.length;i++){
                x+= '_' + closePath[i];
                if(document.getElementById(x))
                        tmr[x] = window.setTimeout("document.getElementById('"+x+"').style.visibility = 'hidden';",50);
        }
}

function menuItem(txt,url,tar){
        return new Array(txt,url,tar);
}

document.onmouseover = function(e){
        obj = document.all ? event.srcElement : e.target;
        if(obj.className == 'menuItemFirst' || obj.className == 'menuItem' || obj.className == 'menuItemLast')
                obj.className+='Over';
}
document.onmouseout = function(e){
        obj = document.all ? event.srcElement : e.target;
        if(obj.className == 'menuItemFirstOver' || obj.className == 'menuItemOver' || obj.className == 'menuItemLastOver')
                obj.className = obj.className.substring(0,(obj.className.length - 4));
}

function iFramePatch(){
        if(!document.all && lastOverId)
                hideSubmenu(document.getElementById(lastOverId));
}

