﻿// Create namespace if it does not exist
AWS = window.AWS || {};
/*  
LeftNav Module will accept a params object passed on creation with 3 options
expandSpeed(string): "slow", "normal", "fast" for speed of expansion
expandDelay(int): milliseconds of mouseover before menu expands
collapseDelay(int): milliseconds after mouse leaves menu area before collasping back to normal state
*/
AWS.LeftNav = function(params) {
    params = params || {};
    var EXPAND_SPEED = params.expandSpeed || "normal";
    var EXPAND_DELAY = parseInt(params.expandDelay, 10) || 500;
    var COLLAPSE_DELAY = parseInt(params.collapseDelay, 10) || 2000;

    var resetTimer, expandTimer;
    var resetLeftNav = function(speed) {
        if (jQuery(".leftNavArrowListItem").parent().hasClass("leftNavLevel3")) {
            jQuery(".leftNavLevel2 > li > a").find("+ ul").not(jQuery(".leftNavArrowListItem").parent()).hide(speed);
        }
        else {
            jQuery(".leftNavLevel2 > li > a").find("+ ul").not(jQuery(".leftNavArrowListItem > a").find("+ ul")).hide(speed);
        }
    };
    var expandChildList = function(ele) {
        jQuery(ele).find("> a + ul").slideDown(EXPAND_SPEED);
    };
    var init = function() {
        resetLeftNav(0);

        jQuery(".leftNavLevel2 > li").not(".leftNavArrowListItem, > ul .leftNavArrowListItem").hover(
                function() {
                    clearTimeout(resetTimer);
                    var culprit = this;
                    if (jQuery(this).hasClass('leftNavLevel2') || jQuery(this).parent().hasClass('leftNavLevel2')) {
                        expandTimer = setTimeout(function() { expandChildList(culprit); }, EXPAND_DELAY);
                    }
                },
                function() {
                    clearTimeout(expandTimer);
                    resetTimer = setTimeout(function() { resetLeftNav('normal'); }, COLLAPSE_DELAY);
                });
    } ();
};