﻿
// dichiarazione del namespace
Type.registerNamespace("MindTheGap.Stonehenge.Web.UI.Menus");

MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext = function(sContextName, sBackgroundColor, sTextColor, sSelectedTextColor, sBorderColor, iAlpha, bPerformAnimation, bShowFlip, bRenderInline, bVisible) {
    this._contextName = sContextName;
    this._backgroundColor = sBackgroundColor != null ? sBackgroundColor : '#000000';
    this._textColor = sTextColor != null ? sTextColor : '#788386';
    this._selectedTextColor = sSelectedTextColor != null ? sSelectedTextColor : '#FFFFFF';
    this._borderColor = sBorderColor != null ? sBorderColor : '#788386';
    this._alpha = iAlpha != null ? iAlpha : 100;
    this._performAnimation = bPerformAnimation != null ? bPerformAnimation : false;
    this._showFlip = bShowFlip != null ? bShowFlip : false;
    this._renderInline = bRenderInline != null ? bRenderInline : false;
    this._visible = bVisible != null ? bVisible : false;

    
}
MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext.prototype = 
{
        getContextName: function() {return this._contextName;},
        getBackgroundColor: function() {return this._backgroundColor;},
        setBackgroundColor: function(sBackgroundColor) { this._backgroundColor = sBackgroundColor!=null ? sBackgroundColor : '#000000';},
        getTextColor: function() {return this._textColor;},
        setTextColor: function(sTextColor) { this._textColor = sTextColor!=null ? sTextColor : '#788386';},
        getSelectedTextColor: function() {return this._selectedTextColor;},
        setSelectedTextColor: function(sSelectedTextColor) { this._selectedTextColor = sSelectedTextColor!=null ? sSelectedTextColor : '#FFFFFF';},
        getBorderColor: function() {return this._borderColor;},
        setBorderColor: function(sBorderColor) { sBorderColor!=null ? sBorderColor : '#788386';},  
        getAlpha: function() {return this._alpha;},
        setAlpha: function(iAlpha) { iAlpha!=null ? iAlpha : 100;},
        getPerformAnimation: function() {return this._performAnimation;},
        setPerformAnimation: function(bPerformAnimation) { bPerformAnimation!=null ? bPerformAnimation : false;},
        getShowFlip: function() {return this._showFlip;},
        setShowFlip: function(bShowFlip) {  bShowFlip !=null ? bShowFlip : false;},
        getRenderInline: function() {return this._renderInline;},
        setRenderInline: function(bRenderInline) { bRenderInline !=null ? bRenderInline : false;},
        getVisible: function() {return this._visible;},
        setVisible: function(bVisible) { bVisible != null ? bVisible : false;}
        
}
MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext.registerClass('MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext', null, Sys.IDisposable); 

var menuContexts = new MindTheGap.Web.UI.Helpers.Hashtable();

var menuContextDay = new MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext('Day','#FFFFFF','#788386','#000000','#788386','75',true,true,false,true);
var menuContextNight = new MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext('Night','#000000','#788386','#FFFFFF','#788386','75',true,true,false,true);
var menuContextInternal = new MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext('Internal','#000000','#788386','#FFFFFF','#788386','100',false,false,false,true);
var menuContextHome = new MindTheGap.Stonehenge.Web.UI.Menus.ClientMenuContext('Home','#000000','#788386','#FFFFFF','#788386','100',false,false,false,false);

menuContexts.put(menuContextDay._contextName,menuContextDay);
menuContexts.put(menuContextNight._contextName,menuContextNight);
menuContexts.put(menuContextInternal._contextName,menuContextInternal);
menuContexts.put(menuContextHome._contextName,menuContextHome);

