﻿    $(document).ready(function() {

        $("ul.topnav li a").hover(function() { //hover
            $(this).children('.catdrop').addClass("hoverArrow");
        }, function() { //hover out
            $(this).children('.catdrop').removeClass("hoverArrow");
        });

        $("ul.topnav li .nodropA").hover(function() { //hover
            $(this).children('.nodrop').addClass("hoverNoArrow");
        }, function() { //hover out
            $(this).children('.nodrop').removeClass("hoverNoArrow");
        });

        $("ul.subnav").hover(function() { //hover
            $(this).parent().children('a').children('.catdrop').addClass("hoverArrow");
            $(this).parent().children('a').addClass("mainNavHover");
        }, function() { // hover out
            $(this).parent().children('a').children('.catdrop').removeClass("hoverArrow");
            $(this).parent().children('a').removeClass("mainNavHover");
        });

        // click version

        $("ul.topnav li a .catdrop").click(function() { //When trigger is clicked...
            //Following events are applied to the subnav itself (moving subnav up and down)
            $(this).parent().parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
            var i = 0; // hover out runs twice for some reason - this hides main li element altogether in IE
            $(this).parent().parent().find("ul.subnav").hover(function() {

            }, function() {
                if (i == 0) {
                    $(this).parent().parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
                    i = 0;
                };
                i += 1;
            });

            //Following events are applied to the trigger (Hover events for the trigger)

            return false; // return false to cancel nav

        }
        );

        $("#login").click(function() {            
            $("#loginPanel").slideDown("slow");            
        });

        $("#loginClose").click(function() {
            $("#loginPanel").slideUp("slow");
        });

        $('#terms-modal').colorbox();
        
    });
    