(function($){
    
   $(function(){   
     
     
     var $nav =$("ul.jquery-gallery-treeview-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.jquery-gallery-treeview-photos");
        var photos =[];
        p.find("li>a").each(function(){                
                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); 
          }
          return false;
        });
     });
     
     $category.find("span.folder").hover(function(){
            $(this).addClass("hover");
            
         },function(){
            $(this).removeClass("hover");
            
        });

     //init
     setCategory($currentCategory);
     
     $("ul.jquery-gallery-treeview-photos").remove();
     
     
     $("div.jquery-gallery-nav > ul.jquery-gallery-treeview-category").addClass("filetree").treeview({collapsed: true,animated: "medium"});

   });
  
    

})(jQuery);

