﻿//Show top nav dropdown menu


$(document).ready(function () {
    $("div.DropNavShow").hide();
    NavEnter();
    NavExit();
    DropDownEnter();
    DropDownExit();
    DropHovered();

    //call function that sets the pop up black out to max 
    popUpBlackOut();

    // DropHovered();
});


//Function called when nav div is entered
this.NavEnter = function () {
    $("div.TopNavDiv").mouseenter(function () {
        //Display this top nav drop down. 
        $("div.DropNavShow").stop(false, true);
        //Each top nav has a matching dropdown with the same index number. 
        //Get this top nav index
        var MatchIndex = $("div.TopNavDiv").index(this);

        //Find the matching dropdown
        var targetNavId = $("div.DropNavShow").get(MatchIndex).id;
        var DropLeftPos = $("#" + targetNavId).offset().left;

        if (DropLeftPos == 0) {
            //Get vars for placement function. 
            var TopNavId = $("div.TopNavDiv").get(MatchIndex).id;

            //Need Top Nav left
            var TopNavLeftPos = $("#" + TopNavId).offset().left;
            //Need Top Nav Top
            var TopNavTopPos = $("#" + TopNavId).offset().top;
            //Need Top Nav Height 
            var TopNavHeight = $("#" + TopNavId).height();

            placedrop(targetNavId, TopNavLeftPos, TopNavTopPos, TopNavHeight);
        }

        $("#" + targetNavId).slideDown("slow");
    });
}

//Function called when a dropdown div is left
this.NavExit = function () {
    $("div.TopNavDiv").mouseleave(function () {
       // $("div.DropNavShow").stop(false, true);
        //Hide this top nav drop down. 
        //Each top nav has a matching dropdown with the same index number. 
        //Get this top nav index
        var MatchIndex = $("div.TopNavDiv").index(this);

        //Find the matching dropdown
        var targetNavId = $("div.DropNavShow").get(MatchIndex).id;
        $("#" + targetNavId).slideUp("slow").delay(300);
    });
}


//Function called when the dropdown is entered 
this.DropDownEnter = function () {
    $("div.DropNavShow").mouseenter(function() {
        //Get the targeted dropdown's id
       var MatchIndex = $("div.DropNavShow").index(this);
       //Find the matching dropdown
       var targetNavId = $("div.DropNavShow").get(MatchIndex).id;
       $("#" + targetNavId).stop(true, true);
       $("#" + targetNavId).show();
    });
}

//Function called when the dropdown is left
this.DropDownExit = function () {
    $("div.DropNavShow").mouseleave(function () {
        //Get the targeted dropdown's id
        var MatchIndex = $("div.DropNavShow").index(this);
        //Find the matching dropdown
        var targetNavId = $("div.DropNavShow").get(MatchIndex).id;
        $("#" + targetNavId).slideUp("slow").delay(300);
    });
}


function placedrop(targetNavId, TopNavLeftPos, TopNavTopPos, TopNavHeight) {
    //Set the position for the taget nav
    $("#" + targetNavId).css({ "left": (TopNavLeftPos) + "px", "top": (TopNavTopPos + TopNavHeight) + "px" });
}



//Function called when an dropdown div is hovered
this.DropHovered = function () {
    $("div.TopNavLinkOff").hover(
                        function () {
                            var targetId = this.id;
                            $("#" + targetId).toggleClass("TopNavLinkOff TopNavLinkOn");
                        });
}


//Function to expand the pop up background to 100% of the document height
this.popUpBlackOut = function () {
    $("div.PopContain").height($(document).height());
    $("div.PopContain").width($(document).width());
    $("div.PopContain").offset({ top: 0, left: 0 });

};

////Function called when an dropdown div is hovered
//this.DropHovered = function () {
//    $("div.DropNavShow").hover(
//                        function () {
//                        var MatchIndex = $("div.DropNavShow").index(this);
//                        var targetNavId = $("div.DropNavShow").get(MatchIndex).id;
//                        $("#" + targetNavId).show();
//                        }, function() {
//                        var MatchIndex = $("div.DropNavShow").index(this);
//                        var targetNavId = $("div.DropNavShow").get(MatchIndex).id;
//                        $("#" + targetNavId).hide();
//                        });
//  }

////Function called when an nav div is hovered
//this.NavHovered = function () {
//    $("div.TopNavDiv").hover(
//                function () {
//                    var MatchIndex = $("div.TopNavDiv").index(this);
//                    var targetNavId = $("div.TopNavDiv").get(MatchIndex).id;
//                    var targetDivId = $("div.DropNavShow").get(MatchIndex).id;
//                    var AdjustLeft = $("#" + targetNavId).offset().left;
//                    var AdjustWidth = $("#" + targetNavId).width();
//                    var AdjustTop =  $("#" + targetNavId).offset().top;
//                    var AdjustHeight = $("#" + targetNavId).height();
//                    $("#" + targetDivId).css({"left":(AdjustLeft) + "px", "top":(AdjustTop+AdjustHeight) + "px"});
//                    $("#" + targetDivId).slideToggle();

//                }, function () {
//                    var MatchIndex = $("div.TopNavDiv").index(this);
//                    var targetDivId = $("div.DropNavShow").get(MatchIndex).id;
//                    $("#" + targetDivId).slideToggle();
//                });
//            }


