﻿var TSDD_$ = function (id) {return "string" == typeof id ? document.getElementById(id) : id;};
function DDMenu(obj,target,options)
{
    if(!options){
        options = [];
    }
    options.w = options.w || 125;
    options.x = options.x || 0;
    options.y = options.y || 0;
    var pos = DDObjPosition(obj);
    target = TSDD_$(target);
    target.style.display = "block";
    target.style.left = pos.x + options.x + "px";
    target.style.top = pos.y + obj.offsetHeight + options.y + "px";
    var menuul = target.getElementsByTagName("ul");
    var menuli = menuul[0].getElementsByTagName("li");
    //obj.onmouseover = show;
    obj.onmouseout = unshow;
    menuul[0].onmouseover = show;
    menuul[0].onmouseout = unshow;
    function show(){
        menuul[0].style.width = options.w + "px";
        menuul[0].className = "ddmenuclearfix typeul block"
    }
    function unshow(){
        menuul[0].className = "typeul"
    }
    for(var i = 0; i < menuli.length; i++){
        menuli[i].num = i;
        var liul = menuli[i].getElementsByTagName("ul")[0];
        if(liul){
            liul.style.left = options.w + "px";
            liul.style.width = options.w + "px";
            menuli[i].getElementsByTagName("a")[0].className = "haschild";
            typeshow();            
        }
    }
    function typeshow(){
        menuli[i].onmouseover = showul;
        menuli[i].onmouseout = unshowul;
    }
    function showul(){
        menuli[this.num].getElementsByTagName("ul")[0].className = "block";
    }
    function unshowul(){
        menuli[this.num].getElementsByTagName("ul")[0].className = "";
    }
    show();
}
function DDObjPosition(obj){
    var target = obj;
    var pos = {x:target.offsetLeft,y:target.offsetTop};
    var target = target.offsetParent; 
    while (target) { 
        pos.x += target.offsetLeft; 
        pos.y += target.offsetTop; 
        target = target.offsetParent;
    }
    return pos;
}
