(function($){

    $(function(){
        
        $("#menu2 li").each(function(){
            if($(this).children("ol").size()>0){
                $(this).children("a").click(function(){

                    
                    $(this).closest("li").siblings(".current").find("ol").slideUp("fast",function(){ $(this).closest("li").removeClass("current");});
                    
                    $(this).siblings("ul,ol").slideDown("fast",function(){ $(this).closest("li").addClass("current");});
                    return false;
                });
            }
        
        });
        $("#newSSContainer").fpSlideShow();
        
        $("#pgGallery a").fancybox({
    		'hideOnContentClick': false
    	});

    });
    
    
    var ssStopped = false;
    $.fn.fpSlideShow = function(commands){
        var fadeSpeed = 750;
        if(commands=="stop"){
            clearInterval($.ssTime);
            ssStopped = true;
        }
        else{
            var aCon = $(this).children(":first");
            aCon.children(":first").addClass("current").fadeIn(fadeSpeed);
            if(!ssStopped){
                $.ssTime = setInterval(function(){
                    
                    aCon.find(".current").fadeOut(fadeSpeed, function(){
                        $(this).removeClass("current");
                        var newCur = $(this).next();
                        
                        if(newCur.size()==0){
                            newCur = aCon.children(":first");
                        }
                        newCur.fadeIn(fadeSpeed).addClass("current");
                    });
                    
                    
                }, 11000);
            }
        }
    
    };



})(jQuery);