YAHOO.namespace("tg");

YAHOO.tg.TabMenu = function(tab, tabMenu)
{  
    this.constructor.superclass.constructor.call(this, tabMenu);
    this.cfg.setProperty("context", [tab, "tl", "bl"]);
    
    // IE 6 sets the right edge of the FAQ menu is past right edge of the viewport. 
    // This results in an ulgy horizontal scroll bar
    
    var x    = YAHOO.util.Dom.getX(this.element);
    var cx   = this.element.offsetWidth;
    var cxVP = YAHOO.util.Dom.getViewportWidth();
    
    // var tooWide = x + cx > cxVP;
    // alert('x: ' +  x + ' width: ' + cx + ' vpwidth: ' + cxVP + ' tooWide: ' + tooWide);
    if (x + cx > cxVP)
    {
        this.element.style.width = (cxVP - x - 10) + 'px';
        this.show();
        this.hide();
    }
    
    YAHOO.util.Event.addListener(tab, "mouseover", function() 
    { 
        this.show(); 
    }, this, true);
    YAHOO.util.Event.addListener(tabMenu, "mouseover", function() 
    { 
        YAHOO.util.Dom.addClass(tab, "selected");
        this.show();
    }, this, true);
    YAHOO.util.Event.addListener(tab, "mouseout", function() 
    { 
        this.hide(); 
    }, this, true);
    YAHOO.util.Event.addListener(tabMenu, "mouseout", function() 
    { 
        YAHOO.util.Dom.removeClass(tab, "selected");
        this.hide(); 
    }, this, true);
};

YAHOO.lang.extend(YAHOO.tg.TabMenu, YAHOO.widget.Overlay);