MindTheGap.Stonehenge.Web.UI.Menus.ClientMenu = function(sContextName, sFontName, bUseText, iInitialFontSize, iFontSizeDecrement, iMenuTimeout, sImageFormat, bUseTransparentImages, bDrawFlip, iZindex, iTop, iLeft)
{
    this._lMenuContainer = $get('lMenuContainer');
    this._lMenuContents = $get('lMenuContents');
    this._lMenuContentsInner = $get('lMenuContentsInner');
    this._lMenuFlipArea = $get('lMenuFlipArea');
    this._lMenuFlipAreaVertical = $get('lMenuFlipAreaVertical');
    this._lMenuFlipAreaFlip = $get('lMenuFlipAreaFlip');
    this._allMenuItems = new MindTheGap.Web.UI.Helpers.Hashtable();
   
    this._selectedMenuItem = null;
    this._itemsLoaded = false;
    this._currentLanguage = 'it';
    this._openCloseWithMovement = false;
    this._postBackFunction = null;
    //The .NET control ID
    this._menuControlId = null;
    
    this._clientMenuContext = sContextName!=null ? menuContexts.get(sContextName) : 'Home';
    this._useText = bUseText!=null ? bUseText : false;
    this._fontName = sFontName!=null ? sFontName : (this._useText ? 'Arial' : 'SWZLIGHN.TTF');
    this._initialFontSize = iInitialFontSize != null ? iInitialFontSize : 30;
    this._fontSizeDecrement =  iFontSizeDecrement != null ? iFontSizeDecrement : 10;
    this._menuTimeout = iMenuTimeout != null ? iMenuTimeout : 4;
    this._sImageFormat = sImageFormat!=null ? sImageFormat : 'Png';
    this._useTransparentImages = bUseTransparentImages != null ? bUseTransparentImages :false;
    this._drawFlip = bDrawFlip != null ? bDrawFlip : true;
    
    this._zIndex = iZindex != null ? iZindex : 100;
    this._top = iTop != null ? iTop : 0;
    this._left = iLeft != null ? iLeft : 0;
    this._padLeft = 20;
    this._padRight = 20;
    this._padTop = 0;
    this._padBottom = 0;

    /* Images for scroller */
    this._scrollArrowPrefix = '/Resources/Img/Icons/';
    this._nightUpUnselected = 'upLarge_G_B.jpg';
    this._nightUpSelected = 'upLarge_W_B.jpg';
    this._nightDownUnselected = 'downLarge_G_B.jpg';
    this._nightDownSelected = 'downLarge_W_B.jpg';

    this._dayUpUnselected = 'upLarge_G_W.jpg';
    this._dayUpSelected = 'upLarge_B_W.jpg';
    this._dayDownUnselected = 'downLarge_G_W.jpg';
    this._dayDownSelected = 'downLarge_B_W.jpg';

    /* Menu Scroller elements */
    this._scrollableArea = $get('lMenuScrollableArea'); 
    this._scrollableContent = $get('lMenuContentsInner'); 
    this._upArrowArea = $get('lMenuScrollTop'); 
    this._downArrowArea = $get('lMenuScrollBottom'); 
    this._menuUpImg = $get('menuUpImg');
    this._menuDownImg = $get('menuDownImg');
    this._currentOffset = 0;
    //this._offset = 113;
    this._scrollupTimer = null;
    this._scrolldownTimer = null;
    
}
MindTheGap.Stonehenge.Web.UI.Menus.ClientMenu.prototype =
{
    _offset: function() {
        return GlobalHelper.FindOffsetTop(myMenu._lMenuContainer) * 2 + 100;
    },
    preloadImages: function() {
        for (i = 0; i < this._allMenuItems._count; i++) {
            this._allMenuItems.getAt(i).preloadImages();
        }
    },
    loadMenuItems: function(arrClientMenuItem) {
        if (arrClientMenuItem != null) {
            for (i = 0; i < arrClientMenuItem.length; i++) {
                var item = new MindTheGap.Stonehenge.Web.UI.Menus.MenuItem(this, arrClientMenuItem[i]);
            }
            this._itemsLoaded = true;
            $addHandler(window, 'load', PreloadImages);
        }
    },
    renderMenuItems: function(sLanguage) {
        if (sLanguage != null && sLanguage != '')
            this._currentLanguage = sLanguage;

        if (this._itemsLoaded) {
            for (i = 0; i < this._allMenuItems._keys.length; i++)
                this._allMenuItems.getAt(i).render(this._currentLanguage);
        }
    },
    setSelectedMenuItem: function(sMenuItemId) {
        var menuItem = this._allMenuItems.get(sMenuItemId);
        if (menuItem != null) {

            menuItem.toggle();
            var tgt = menuItem._clientMenuItem.TargetViewlet;
            if (tgt != null && tgt != '')
                __doPostBack(this._menuControlId, tgt);
        }
    },
    getObj: function() { return this._lMenuContainer; },
    setContext: function(sContextName, sLanguage) {
        this._clientMenuContext = sContextName != null ? menuContexts.get(sContextName) : (this._clientMenuContext != null ? this._clientMenuContext : menuContexts.get('Home'));
        var ctx = this._clientMenuContext;

        this.setBgColor(this.isClosed() ? ctx.getBorderColor() : ctx.getBackgroundColor());
        this.setTextColor(ctx.getTextColor());
        this.setBorderColor(this.isClosed() ? ctx.getBorderColor() : ctx.getBackgroundColor());
        this.setAlpha(ctx.getAlpha());
        this.menu_UpImageHover();
        this.menu_DownImageHover();
        if (ctx.getRenderInline())
            this.setPositionMode('relative');
        else
            this.setPositionMode('absolute');

        if (ctx.getVisible()) {
            this.renderMenuItems(sLanguage);

            if (ctx.getShowFlip())
                this._lMenuFlipArea.style.display = 'block';
            else
                this._lMenuFlipArea.style.display = 'none';

            this.show();
            if (!ctx.getPerformAnimation())
                this.open();
        }
        else
            this.hide();
        try {
            $removeHandler(this._lMenuContainer, 'mouseover', MenuMouseOver);

        }
        catch (ex) { }
        try {

            $removeHandler(this._lMenuContainer, 'mouseout', MenuMouseOut);
        }
        catch (ex) { }
        if (ctx.getPerformAnimation()) {
            $addHandler(this._lMenuContainer, 'mouseover', MenuMouseOver);
            $addHandler(this._lMenuContainer, 'mouseout', MenuMouseOut);
        }
    },
    setLocation: function(iLeft, iTop) {
        Sys.UI.DomElement.setLocation(this._lMenuContainer, iLeft, iTop);

    },
    setZIndex: function(iIndex) { this._lMenuContainer.style.zIndex = iIndex; },
    setPadding: function(iLeftPadding, iRightPadding, iTopPadding, iBottomPadding) {
        this._lMenuContentsInner.style.paddingLeft = iLeftPadding + 'px';
        this._lMenuContentsInner.style.paddingRight = iRightPadding + 'px';
        this._lMenuContentsInner.style.paddingTop = iTopPadding + 'px';
        this._lMenuContentsInner.style.paddingBottom = iBottomPadding + 'px';
    },
    setPositionMode: function(sPositionMode) { this._lMenuContainer.style.position = sPositionMode; },
    drawFlip: function(sColor) {
        var jg = new jsGraphics(this._lMenuFlipAreaFlip);
        jg.clear();
        jg.setColor(sColor);
        jg.setStroke(1);
        jg.fillArc(-10, 0, 20, 20, 0, 90);
        jg.fillRect(0, 10, 10, 100);
        jg.fillArc(-10, 100, 20, 20, 270, 360);
        jg.paint();
    },
    setBgColor: function(sColor) {
        this._lMenuContents.style.backgroundColor = sColor;
        this._lMenuContentsInner.style.backgroundColor = sColor;
        this._lMenuFlipAreaVertical.style.backgroundColor = sColor;

        if (this._drawFlip) {
            this._lMenuFlipAreaFlip.style.backgroundColor = 'Transparent';
            this.drawFlip(sColor);

        }
        else {
            var jg = new jsGraphics(this._lMenuFlipAreaFlip);
            jg.clear();
            this._lMenuFlipAreaFlip.style.backgroundColor = sColor;
        }
    },
    setTextColor: function(sColor) {
        this._lMenuContainer.style.color = sColor;
    },
    setSelectedTextColor: function(sColor) {

    },
    setBorderColor: function(sColor) {

        if (sColor != null && sColor != '') {
            this._lMenuFlipAreaVertical.style.borderRight = 'solid 1px ' + sColor;

            if (this._drawFlip) {
                this._lMenuFlipAreaFlip.style.borderRight = 'none';
                this._lMenuFlipAreaFlip.style.borderTop = 'none';
                this._lMenuFlipAreaFlip.style.borderBottom = 'none';
            }
            else {
                this._lMenuFlipAreaFlip.style.borderRight = 'solid 1px ' + sColor;
                this._lMenuFlipAreaFlip.style.borderTop = 'solid 1px ' + sColor;
                this._lMenuFlipAreaFlip.style.borderBottom = 'solid 1px ' + sColor;
            }


        }
        else {
            this._lMenuFlipAreaVertical.style.borderRight = 'none';
            this._lMenuFlipAreaFlip.style.borderRight = 'none';
            this._lMenuFlipAreaFlip.style.borderTop = 'none';
            this._lMenuFlipAreaFlip.style.borderBottom = 'none';
        }
    },
    setAlpha: function(iAlpha) {
        var object = this._lMenuContainer.style;
        if (iAlpha < 100) {
            object.opacity = (iAlpha / 100);
            object.MozOpacity = (iAlpha / 100);
            object.KhtmlOpacity = (iAlpha / 100);
            object.filter = "alpha(opacity=" + iAlpha + ")";
        }
        else {
            object.opacity = null;
            object.MozOpacity = null;
            object.KhtmlOpacity = null;
            object.filter = null;
        }
    },
    show: function() {
        this._lMenuContainer.style.display = 'block';
    },
    hide: function() {
        this._lMenuContainer.style.display = 'none';
    },
    isClosed: function() {
        return this._lMenuContents.style.width == '0px';
    },
    close: function() {
        if (!this._openCloseWithMovement) {
            this._lMenuContents.style.overflow = 'hidden';
            this._lMenuContents.style.width = '0px';
            this.setBgColor(this._clientMenuContext.getBorderColor());
            this.setBorderColor(this._clientMenuContext.getBorderColor());
            this.setAlpha(100);
        }
        else {
        }
    },
    open: function() {
        if (!this._openCloseWithMovement) {
            this.setBgColor(this._clientMenuContext.getBackgroundColor());
            this.setBorderColor(this._clientMenuContext.getBackgroundColor());
            this._lMenuContents.style.width = null; //this._lMenuContentsInner.offsetWidth+'px';
            this.setAlpha(this._clientMenuContext.getAlpha());
            this._lMenuContents.style.overflow = 'visible';

        }
        else {
        }
    },
    init: function(sContextName, sLanguage, fnPostbackFunction) {
        this.setLocation(this._left, this._top);
        this.setZIndex(this._zIndex);
        this.setPadding(this._padLeft, this._padRight, this._padTop, this._padBottom);
        this._postBackFunction = fnPostbackFunction;
        this.setContext(sContextName, sLanguage);
    },
    /* Menu Scrollin Methods */
    menu_IsScrollingCondition: function() {
        return this._scrollableContent.clientHeight > this._scrollableArea.clientHeight;
    },
    menu_ShowTopScrolling: function() {
        return this.menu_IsScrollingCondition() && (-this._scrollableContent.style.top < (this._scrollableContent.clientHeight - this._scrollableArea.clientHeight));
    },
    menu_ShowBottomScrolling: function() {
        return this.menu_IsScrollingCondition() && this._scrollableContent.style.top < 0;
    },
    menu_SetArrowsVisibility: function() {
        if (this.menu_IsScrollingCondition()) {
            if ((this._scrollableArea.clientHeight - (this._currentOffset - 2)) <= this._scrollableContent.clientHeight)
                this._downArrowArea.style.visibility = 'visible';
            else {
                this._downArrowArea.style.visibility = 'hidden';
                this.menu_StopScrollDown();
            }

            if (this._currentOffset + 2 <= 0)
                this._upArrowArea.style.visibility = 'visible';
            else {
                this._upArrowArea.style.visibility = 'hidden';
                this.menu_StopScrollUp();
            }
        }
        else {
            this._downArrowArea.style.visibility = 'hidden';
            this._upArrowArea.style.visibility = 'hidden';
        }

    },
    menu_InitMenuScroll: function() {
        this.menu_HandleResize();
        try {
            $removeHandler(window, 'resize', myMenu.menu_HandleResize);
        }
        catch (e) { }
        $addHandler(window, 'resize', myMenu.menu_HandleResize);
    },

    menu_HandleResize: function() {

        if (document.body.clientHeight <= 0 || document.body.clientHeight - myMenu._offset() <= 0)
            return;
        myMenu._scrollableArea.style.height = (document.body.clientHeight - myMenu._offset()) + 'px';
        if (!myMenu.menu_IsScrollingCondition()) {
            myMenu._scrollableContent.style.marginTop = '0px';
            this._currentOffset = 0;
        }
        else {
            //If down arrow is not visible, we might have a hole at the bottom
            if ((myMenu._scrollableArea.clientHeight - (myMenu._currentOffset - 2)) > myMenu._scrollableContent.clientHeight) {
                myMenu._currentOffset = Math.max(myMenu._currentOffset, myMenu._scrollableContent.clientHeight - myMenu._scrollableArea.clientHeight);
                myMenu._scrollableContent.style.marginTop = myMenu._currentOffset + 'px';
            }

            if (this._currentOffset > 0) {
                myMenu._scrollableContent.style.marginTop = '0px';
                myMenu._currentOffset = 0;
            }
        }

        myMenu.menu_SetArrowsVisibility();
    },
    menu_ScrollUp: function() {

        if ((myMenu._scrollableArea.clientHeight - (myMenu._currentOffset - 2)) <= myMenu._scrollableContent.clientHeight) {
            myMenu._currentOffset = myMenu._currentOffset - 2;
            myMenu._scrollableContent.style.marginTop = myMenu._currentOffset + 'px';
        }
        myMenu.menu_SetArrowsVisibility();

    },
    menu_MouseWheel: function(e) {
        e = e ? e : event;
        var dir = 0;
        if (e.wheelDelta >= 120) dir = 1;
        if (e.wheelDelta <= -120) dir = -1;
        var scrollDelta = 30 * dir;
        if (myMenu.menu_IsScrollingCondition()) {
            if (dir == -1) {
                var maxOffset = myMenu._scrollableArea.clientHeight - myMenu._scrollableContent.clientHeight;
                if (maxOffset < 0) {
                    if (this._currentOffset > maxOffset) {
                        var delta = maxOffset - myMenu._currentOffset;
                        var valid = Math.max(delta, scrollDelta);
                        myMenu._currentOffset = myMenu._currentOffset + valid;
                        myMenu._scrollableContent.style.marginTop = myMenu._currentOffset + 'px';
                    }
                }

            }
            else {
                var valid = Math.min(scrollDelta, -myMenu._currentOffset);
                myMenu._currentOffset = myMenu._currentOffset + valid;
                myMenu._scrollableContent.style.marginTop = myMenu._currentOffset + 'px';
            }
            myMenu.menu_SetArrowsVisibility();


        }
        e.returnValue = false;
    },
    menu_ScrollDown: function() {
        if (myMenu._currentOffset + 2 <= 0) {
            myMenu._currentOffset = myMenu._currentOffset + 2;
            myMenu._scrollableContent.style.marginTop = myMenu._currentOffset + 'px';
        }
        myMenu.menu_SetArrowsVisibility();

    },
    menu_StartScrollUp: function() {

        if (myMenu._scrollupTimer == null) {
            this.menu_StopScrollDown();
            myMenu._scrollupTimer = setInterval(myMenu.menu_ScrollUp, 5);
        }
    },

    menu_StopScrollUp: function() {
        if (myMenu._scrollupTimer != null) {
            clearInterval(myMenu._scrollupTimer);
            myMenu._scrollupTimer = null;
        }
    },

    menu_StartScrollDown: function() {

        if (myMenu._scrolldownTimer == null) {
            this.menu_StopScrollUp();
            myMenu._scrolldownTimer = setInterval(myMenu.menu_ScrollDown, 5);
        }
    },

    menu_StopScrollDown: function() {
        if (myMenu._scrolldownTimer != null) {
            clearInterval(myMenu._scrolldownTimer);
            myMenu._scrolldownTimer = null;
        }
    },
    menu_UpImageHover: function(sStatus) {
        if (this._menuUpImg.nightUpSelected == null) {
            this._menuUpImg.nightUpSelected = new Image();
            this._menuUpImg.nightUpSelected.src = this._scrollArrowPrefix + this._nightUpSelected;
        }
        if (this._menuUpImg.nightUpUnselected == null) {
            this._menuUpImg.nightUpUnselected = new Image();
            this._menuUpImg.nightUpUnselected.src = this._scrollArrowPrefix + this._nightUpUnselected;
        }
        if (this._menuUpImg.dayUpSelected == null) {
            this._menuUpImg.dayUpSelected = new Image();
            this._menuUpImg.dayUpSelected.src = this._scrollArrowPrefix + this._dayUpSelected;
        }
        if (this._menuUpImg.dayUpUnselected == null) {
            this._menuUpImg.dayUpUnselected = new Image();
            this._menuUpImg.dayUpUnselected.src = this._scrollArrowPrefix + this._dayUpUnselected;
        }

        if (this._clientMenuContext == menuContextDay)
            this._menuUpImg.src = ((sStatus == null || sStatus == '' || sStatus == 'out') ? this._menuUpImg.dayUpUnselected.src : this._menuUpImg.dayUpSelected.src);
        else
            this._menuUpImg.src = ((sStatus == null || sStatus == '' || sStatus == 'out') ? this._menuUpImg.nightUpUnselected.src : this._menuUpImg.nightUpSelected.src);
    },
    menu_DownImageHover: function(sStatus) {
        if (this._menuDownImg.nightDownSelected == null) {
            this._menuDownImg.nightDownSelected = new Image();
            this._menuDownImg.nightDownSelected.src = this._scrollArrowPrefix + this._nightDownSelected;
        }
        if (this._menuDownImg.nightDownUnselected == null) {
            this._menuDownImg.nightDownUnselected = new Image();
            this._menuDownImg.nightDownUnselected.src = this._scrollArrowPrefix + this._nightDownUnselected;
        }
        if (this._menuDownImg.dayDownSelected == null) {
            this._menuDownImg.dayDownSelected = new Image();
            this._menuDownImg.dayDownSelected.src = this._scrollArrowPrefix + this._dayDownSelected;
        }
        if (this._menuDownImg.dayDownUnselected == null) {
            this._menuDownImg.dayDownUnselected = new Image();
            this._menuDownImg.dayDownUnselected.src = this._scrollArrowPrefix + this._dayDownUnselected;
        }

        if (this._clientMenuContext == menuContextDay)
            this._menuDownImg.src = ((sStatus == null || sStatus == '' || sStatus == 'out') ? this._menuDownImg.dayDownUnselected.src : this._menuDownImg.dayDownSelected.src);
        else
            this._menuDownImg.src = ((sStatus == null || sStatus == '' || sStatus == 'out') ? this._menuDownImg.nightDownUnselected.src : this._menuDownImg.nightDownSelected.src);

    }
}
MindTheGap.Stonehenge.Web.UI.Menus.ClientMenu.registerClass('MindTheGap.Stonehenge.Web.UI.Menus.ClientMenu', null, Sys.IDisposable); 


