$(function() {
    /////////////////////////////////////////////////////////////
    // Filter
    $("#showroom-filter li").bind("click",function(){
            var $thisName = $(this).attr("class");
            if($thisName == "all"){
                $("#showroom-cont li").each(function(){
                    $(this).fadeIn().stop().animate({height:200,width:150,opacity:1});
                }); 
            }else{
                $("#showroom-cont li").not("#showroom-cont #"+$thisName).each(function(){
                    $(this).stop().animate({height:0,width:0,opacity:0}).fadeOut();
                });
                
                $("#showroom-cont #"+$thisName).each(function(){
                     $(this).fadeIn().stop().animate({height:200,width:150,opacity:1});
                });  
            }
            
            /// Color efx
            $(this).addClass("clicked").css("background-color","silver");
            $("#showroom-filter li").not(this).each(function(){
                $(this).removeClass("clicked").css("background-color","#DADADA");
            });
        });
    
    ////////////////////////////////////////////////////////////////////
    /// Item click
    $("#showroom-cont li").live("mouseover",function(){
        $(this).children("#item-background").stop().animate({opacity:1});
        $("#showroom-cont li").not(this).each(function(){
            $(this).children("#item-background").stop().animate({opacity:0});
        });
    }).live("mouseout",function(){
        $("#showroom-cont li").each(function(){
            $(this).children("#item-background").stop().animate({opacity:0});
        });
    }).live("click",function(){
       window.location.hash = $(this).attr("name");
    });
    //////////////////////////////////////////////////////////////////////
    //// Hash reader
    var hashchange = function(){
       var $hash = window.location.hash.slice(1).split("-")[0]; 
       if($hash != "" && $hash != undefined){
            $.ajax({
            url:"ajax.php",
            type:"POST",
            data:"showroom="+$hash,
            success:function(data){
                $("#showroom-loadarea").html(data).fadeIn().children("#showroom-viewarea").fadeIn();
            }
           });
       }
    }
    hashchange();
    $(window).bind("hashchange",function(){
        hashchange();
    });
    ///////////////////////////////////////////////////////////////////////
    //// Showroom closer
    $("#showroom-close").live("click",function(){
        $("#showroom-loadarea").children("#showroom-viewarea").fadeOut().parent("#showroom-loadarea").fadeOut().empty();
        window.location.hash = "";
    });
    ///////
    //// Images zoomer
    $("#images-cont ul li img")
        .live("click",function(){
            var $src = $(this).attr("src").replace("small_","");
            $("#image-dark")
                .fadeIn()
                .children("#image-load")
                    .html("sys/img/loading.gif")
                    .html("<img src='"+$src+"' id='showroom-inside-image' />")
                    .fadeIn();
            
        });
        
    $("#image-dark").live("click",function(){
        $(this).fadeOut().children("#image-load").empty();
    });
});
