﻿/*

@requires: YAHOO.dom,YAHOO.event,YAHOO.util

*/

if (typeof DrillSpot == "undefined")
{
    var DrillSpot = { };
}

DrillSpot.menu = {

    buildMenu: function(id) {
    
        var menu = document.getElementById(id);
        var clientWidth = YAHOO.util.Dom.getViewportWidth();
        
        for (var i = 0; i < menu.childNodes.length; i++)
        {
            var item = menu.childNodes[i];
            if (item.nodeName == 'LI')
            {
                item.img = item.getElementsByTagName('IMG')[0];
                
                if (!item.img) continue;
                
                item.img.onSrc = item.img.src.replace('.jpg','_over.jpg');
                item.img.offSrc = item.img.src;
                item.subMenu = item.getElementsByTagName('DIV')[0];

                var r = YAHOO.util.Dom.getRegion(item.img);
                var x = r.left;
                var y = r.bottom;
                
                if (x + 500 > clientWidth)
                    x = clientWidth - 500;
                    
                YAHOO.util.Dom.setStyle(item.subMenu, 'left', x + 'px');
                YAHOO.util.Dom.setStyle(item.subMenu, 'top', y + 'px');
                                        
                item.on = function()
                {
                    if (this.over)
                    {
                        this.img.src = this.img.onSrc;
                        YAHOO.util.Dom.setStyle(this.subMenu, 'display', 'block');
                    }
                };
                item.off = function()
                {
                    if (!this.over)
                    {
                        this.img.src = this.img.offSrc;
                        YAHOO.util.Dom.setStyle(this.subMenu, 'display', 'none');
                    }
                };
                item.onmouseover = function(e) 
                {
                    this.over = true;
                    var item = this;
                    window.setTimeout(function() { item.on(); }, 200);
                };
                item.onmouseout = function(e)
                {
                    this.over = false;
                    var item = this;
                    window.setTimeout(function() { item.off(); }, 100);
                };
            }
        }
    }
};