$(document).ready(function() {

    // Highlight current page; HACK: for main section items with sub items.
    $("a[href=" + location.pathname + "]").addClass("current-page");
    $("#sectionNav li ul").hide();
    $("#sectionNav li>a.current-page").parent().children("ul").show();

    //Setup main menu
    $("#main LI>SPAN").click(function() {
        var data = this;


        $("#main LI>SPAN").each(function() {
            if (this != data) {
                $(this).next().hide();
                $(this).parent().removeClass("active");
            }
        });

        // Toggle the menu
        $(this).next().toggle();
        $(this).parent().toggleClass("hover");

        // hide the select list
        if ($(this).next().css("display") == "block" && $(this).parent().hasClass("first-nav-item")) {
            $("#ctl00_TripPlanner_ddlSchedule").css("visibility", "hidden");
        }
        else { $("#ctl00_TripPlanner_ddlSchedule").css("visibility", "visible"); }



        //Make sure the LI keeps the active class
        if ($(this).parent().hasClass("active") == false) {
            $(this).parent().addClass("active");

        }
    });

    //    // Click anywhere, except the main menu, to close the main menu
    //    $("body *").click(function(){
    //        if($("DIV").index(this) != 1 && $("DIV").index(this) != -1){
    //            $("#main LI SPAN").each(function(){
    //                $(this).next().hide();
    //                $(this).parent().removeClass("active");
    //            });
    //        }
    //    });
    //    

    $('#main LI>SPAN').hover(
	    function() {
	        if ($(this).next().css("display") != "block") {
	            $(this).parent().addClass("hover");
	            $(this).parent().addClass("active");
	            $(this).addClass("hover-arrow");
	        }
	    },
	    function() {
	        if ($(this).next().css("display") != "block") {
	            $(this).parent().removeClass("hover");
	            $(this).parent().removeClass("active");
	            $(this).removeClass("hover-arrow");
	        }
	    }
	 );

    $('#main LI>a').hover(
       function() {
           if ($(this).parent().hasClass("hover") == false) {
               $(this).parent().addClass("hover");
           }
       },
       function() {
           $(this).parent().removeClass("hover");
       }
    );

    $("table.timetable tbody tr:odd").addClass("even");
    $("table.content-table tr:odd").addClass("even");

    $('#ankle').equalHeights();

    $(".iform .routelist a").unbind();
    $(".iform .routelist a").click(function(event) {
        var routes = "|";
        event.preventDefault();
        route = $(this).attr("id");
        $(this).toggleClass("selected");
        $(".iform .routelist a.selected").each(function() {
            routes = routes + $(this).attr("id") + "|";
        });
        $("#ctl00_LeadContent_RiderInsiderSignUp1_routes").val(routes);

    });


    $('#main li>a').focus(function(e) {
        $(this).next("span").click();
    });

    $('#main li a').blur(function(e) {
        if (!$(this).parent().hasClass("active")) {
            $(this).parent().removeClass("hover");
            $(this).parent().removeClass("active");
            //$("#ctl00_TripPlanner_ddlSchedule").css("visibility", "visible");

        } else {
            $(this).parent().removeClass("hover");
            //$("#ctl00_TripPlanner_ddlSchedule").css("visibility", "visible");
        }
    });

    $('#container>div a').focus(function(e) {
        $("#main li").removeClass("active");
        $("#main li").removeClass("hover");
        $("#main li div").hide();
        $("#ctl00_TripPlanner_ddlSchedule").css("visibility", "visible");
    });

    $('#container>div input').focus(function(e) {
        $("#main li").removeClass("active");
        $("#main li").removeClass("hover");
        $("#main li div").hide();
        $("#ctl00_TripPlanner_ddlSchedule").css("visibility", "visible");
    });

});          //End $(document).ready



	/*-------------------------------------------------------------------- 
	 * JQuery Plugin: "EqualHeights"
	 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
	 *
	 * Copyright (c) 2008 Filament Group
	 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
	 *
	 * Description: Compares the heights or widths of the top-level children of a provided element 
	 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
	 		by default if pxToEm() method is available.
	 * Dependencies: jQuery library, pxToEm method	(article: 
			http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
	 * Usage Example: $(element).equalHeights();
	  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
	 * Version: 2.0, 08.01.2008
	--------------------------------------------------------------------*/

	$.fn.equalHeights = function(px) {
		$(this).each(function(){
			var currentTallest = 0;
			$(this).children().each(function(i){
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			});
		//	if (!px || !Number.prototype.toEm) currentTallest = currentTallest.toEm(); //use ems unless px is specified
			// for ie6, set height since min-height isn't supported
			if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
			$(this).children().css({'min-height': currentTallest}); 
		});
		return this;
	};


