jQuery(document).ready(function($) {
	$('.layer-showcase ul li:gt(0)').hide();
	
	$('.layer-showcase ul li').each(function() {
		$('> *:eq(0)', this).nextAll().wrapAll('<div class="layer-showcasecontent" />');
		$(this).append('<div class="layer-showcasecontentbottom" />');
	});
	
	$('.layer-showcase ol li').each(function(i) {
		if (i > 2) $(this).addClass('hide');
		else $(this).addClass('item-tab'+(i+1));
	});
	
	var timerShowcase = null;
	
	$('.layer-showcase ol li').click(function() {
		clearInterval(timerShowcase);
		
		var index = $('li', $(this).parent()).index($(this));

		$('.layer-showcase ul li').stop(true, true);

		if (!$('.layer-showcase ul li:eq('+index+')').is(':visible')) {
			$('.layer-showcase ul li:visible').fadeOut(function() {
				$('.layer-showcase ul li:eq('+index+')').fadeIn();
			});
		}
		
		timerShowcase = setInterval(function() {
			if (jQuery('.layer-showcase ul li:visible').is(':last-child')) jQuery('.layer-showcase ol li:first').trigger('click');
			else {
				var index = jQuery('.layer-showcase ul li').index(jQuery('.layer-showcase ul li:visible'));
				
				jQuery('.layer-showcase ol li:eq('+(index+1)+')').trigger('click');
			}
		}, 9000);
				
		return false;
	});
	
	var timerShowcase = setInterval(function() {
		if (jQuery('.layer-showcase ul li:visible').is(':last-child')) jQuery('.layer-showcase ol li:first').trigger('click');
		else {
			var index = jQuery('.layer-showcase ul').find('li').index(jQuery('.layer-showcase ul li:visible'));
			
			jQuery('.layer-showcase ol li:eq('+(index+1)+')').trigger('click');
		}
	}, 9000);
	
	
	

	$('.layer-productlist .layer-next').click(function() {
		$('.layer-productlist li').stop(true, true);
		if (!$('.layer-productlist li:last').hasClass('item-noborder'))
			$('.layer-productlist li:visible:first').fadeOut('fast', function() {
				$('.layer-productlist li:visible:last').removeClass('item-noborder').next().addClass('item-noborder').fadeIn('fast');
			});
		
			return false;
		});

	$('.layer-productlist .layer-previous').click(function() {
		$('.layer-productlist li').stop(true, true);
		if (!$('.layer-productlist li:visible:first').is(':first-child'))				
			$('.layer-productlist li:visible:last').fadeOut('fast', function() {
				$('.layer-productlist li:visible:first').prev().fadeIn('fast');
			}).removeClass('item-noborder').prev().addClass('item-noborder');
			
		return false;
	});
	
	//$('.layer-collection li').append('<div class="layer-rc"></div>');
	
	$('.layer-collection li .layer-rc').click(function() {
		var target = $('h4 a', $(this).parent()).attr('href');
		location.href = target;
	}).css('cursor', 'pointer');
	
	// Fancybox setup
	
	if (typeof fancybox == 'function') $('a.fancybox').fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'titleShow'		:	false
	});
});
