$(document).ready(function() {

    /*COLLAPSE SECONDARY MENU ITEMS*/
    $("div#content.eventListing ul.sideNavbar li ul").slideUp();
    $("div#content.eventListing ul.sideNavbar li a").click(function() {
        $(this).parent("li").children("ul").toggle("slow");
    });


    /*REARRANGE FEATURE VIDEO STRUCTURE FOR SCROLLING*/
    $("#featureVideoWrapper").css("height", "160px").css("overflow", "visible");
    $("div.overlapPadding").css("height", "160px").css("overflow", "hidden").css("position", "absolute");

    $("div#featureVideoWrapper div.featureBoxWide").css("height", "160px").css("overflow", "hidden");
    $("div#featureVideoWrapper div.featureBoxWide").css("background-color", "transparent");
    $("div#featureVideoWrapper div.featureBoxWide").css("background-image", "url(\"/_layouts/images/rwcnavy/bgFeatureContent.gif\")");
    $("div#featureVideoWrapper div.featureBoxWide").css("background-repeat", "repeat-x");
    $("div#featureVideoWrapper div.featureBoxWide").css("background-position", "30px 0px");

    $("div.featureFooterWide").css("background-color", "transparent");
    $("div.featureFooterWide").css("background-image", "url(\"/_layouts/images/rwcnavy/bgFeatureFooterWide.gif\")");
    $("div.featureFooterWide").css("background-repeat", "no-repeat");

    $("div.featureVideo").css("margin-left", "30px");

    $("div#featureVideoWrapper div.featureBoxContentWide").css("height", "91px").css("overflow", "hidden");
    $("div#featureVideoWrapper div.featureBoxContentWide").css("border-left-color", "#d0d8dc");
    $("div#featureVideoWrapper div.featureBoxContentWide").css("border-right-color", "#d0d8dc");

    $("div#featureVideoWrapper #videoScrollWrapper").css("height", "94px").css("overflow", "hidden").css("position", "absolute").css("width", "5000px");
    $("a#prevVideo").css("display", "block");
    $("a#nextVideo").css("display", "block");

    /*SET DEFAULT SCROLLER POSITION*/
    $("div#videoScrollWrapper").css("left", "0px");

    /*SCROLLER ACTIONS*/
    var numVids = $("div#videoScrollWrapper").children().size();
    var upperBound = 0;
    var lowerBound = numVids * -330 + 660; //number of vids negative times the width of the vid plus the width of two vids (for the end)
    var voidBound = numVids * -330;

    $("a#prevVideo").mousedown(function() {

        var vswLeft = $("div#videoScrollWrapper").css("left");
        var vswLeft = vswLeft.substring(0, vswLeft.indexOf("px"));

        if (vswLeft > upperBound) {
            /*alert("resetting");*/
            $("div#videoScrollWrapper").css("left", "0px")
        }
        else if (vswLeft < upperBound) {
            /*alert("animating prev");*/
            $("div#videoScrollWrapper").animate({
                left: "+=330px"
            }, 800, "swing");
        }
    });
    $("a#nextVideo").mousedown(function() {

        var vswLeft = $("div#videoScrollWrapper").css("left");
        var vswLeft = vswLeft.substring(0, vswLeft.indexOf("px"));

        if (vswLeft < voidBound) {
            /*alert("resetting");*/
            $("div#videoScrollWrapper").css("left", "0px")
        }
        else if (vswLeft > lowerBound) {
            /*alert("animating next");*/
            $("div#videoScrollWrapper").animate({
                left: "-=330px"
            }, 800, "swing");
        }
    });

    /*REGION LIST*/
    $("div.regionWrapper").addClass("collapsed");

    $("div.regionWrapper").click(function() {
        if ($(this).hasClass("collapsed")) {
            $(this).removeClass("collapsed").addClass("expanded");
            $(this.id + " div.regionInfo").css("display", "block");
        }
        else {
            $(this).removeClass("expanded").addClass("collapsed");
            $(this.id + " div.regionInfo").css("display", "none");
        }
    })

    /*EXPAND/COLLAPSE ALL REGIONS*/
    $(".expandCollapse").addClass("expandAll");
    $(".expandCollapse").click(function() {
        if ($(this).hasClass("expandAll")) {
            $(this).removeClass("expandAll").addClass("collapseAll").text("Collapse All");
            $("div.regionWrapper").removeClass("collapsed").addClass("expanded");
        }
        else {
            $(this).removeClass("collapseAll").addClass("expandAll").text("Expand All");
            $("div.regionWrapper").removeClass("expanded").addClass("collapsed");
        }
    })

    /*SWITCH BETWEEN LIST VIEW AND MAP VIEW*/
    $("div.listView").hide();
    $("ul#viewSelector li#viewList a").click(function() {
        $(this).addClass("current");
        $("ul#viewSelector li#viewMap a").removeClass("current");
        $("div.mapView").hide();
        $("div.listView").show();

    })
    $("ul#viewSelector li#viewMap a").click(function() {
        $(this).addClass("current");
        $("ul#viewSelector li#viewList a").removeClass("current");
        $("div.mapView").show();
        $("div.listView").hide();
    })

    /*MAP REGION HIGHLIGHTING AND DISPLAY*/
    function removeDetails() {
        $("div.mapDetails div").hide();
    }
    function removeLabels() {
        $("div#mapRegionHighlight div").removeClass();
        $("div#mapRegionLabel div").removeClass();
    }
    function isNotIE6() {
        return !($.browser.msie && $.browser.version <= 6);
    }

    removeLabels();
    removeDetails();

    $("area.mapArea").hover(function() {
        /*if (isNotIE6()) {*/
        $("div#mapRegionHighlight div").removeClass().addClass(this.id);
        $("div#mapRegionLabel div").removeClass().addClass(this.id);
        /*}*/
    }, function() {
        /*if (isNotIE6()) {*/
        removeLabels();
        /*}*/
    }).click(function() {
        removeDetails();
        $("#" + this.id + "Details").show();
    });

    $("div.mapView").css("background", "transparent url(/_layouts/images/rwcnavy/bgMapView.gif) no-repeat");
    $("div.mapFooter").show();
    $("ul#viewSelector").show();
    $("a.expandCollapse").css("display", "block");

    /*DEPLOYMENT MAP DIV TWEAKS*/
    /*$("div.gmnoprint").css("border", "2px red solid !important");*/

    /*TWEAK SIDENAV BULLETS*/
    //alert("!");
    $("ul.sideNavbar li.selected:has(ul) a").css("background-image", "none");
});
