$(function() {
	function loadprod(id) {
		$('.catalogo').hide();
		$('.catalogo-' + id).show().children().show();

		//catalogo
		$('.catalogo-' + id + ' .didascalia').children().hide().parent().show().children(':first').fadeIn();
	
		$('.catalogo-' + id + ' .scroll').jScrollPane();
		
		sel = '.catalogo-' + id + ' .slider a';

		$(sel).click(function() {
			cl = $(this).parent('div').attr('class');
			src = $(this).children().attr('src');
			$(".catalogo-" + id + " .prod-img img:first").attr('src', src);
			$('.catalogo-' + id + ' .didascalia div:visible').hide();
			//$('.catalogo-' + id + ' .didascalia .' + cl).fadeIn();
			$('.' + cl).fadeIn();
			if (cl != 'funny-13') $('span.funny-13').hide();
		});
	}
	
	function scrollto(t) {
		//alert(t);
		$('.scroller').animate({'left': t}, 500);	
	}
	
	function loadmarca(marca) { 
		ind = marca.indexOf(':');
		page = marca.substring(1, ind);
		prod = marca.slice(ind + 1);
		
		$('.menu .current').removeClass('current');
		t = $('a[href=#' + page + ']').addClass('current').attr('rel');
		scrollto(t);
		loadprod(prod);
	}

	loadprod('azzurra');
	
	$('.nav-img a').click(function() {
		t = $(this);
		slider = t.parent().next().children('.slider');
		mass = slider.children('div').size() - 3;
		
		left = slider.css('margin-left');
		rel = t.parent().attr('title');

		if (t.attr('href') == '#next' && rel >= -mass) rel--;
		else if (rel <= 0) rel++;
		
		t.parent().attr('title', rel);
		move = 100 * rel;
		slider.animate({'margin-left': move + 'px'}, {queue:false, duration:300});
	});
	$('a.lvideo').click( function(){
		video = $(this).children('.video').html();
		$.fancybox(video);
		return false;
	});
	
	$('.catalogo').each(function() {
		$(this).children('div:first').siblings().css({'margin': 0});
	});
	
	$('.ADV').cycle({ 
			fx:     'fade', 
			speed:   500, 
			timeout: 3000 
	});	
	
	$('a[href="#zoom"]').click(function() {
		src = $(this).parent().prev().children('img').attr('src');
		$.fancybox('<img src="' + src + '" />');
	});
		
	$('.menu a').click(function() {
		$('.current').removeClass('current');
		rel = $(this).addClass('current').attr('rel');
		scrollto(rel);
	});
	
	$('area').click(function() {
		loadmarca($(this).attr('href'));
	});
	
	 $('button.accedi').click(function() {
		token = '&_=' + rand(32425);
		pass = $('.passlistini').val();
									  
		$('.listino').load('/page/listino.php?pass=' + pass + token);
	});
	 
	$('a[href="#funny-13"]').click(function() {
		$('body').append()
		$.fancybox($('.apollo-det').html());									 
	});
	
});

