﻿LangloWeb.ProductManager = function() 
{
    Sys.Application.add_init(Function.createDelegate(this, this.handleAppInit));
    Sys.Application.add_load(Function.createDelegate(this, this.handleAppLoad));
}

LangloWeb.ProductManager.prototype = 
{
    getSplashPanel : function()
    {
        var panel = $get('WardrobePanel2'); 
        if (panel == null)
            panel = $get('overlayBig'); 
        return panel;
    },
    
    onGetDescription : function(results) 
    {
        if (results != null && results.toString().length > 0) 
        {
            var desc = $get('WardrobePanel2'); 
            if (desc == null)
                desc = $get('overlayBig'); 
            if (desc != null)
                desc.innerHTML = results; 
        }
    },
    
    menuMouseover : function(sender) 
    {
        if (sender != null && typeof sender.target != 'undefined')
        {
            var link = sender.target;
            if (link != null && link.nodeName == 'A')
            {
                var splash = this.getSplashPanel();
                if (splash != null)
                {
                    // Div displays 'we have a dream...', let's hide it!
                    var WardrobePanel1 = $get('ctl00_cpMain_WardrobePanel1');
                    if (WardrobePanel1) 
                        WardrobePanel1.style.display = 'none'; 
                        
                    // Strips the first 4 chars from the control id and uses the remainder as the key in a lookup
                    // to retrieve the menu item's description.
                    var id = link.id.substring(this.idOffset);
                    ProductService.GetDescriptionHTM(id, this.onGetDescriptionDelegate);
                }
            }
        }
    }, 
        
    // Not currently used
    menuMouseout : function(control) 
    {
        var desc = this.getSplashPanel();
        if (desc != null)
            desc.innerHTML = ''; 
    },
    
    handleAppLoad : function()
    {
        var menu = $get('ProdMenu');
        if (menu != null) 
        {
            var delegate = Function.createDelegate(this, this.menuMouseover);
            $addHandler(menu, 'mouseover', delegate);
            // Don't think we want to erase the text on mouseout!
            //delegate = Function.createDelegate(this, this.menuMouseout);
            //$addHandler(menu, 'mouseout', delegate);
        }
    },

    handleAppInit : function()
    {
        var idPrefix = 'ctl00_cbBottomLeft_ProductsMenu_';
        this.idOffset = idPrefix.length;
        this.onGetDescriptionDelegate = Function.createDelegate(this, this.onGetDescription);
    }
}

// Register the class with the script manager. 
LangloWeb.ProductManager.registerClass('LangloWeb.ProductManager'); 
 
productMgr = new LangloWeb.ProductManager();

if (typeof(Sys) !== 'undefined')
    Sys.Application.notifyScriptLoaded();
