﻿$(document).ready
(
    function() {

        $('.TopLevelMenu a[rel]').each(function() {
            $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').css("left", $(this).offset().left + 54 + "px");
        });

        $('.TopLevelMenu a').mouseover(function(e) {

            if ($(this).attr('rel')) {
                //$('.TopLevelMenu a[rel]').attr("class", "MainMenuItem");
                $('.TopLevelMenu a[rel]').each(
                function(intIndex) {
                    if ($(this).attr('class') != "MainMenuSelected") {
                    $(this).attr("class", "MainMenuItem");
                    }
                }
                );
                $('.BottomMenu div.SubMenuBar[id]').fadeOut('fast');
                $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').fadeIn('fast');
                $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').css("left", $(this).offset().left + 54 + "px");
                $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').css("z-index", "2");
                //$(this).attr("class", "MainMenuItemHover");
                if ($(this).attr('class') != "MainMenuSelected") {
                    $(this).attr("class", "MainMenuItemHover");
                }
            }

            else {
                //$('.TopLevelMenu a[rel]').attr("class", "MainMenuItem");
                $('.TopLevelMenu a[rel]').each(
                function(intIndex) {
                    if ($(this).attr('class') != "MainMenuSelected") {
                        $(this).attr("class", "MainMenuItem");
                    }
                }
                );                
                $('.BottomMenu div.SubMenuBar[id]').fadeOut('fast');
                $('.BottomMenu div.SubMenuBar[id]').css("z-index", "1");
            }
        });

        $('.BottomMenu').mouseleave(function(e) {
        $('.TopLevelMenu a[rel]').each(
                function(intIndex) {
                    if ($(this).attr('class') == "MainMenuSelected") {
                        $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').fadeIn('fast');
                        $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').css("left", $(this).offset().left + 54 + "px");
                        $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').css("z-index", "2");
                    }
                    if ($(this).attr('class') == "MainMenuItemHover") {
                        $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').fadeOut('fast');
                        $('.BottomMenu div.SubMenuBar[id$=' + $(this).attr('rel') + ']').css("z-index", "1");
                        $(this).attr("class", "MainMenuItem");
                    }                    
                }
                );        
        });

        $('.BottomMenu div.SubMenuBar[id]').mouseleave(function(e) {
                //$('.TopLevelMenu a[rel]').attr("class", "MainMenuItem");
                $('.TopLevelMenu a[rel]').each(
                function(intIndex) {
                    if ($(this).attr('class') != "MainMenuSelected") {
                        $(this).attr("class", "MainMenuItem");
                    }
                }
                );            
            $('.BottomMenu div.SubMenuBar[id]').fadeOut('fast');
            $('.BottomMenu div.SubMenuBar[id]').css("z-index", "1");
        });
    }
)    
