if(!IDE){
    var IDE = {};
};

function props(obj){
    for(var i in obj){
        console.log(i, obj[i]);
    }
}


IDE.megamenu = function(){
    var that = {};

    // ID from setTimeOut: used to remove pending methods
    that.setTimeoutID = null;

    // classname of hovered menu item link
    that.currentTarget = null;

    // show the current hovered item
    that.showMegaItem = function(){
        var content_div = that.currentItem.select('div.mega-item-content')[0];

        // show the div
        content_div.setStyle({display:'block'});        
        
        // set the style of menu li element
        that.currentItem.addClassName('hover');
        
     // hide the object tags
      /* $$('iframe')[0].setStyle({visibility:'visible'});    
       $$('object')[0].setStyle({visibility:'visible'});    */
        var oelemts = $$('object');
        oelemts.each(function(x) {
            x.setStyle({visibility:'hidden'});
        });
      // hide the iframe tags
       var ielemts = $$('iframe');
       ielemts.each(function(y) {
            y.setStyle({visibility:'hidden'});
        });

    };

    // Hide the currently hovered item
    that.hideMegaItem = function(){
        if(that.currentItem == this)
            return;

        var content_div = that.currentItem.select('div.mega-item-content')[0];

        // hide the div
        content_div.setStyle({display:'none'});        
              
        that.currentItem.removeClassName('hover');
        
     // hide the object tags
      /* $$('iframe')[0].setStyle({visibility:'visible'});    
       $$('object')[0].setStyle({visibility:'visible'});    */
        var oelemts = $$('object');
        oelemts.each(function(x) {
            x.setStyle({visibility:'visible'});
        });
      // hide the iframe tags
       var ielemts = $$('iframe');
       ielemts.each(function(y) {
            y.setStyle({visibility:'visible'});
        });
    };

    that.mouseOverMegaItem = function(ev){
        if(that.timeoutID){
            // turn off the delayed show of the mega-menu
            clearTimeout(that.timeoutID);            
        }
        // if another mega item menu is currently shown hide it
        if(that.currentItem && that.currentItem != this){
            that.hideMegaItem();
        }
        that.currentItem = this;
        that.timeoutID = window.setTimeout(that.showMegaItem, 500);  
    };

    that.mouseOutMegaItem = function(ev){
        if(that.timeoutID){
            // turn off the delayed show of the mega-menu
            clearTimeout(that.timeoutID);            
        }
        that.currentItem = this;
        that.timeoutID = window.setTimeout(that.hideMegaItem, 250);  
    };

    that.addMenuItemsHoverListener = function(){
        $$('.mega-item').each(
            function(item){
                // YEAH. mouseenter and mouseleave events
                // added to prototype 1.6.1
                item.observe('mouseenter', that.mouseOverMegaItem);
                // turned of for now
                item.observe('mouseleave', that.mouseOutMegaItem);
            }
        );
    };

    that.init = function(){
        that.addMenuItemsHoverListener();
        return that;
    };

    return that.init();
};

document.observe("dom:loaded", function() {
   IDE.megamenu();
});