MindTheGap.Stonehenge.Web.UI.Menus.MenuItem = function(objMenu, objClientMenuItem)
{
    this._menu = objMenu;
    this._clientMenuItem = objClientMenuItem;
    this._menu._allMenuItems.put(this._clientMenuItem.Id,this);
    this._itemAdded = false;
  
    
    this._menuItemDiv = document.createElement("DIV");
    this._menuTextDiv =  document.createElement("DIV");
    this._menuChildrenDiv =  document.createElement("DIV");
    
    this._menuChildrenDiv.style.display = 'none';
    //this._menuChildrenDiv.style.overflow = 'hidden';
    //this._menuChildrenDiv.style.height = '0px';
    
    this._menuHrefTag = document.createElement("A");
    //this._menuHrefTag.href = 'javascript: void 0;';
    this._menuHrefTag.id = this._clientMenuItem.Id; 
    this._menuHrefTag.style.textDecoration = 'none';
    this._menuHrefTag.style.cursor = 'hand';
    
    $addHandler(this._menuHrefTag,'click',MenuItemClicked);
    $addHandler(this._menuHrefTag,'focus',HideFocus);
    
    this._imgNormal = null;
    this._imgSelected = null;
    this._currentImage = null;
    
    //this._menuTextDiv.id = this._clientMenuItem.Id; 
    //this._children = null;
    
    //$addHandler(this._menuTextDiv,'click',MenuItemClicked);
    this._menuTextDiv.style.paddingBottom = '7px';
    //this._menuTextDiv.style.cursor = 'hand';
    this._menuChildrenDiv.style.paddingLeft = '15px';
    
    
    this._menuTextDiv.appendChild(this._menuHrefTag);
    this._menuItemDiv.appendChild(this._menuTextDiv);
    this._menuItemDiv.appendChild(this._menuChildrenDiv);
    
 
}
MindTheGap.Stonehenge.Web.UI.Menus.MenuItem.prototype =
{
    preloadImages: function() {
        var textSize = this._menu._initialFontSize;
        if (this._clientMenuItem.Level > 0)
            textSize = textSize - this._menu._fontSizeDecrement;

        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('it')) + '&size=' + textSize + '&textcolor=' + escape(menuContextDay.getTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextDay.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('it')) + '&size=' + textSize + '&textcolor=' + escape(menuContextDay.getSelectedTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextDay.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('it')) + '&size=' + textSize + '&textcolor=' + escape(menuContextNight.getTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextNight.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('it')) + '&size=' + textSize + '&textcolor=' + escape(menuContextNight.getSelectedTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextNight.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('en')) + '&size=' + textSize + '&textcolor=' + escape(menuContextDay.getTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextDay.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('en')) + '&size=' + textSize + '&textcolor=' + escape(menuContextDay.getSelectedTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextDay.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('en')) + '&size=' + textSize + '&textcolor=' + escape(menuContextNight.getTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextNight.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
        GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText('en')) + '&size=' + textSize + '&textcolor=' + escape(menuContextNight.getSelectedTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(menuContextNight.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);

    },
    render: function(sLanguage) {

        /* EXCLUDE NODES WITH NO TEXT VALUE */
        if (typeof (this.getText(sLanguage)) == 'undefined' || this.getText(sLanguage) == null || this.getText(sLanguage) == '') {
            this._menuItemDiv.style.display = 'none';
            return;
        }
        else
            this._menuItemDiv.style.display = 'block';

        /* CREATE THE NODE DIV (IF NOT ALREADY CREATED) */
        if (this._menuItemDiv.parentElement == null && !this._itemAdded) {
            if (this.parent() != null)
                this.parent()._menuChildrenDiv.appendChild(this._menuItemDiv);
            else
                this._menu._lMenuContentsInner.appendChild(this._menuItemDiv);

            this._itemAdded = true;
        }

        if (this._menu._useText) {
            this._menuHrefTag.innerText = this.getText(sLanguage);
        }
        else {
            if (this._imgNormal == null) {
                this._imgNormal = new Image();
                this._imgSelected = new Image();
                this._currentImage = new Image();
                this._currentImage.border = 0;

                if (this.usePngPatch())
                    this._menuHrefTag.appendChild(this._currentImage);
                else
                    this._menuHrefTag.appendChild(this._currentImage);
            }
            textSize = this._menu._initialFontSize;
            if (this.level() > 0)
                textSize = textSize - this._menu._fontSizeDecrement;

            this._imgNormal = GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText(sLanguage)) + '&size=' + textSize + '&textcolor=' + escape(this._menu._clientMenuContext.getTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(this._menu._clientMenuContext.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);
            this._imgSelected = GlobalImageManager.GetImage('/GetImageForText.ashx?text=' + (this.getText(sLanguage)) + '&size=' + textSize + '&textcolor=' + escape(this._menu._clientMenuContext.getSelectedTextColor()) + '&font=' + escape(this._menu._fontName) + '&backColor=' + escape(this._menu._clientMenuContext.getBackgroundColor()) + '&transparent=' + this._menu._useTransparentImages + '&cropMode=28&imageFormat=' + this._menu._sImageFormat);

            if (this.isSelected() || (this._menu._selectedMenuItem != null && (this._menu._selectedMenuItem._clientMenuItem.Path.indexOf(this._clientMenuItem.Path) == 0))) {
                this._currentImage.src = this._imgSelected.src;
                // this._currentImage.width = this._imgSelected.width;
                // this._currentImage.height = this._imgSelected.height;
            }
            else {
                this._currentImage.src = this._imgNormal.src;
                //this._currentImage.width = this._imgNormal.width;
                //this._currentImage.height = this._imgNormal.height;
            }
        }
    },
    usePngPatch: function() {
        return (this._menu._sImageFormat.toLowerCase() == 'png' && this._menu._useTransparentImages && Sys.Browser.agent === Sys.Browser.InternetExplorer && Sys.Browser.version < 7);
    },
    toggle: function() {
        if (this.isSelected()) {
            this.hideChildren();
            this._currentImage.src = this._imgSelected.src;
            //this._currentImage.width = this._imgSelected.width;
            //this._currentImage.height = this._imgSelected.height;
            this.parent() != null ? this.parent().toggle() : this._menu._selectedMenuItem = null;
        }
        else {
            if (this._menu._selectedMenuItem != null)
                this._menu._selectedMenuItem.setUnselectedTree(this);

            this.setSelectedTree();
            this._menu._selectedMenuItem = this;

            //if(this.getLinkArgs()!=null && this.getLinkArgs()!='')
            // __doPostBack('Menu',this.getLinkArgs());
        }
        //this._menu.menu_SetArrowsVisibility();
        this._menu.menu_HandleResize();

    },
    setUnselectedTree: function(newSelectedItem) {
        if (newSelectedItem.parent() == null || newSelectedItem.parent() != this) {
            this.hideChildren();
            this._currentImage.src = this._imgNormal.src;
            //this._currentImage.width = this._imgNormal.width;
            //this._currentImage.height = this._imgNormal.height;

            if (this.parent() != null)
                this.parent().setUnselectedTree(newSelectedItem);
        }
    },
    setSelectedTree: function() {
        if (!this.isLeaf())
            this.showChildren();

        this._currentImage.src = this._imgSelected.src;
        //this._currentImage.width = this._imgSelected.width;
        //this._currentImage.height = this._imgSelected.height;

        if (this.parent() != null)
            this.parent().setSelectedTree();
    },
    isLeaf: function() {
        return (this.childrenIds() == null);
    },
    childrenIds: function() {
        if (this._clientMenuItem.Children != null && this._clientMenuItem.Children.length > 0)
            return this._clientMenuItem.Children;
        else
            return null;
    },
    level: function() {
        return this._clientMenuItem.Level;
    },
    hideChildren: function() {
        this._menuChildrenDiv.style.display = 'none';
        //this._menuChildrenDiv.style.height = '0px';
    },
    showChildren: function() {
        this._menuChildrenDiv.style.display = 'block';
        //this._menuChildrenDiv.style.height = null;
    },
    parent: function() {
        if (this._clientMenuItem.Parent == null || this._clientMenuItem.Parent == '')
            return null;
        else
            return this._menu._allMenuItems.get(this._clientMenuItem.Parent);
    },
    isSelected: function() {
        if (this._menu._selectedMenuItem != null && this._menu._selectedMenuItem == this)
            return true;
        else
            return false;
    },
    getText: function(sLanguage) {
        return this._clientMenuItem.Text[sLanguage];
    },
    getLinkArgs: function() {
        return this._clientMenuItem.TargetViewlet;
    }
}

