$(document).ready(function() {

    $(".marketMenuItem").bind("click", function() {
        //get the market we just clicked on
        $(".bulletOn").hide();
        $(".bulletOff").show();
        var market = $(this).attr("id");
        var marketName = $(this).children("a").html();
        //make all other markets inactive
        $(".marketMenuItem").removeClass("active");
        //make the link they clicked on active so we know what market we're looking at
        $(this).addClass("active")
        $("#bymarket").siblings(".bulletOn").show();
        $("#bymarket").siblings(".bulletOff").hide();
        $(this).children(".bulletOff").hide();
        $(this).children(".bulletOn").show();
        //hide all of the sites
        $(".site").hide();
        //set the header to tell the user what they clicked
        $(".resultHeader").show();
        $(".resultHeader").html(marketName);
        //now show only the results that are in this market
        $("." + market).show();
        return false;
    });

    $("#alphabetical").bind("click", function() {
        //they clicked on the alphabetical listing.
        //make all market links inactive
        $(".marketMenuItem").removeClass("active");
        $(".bulletOn").hide();
        $(".bulletOff").show();
        $(this).siblings(".bulletOn").show();
        $(this).siblings(".bulletOff").hide();
        //shrink the market list if it is open
        //$(".markets").hide();
        $(".resultHeader").hide();
        //Show all of the sites since they were dumped on the page in alphabetical order.
        $(".site").show();
        return false;
    });

    $("#bymarket").bind("click", function() {
        //they clicked on the "show by market" link.
        //Show the subnav.
        $(".marketMenuItem").removeClass("active");
        $(".markets").show();
        $(".bulletOn").hide();
        $(".bulletOff").show();
        $(this).siblings(".bulletOn").show();
        $(this).siblings(".bulletOff").hide();
        
        //make automotive active
        $("#mkt476").children(".bulletOn").show();
        $("#mkt476").children(".bulletOff").hide();
        $("#mkt476").addClass("active")
        //set the header to automotive
        $(".resultHeader").show();
        $(".resultHeader").html($("#mkt476").children("a").html());
        //now show only the results that are in this market
        $(".site").hide();
        $(".mkt476").show();
        return false;
    });
});