$(document).ready(function() {
	// Init and options for scrollable content
//	$('.scrollable').scrollable({
//		size: 4
//	});
	// Superfish
	$('#sub_nav').superfish();
	
	jQuery('.jCarousel').jcarousel({
         
        initCallback:mycarousel_initCallback
					  
    });
   
	 function mycarousel_initCallback(carousel)
                                             {_Carousel=carousel;
     };
	 $(function(){
		
		 $(".slide").hide();
		 $(".slide").eq(0).show();
		 $("li.button").css({
		                opacity: 0.5,
				        border: '1px solid #fff'
            			 
		 });
		 $("li.button").eq(0).css({
		                opacity: 1,
            			borderWidth: 1 
            			 
		 });

		
            $("li.button").click(function(){
            
                $clicked = $(this);
            	if(currentTimer){
            	                  clearTimeout(currentTimer);currentTimer=null;
            	                                     
            	}
            	if(parseInt($clicked.attr("jcarouselindex")) < parseInt($("li.button").length))                   
	                currentTimer=setTimeout("fireNext()", TIME);       
	            else 
	                currentTimer=setTimeout("fireFirst()",TIME);       
	            
            	// if the button is not already "transformed" AND is not animated
            	if ($clicked.css("opacity") != "1" && $clicked.is(":not(animated)")) {
            		
            		$clicked.animate({
            			opacity: 1,
            			borderWidth: 1
            		}, 600 );
            		 
            		// each button div MUST have a "xx-button" and the target div must have an id "xx" 
            		var idToLoad = $clicked.attr("id").split('-');
            		//we search trough the content for the visible div and we fade it out
            		$("#jcDisplay").find("div.slide:visible").fadeOut("fast", function(){
            			//once the fade out is completed, we start to fade in the right div
            			$(this).parent().find("#"+idToLoad[0]).fadeIn();
            		})
            	}
            	
            	//we reset the other buttons to default style
            	$clicked.siblings(".button").animate({
            		opacity: 0.5,
            		borderWidth: 1
            	}, 600 );
            	 
            	
            });
		});

});