var myMenu = null;
function MenuItemClicked(eventElement)
{
    if(eventElement!=null)
    {
        if(eventElement.target.tagName=='IMG')
            myMenu.setSelectedMenuItem(eventElement.target.parentNode.id);
        else  if(eventElement.target.tagName=='A') 
            myMenu.setSelectedMenuItem(eventElement.target.id);
        else  if(eventElement.target.tagName=='DIV') 
            myMenu.setSelectedMenuItem(eventElement.target.firstChild.id); 
    }
}
function HideFocus(eventElement)
{
    eventElement.target.hideFocus=true;
}

var tOutId = null;
function MenuMouseOver()
{
    if(tOutId!=null)
    {
        window.clearTimeout(tOutId);
        tOutId = null;
    }
    myMenu.open();
}
function MenuMouseOut()
{
    tOutId = window.setTimeout(DoClose,myMenu._menuTimeout*1000);
}

function DoClose()
{
    myMenu.close();
}

function InitializeMenu(sMenuControlId)
{
    if(myMenu==null || myMenu._menuControlId==null)
    {
        myMenu = new MindTheGap.Stonehenge.Web.UI.Menus.ClientMenu();
        myMenu._menuControlId = sMenuControlId;
        ClientSideMenu.GetMenu(MenuItemsLoaded);
        myMenu.menu_InitMenuScroll();
    }
}
 function MenuItemsLoaded(result)
    {
        var items = eval(result);
        myMenu.loadMenuItems(items);

	if(menuRequiredContext==null)
        	myMenu.init('Home','it');
	else
	{
		myMenu.init(menuRequiredContext,menuRequiredLanguage );
		menuRequiredContext = null;
		menuRequiredLanguage = null;
	}
      
       
    /*
        var items = eval(result);
        var myDiv = $get('test');
        for(i=0; i<items.length; i++)
        {
            var oDiv=document.createElement("DIV");
            oDiv.innerText = items[i].Text['it'];
            myDiv.appendChild(oDiv);
        }*/
    }

var menuRequiredContext = null;
var menuRequiredLanguage = null;
    
function DoMenuContextChange(sNewContext,sLanguage)
{
    if(myMenu!=null)
        myMenu.setContext(sNewContext,sLanguage);
    else
{
	menuRequiredContext = sNewContext;
	menuRequiredLanguage = sLanguage;
}
}

function PreloadImages()
{
     window.setTimeout(PreloadImages2,20);
}
function PreloadImages2()
{
     if(myMenu!=null)
       myMenu.preloadImages();
}
    
// finalmente registriamo la classe appartenente al namespace
MindTheGap.Stonehenge.Web.UI.Menus.MenuItem.registerClass('MindTheGap.Stonehenge.Web.UI.Menus.MenuItem', null, Sys.IDisposable); 

if (typeof(Sys) !== 'undefined') 
    Sys.Application.notifyScriptLoaded(); 


    
    
