﻿var hoverClass = "AspNet-Menu-Hover";

function Hover__AspNetMenu(element)
{
    AddClass__CssFriendlyAdapters(element, hoverClass);
}

function Unhover__AspNetMenu(element)
{
    RemoveClass__CssFriendlyAdapters(element, hoverClass);
}

/*********************************************************
** MenuImage - page related functions
*********************************************************/

MenuImageBase = function()
{
    this.Image = new Array();
}
MenuImageBase.prototype = {
    init : function()
    {
        this.attachEvents();
    },
    attachEvents : function()
    {
        var UL = document.getElementsByTagName('ul');
        if ( UL.length > 0 )
        {
            for ( var i = 0; i < UL.length; i ++ )
            {
                if ( UL[i].className == 'AspNet-Menu' )
                {
                    var LI = UL[i].getElementsByTagName('li');
                    for ( var j = 0; j < LI.length; j ++ )
                    {
                        var img = LI[j].getElementsByTagName('img');
                        if ( ( img.length > 0 ) && ( img[0].src.indexOf('_selected_') == -1 ) )
                        {
                            // Figure out the hover src
                            var end = img[0].src.substring( img[0].src.lastIndexOf('_'), img[0].src.length );
                            var hover = img[0].src.replace( end, '_hover' + end ); // store the rollover src
                            
                            // Preload the image
                            var preload = new Image();
                            preload.src = hover;
                            
                            // Set the id
                            img[0].id = 'MenuItemImage-' + j;
                            
                            // Save the id, src and hover src
                            this.Image[img[0].id] = new Array( img[0].src, hover );
                            
                            // Attach the events
                            img[0].onmouseover = function()
                            {
                                this.src = MenuImage.Image[ this.id ][1];
                            }
                            img[0].onmouseout = function()
                            {
                                this.src = MenuImage.Image[ this.id ][0];
                            }
                        }
                    }
                }
            }
        }
    }
}

var MenuImage = new MenuImageBase();

