jQuery(function($){
    // Hide the Symfony debug toolbar...
    var ms = parseInt($("#sfWebDebugDetails li:eq(5)").text().replace(/\ ms/, ''));
    var db = parseInt($("#sfWebDebugDetails li:eq(6)").text());
    var error = parseInt($("#sfWebDebug:has(.sfWebDebugWarning)").size()) + parseInt($("#sfWebDebug:has(.sfWebDebugError)").size());
    
    if (ms < 750 && db < 10 && error == 0) {
        sfWebDebugToggleMenu();
    }
    
    $("ul").each(function(){
        $(this).children("li:first").addClass('first');
        $(this).children("li:last").addClass('last');
    });
    
    $("#mainNav li").hover(
        function(){
            $(this).addClass('hover');
            $('ul:first',this).css({visibility:'visible'});
        },
        function(){
            $(this).removeClass('hover');
            $('ul:first',this).css({visibility: 'hidden'});
        }
    );
    
    
    $(".shopListColumn a").hover(function(){
        var $this = $(this),
            dotId = $this.attr('id').replace('shopLink-','mapLink-');
        $("#"+dotId).addClass('hover');
    },
    function(){
        var $this = $(this);
        $("#shopMap .hover").removeClass('hover');
    });
    
    $("#shopMap a").hover(function(){
        var $this = $(this),
            shopId = $this.attr('id').replace('mapLink-','shopLink-');
        $("#"+shopId).addClass('hover');
    },
    function(){
        var $this = $(this);
        $("#shopList .hover").removeClass('hover');
    });
    
    $("#shopMap a, .shopListColumn a").click(function(e){
        e.preventDefault();
        var $this = $(this),
            $target = $("#shopData"),
            mapRef = $this.attr('id').split("-")[1];
        $.get('/shop/details/'+mapRef,function(data){
            
            $("#shopList .selected, #shopMap .selected").removeClass('selected');            
            $target.fadeOut('fast',function(){
                $target.empty().html(data).fadeIn('fast');
                $("#shopLink-"+mapRef+", #mapLink-"+mapRef+"").addClass('selected');
            });
            
        });
    });
});
