﻿
var tallestUL = 0;
$(document).ready(function() {

    //equalHeight height columns

    equalHeight($("#SideColContainer #Widgets, #MainColContainer #CenterColContainer .column, #MainColContainer #LeftColContainer .column "));

    //Menu Settings
    var MenuNav = $("#MenuNavContainer");
    var DropDownMenu = $("#MyClone");
    var MenuNavPos = MenuNav.position();
    var MenuNavH = MenuNav.height();
    var DropDownPos = DropDownMenu.position();
    var DropDownIeTop = MenuNav.top + 35;

    DropDownMenu.css('top', MenuNavPos.top + 35);
    DropDownMenu.html(MenuNav.html());

    if ($.browser.msie) {
        DropDownMenu.css('left', MenuNavPos.left + 'px');
    }

    $("#MenuNavContainer > ul > li > ul").remove();
    $('#MyClone > ul > li > a').remove();
    $("#MyClone ul ul:last").addClass("last");
    $("#MyClone > ul > li").each(function(i) {
        $(this).prepend("<div class='menucolor color" + i + "'>&nbsp;</div>");
    });

    equalHeight($("#MyClone ul ul"));

    // append the background color to the "current"  element
    $("#MenuNavContainer > ul > li").each(function(i) {

        if ($(this).hasClass("current") || $(this).hasClass("currentCategory")) {
            $(this).addClass("color" + i)
            $("#ColorBox").addClass("color" + i);
        }
    });


    DropDownMenu.slideUp("slow", function() {
        $(this).css('visibility', "visible");
    });


    //Actions

    $("#mainmenu").hoverIntent(showNav, hideNav);

    function showNav() {

        MenuNav.addClass('header');
        DropDownMenu.height(tallestUL + 15); // the number (15) is computed paddings and margins of #myclone ul
        DropDownMenu.slideDown("slow", function() {
            DropDownMenu.corner("bottom");
        });
    }

    function hideNav() {
        DropDownMenu.stop().slideUp("slow", function() {
            MenuNav.removeClass('header');
        });
        DropDownMenu.css('visibility', "visible");

    }
});




/*for equalheight ul ul*/

function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    tallestUL = tallest;
    group.height(tallest);
}