$(document).ready(function(){
	
	$('.panel').css({
		'position':'absolute',
		'height':'300px',
		'background-color':'#fff'
			});
	$('.panel').each(function(i){
		$(this).attr('id', 'panel' + ++i );
		
	}).not(':first').hide();
	
	$('.master-category span').not(':first').hide();
	
	$('.belt:hover').cycle({
		
	});
	$('.belt').cycle({
		fx:    'scrollRight', 
	    sync:   0, 
	    delay: -2000,
	    //timeout: 2000,
	    //next: '.belt',
	    pause: 1,
	    before: onBeforeBorder
	});
	
	function onBeforeSpan(){
		ind = $('.belt .panel').index($(this));
		
		if (ind == 0) $('.master-category li span:last').hide();
		$('.master-category li span')
			.eq(ind-1).hide();
		$('.master-category li span')
		.eq(ind).show(1000);
		
		//$(this).children('span').hide();
		//$(this).next().children('span').show();
		};
	
	function onBeforeBorder(){
			ind = $('.belt .panel').index($(this));
			
			if (ind == 0) $('.master-category li:last')
			.removeClass('li-active')
			.find('a')
			.removeClass('a-active');
			$('.master-category li')
				.eq(ind-1)
				.removeClass('li-active')
				.find('a')
				.removeClass('a-active');;
			$('.master-category li')
			.eq(ind)
			.addClass('li-active')
			.find('a')
			.addClass('a-active');
			
			//$(this).children('span').hide();
			//$(this).next().children('span').show();
			};	
		
	$('.master-category li a').each(function(i){
		//count = ++i;
		$(this).attr('id', ++i);
		
		$(this).click(function(){
			//alert('ci sono!');
			$('.belt').cycle('stop');
			$('.panel').removeAttr('style');
			$('.master-category span').hide();
			$('.master-category li').removeClass('li-active');
			$('.master-category li a').removeClass('a-active');
			$(this).addClass('a-active');
			$(this).parent().addClass('li-active');
			
			id = $(this).attr('id');
			//alert(id);
			$('.panel').hide();
			//alert(id-1);
			$('.panel').eq(id-1).fadeIn(1000);
			
		});
	});
	
});