﻿var toggleTime = 200; // not like hammer time

$(document).ready(function() {

    $(".sideNav > .item > .element > ul > li > a").attr("href", "#");

    // Set the secondary category titles
    $(".sideNav > .item .element > ul > li > a").click(function() {
        $(this).siblings("ul").toggle(toggleTime);
        return false;
    });
    hideAllClosed();
    addTopAfterOpen();
    
    // Highlight the current selected item
    $(".sideNav > .item .element ul li ul li a.subItemSelected").css({ color: "#619EDD" }); 

    

});                       // END ready()



// Get the next ".sideNav.light .item .title" and toggle it's "top" state.
// Used to add the "top" class to the nav item that appears after an open element.
function addTopAfterOpen() {
    var element = $(".sideNav > .item .element.open");
    var nextItem = element.parent().next(".sideNav > .item");
    var nextItemTitle = nextItem.children(".title");
    toggleTopForNextTitle(nextItemTitle);
}





// Used by ProductLeftNav.cs code behind to add nav toggle.
var productNavHelper = {
    // Add javascript call to secondary category titles
    togglePrimaryCategoryTitle: function(index, menuColor, topMenuSize) {
        var navItem = $(".sideNav .item .title:eq(" + index + ")");
        navItem.siblings(".element").toggle(toggleTime);

        //alert(index);
        if (menuColor == "light") {
            var nextIndex = index + 1;
            toggleTopForNextTitle(".sideNav.light .item .title:eq(" + nextIndex + ")");
        } else {
            var nextIndex = (index - topMenuSize) + 1;
            //alert(bottomIndex);
            toggleTopForNextTitle(".sideNav.dark .item .title:eq(" + nextIndex + ")");
        }
    }
}


// Adds and removes "top" class to switch title image.
function toggleTopForNextTitle(navItem) {
    //alert(navItem);
    // change the background image of the next item

    if ($(navItem).hasClass("top")) {
        $(navItem).delay(toggleTime, function() { // delay removal of top for a nicer transition.
            $(navItem).removeClass("top");
        })
    } else {
        $(navItem).addClass("top");
    }
}