(function($){
    
   $(function(){   
     var $nav =$("ul.jquery-gallery-h-link-category");
     var $category =$nav.children("li");

     var $currentCategory = $category.eq(0);
     
     var $title =$("div.jquery-gallery-title");
     var $list  =$("div.jquery-gallery-list");
     var $view  =$("div.jquery-gallery-viewer");
    
     $title.html("");
     $list.html("");
     $view.html("");

     var setCategory=function(category){  
        $title.text(category.attr("title"));
        $currentCategory.removeClass("active");
        $currentCategory =category;
        $currentCategory.addClass("active");
        category.each(function(){
            var _category =this;
            $list.each(function(){
                if(window.jquery_gallery_list_init){
                    window.jquery_gallery_list_init(_category,this);
                }
            });
        });
     };
     
     $category.each(function(){
        var c =$(this);
        var p= c.children("ul");
        var photos =[];
        p.find("li>a").each(function(){
//                $("<img/>").attr("src",$(this).attr("thumb")).appendTo($(this));
                photos.push({"title":$(this).attr("title"),"thumb": $(this).attr("thumb"),"href":$(this).attr("href")});
            });
        this.photos = photos;
        c.click(function(){
          if(c!=$currentCategory){
             setCategory(c); 
          }
        });
     }).hover(function(){
        $(this).addClass("hover");
     },function(){
        $(this).removeClass("hover");
     });

     //init
     setCategory($currentCategory);

   });
  
    

})(jQuery);

