﻿
var openNav = "";
var closeNavTimeout=0
function closeNav() {
    var t = $(openNav);
    t.find("ul").stop(true).animate({ height: t.data("smallHeight") }, 400);
    t.find("a.moreLink").stop(true).animate({ opacity: 1 }, 400);
}
$(document).ready(function (e) {
    $("#header nav").css({ opacity: 0 });
});
$(window).load(function (e) {

    $("#header nav").css({ opacity: 1 });
    $("#brandsNav, #categoriesNav").each(function () {

        var normalHeight = $(this).find("ul").height();
        var smallHeight = $(this).find("h2").height()
        $(this).data("normalHeight", normalHeight);
        
        $(this).data("smallHeight", smallHeight);
        var mm = function () {
            clearTimeout(closeNavTimeout);
            $(document).unbind("mousemove", mm);
        }
        /*
        if (location.hash == "#b" && $(this).attr("id") == "brandsNav") {
            $(this).find("a.moreLink").css({ opacity: 0 });
            location.hash = "";
            openNav = "#brandsNav"
            closeNavTimeout = setTimeout("closeNav()", 1000);
            $(document).bind("mousemove", mm);
        } else if (location.hash == "#c" && $(this).attr("id") == "categoriesNav") {
            $(this).find("a.moreLink").css({ opacity: 0 });
            location.hash = "";
            openNav = "#categoriesNav"
            closeNavTimeout = setTimeout("closeNav()", 1000);
            $(document).bind("mousemove", mm);
        } else {
            $(this).find("ul").height(smallHeight);
        }*/
        $(this).find("ul").height(smallHeight);
    });
    $("#brandsNav a").not(".moreLink").each(function () {
        $(this).attr("href", $(this).attr("href") + "#b");
    });
    $("#categoriesNav a").not(".moreLink").each(function () {
        $(this).attr("href", $(this).attr("href") + "#c");
    });
    $("#brandsNav, #categoriesNav").each(function () {
        $(this).hover(function () {
            $(this).find("ul").stop(true).animate({ height: $(this).data("normalHeight") }, 300);
            $(this).find("a.moreLink").stop(true).animate({ opacity: 0 }, 300);
        }, function () {

            $(this).find("ul").stop(true).animate({ height: $(this).data("smallHeight") }, 400);
            $(this).find("a.moreLink").stop(true).animate({ opacity: 1 }, 400);
        });
    });



});


$(document).ready(function () { $.ga.load(GoogleTrackingId); });
