$(document).ready(function() {
	
	/**
	 * Aside navigation
	 */
	$("aside > nav h3 a").click(function() {
		$("aside > nav section.active").removeClass('active');
		$(this).parent().parent().addClass('active');
		
		return false;
	});
	
	/**
	 * Products preview
	 */
	$("#b-home-large").each(function() {
		$(this).find('li:gt(0)').hide();		
		window.setTimeout(products_preview_roll, 4000);
	});
	
	function products_preview_roll(element) {
		var current = $("#b-home-large li:visible");
		
		if (current.next().length > 0) {
			current.next().fadeIn(2000).prev().fadeOut(2000);
		}
		else {
			$("#b-home-large li:first").fadeIn();
			current.fadeOut(2000);
		}
		
		window.setTimeout(products_preview_roll, 6000);
	}
	
	/**
	 * Brands preview
	 */
	$("#brands-preview").each(function() {
		
	});
	
	/**
	 * Product details
	 */
	$("body#module-products #details").each(function() {
		// Set active tab
		$(this).find('li').first().addClass('active');
		
		// Do links
		$(this).find('li h3').each(function() {
			$(this).wrapInner('<a href="' + window.location.href + '#' + $(this).parent().attr('id') + '" />');
		});
		
		// Hide inactive content
		$(this).find('li:not(.active) .content').hide().parent().addClass('non-active');
		
		// Make tabs
		var tab_left = 0;
		$(this).css('position', 'relative').css('padding', '34px 0 0')
			   .find('li').css('position', 'static').css('padding', '0')
			   .find('h3').css('position', 'absolute').css('top', 0).each(function() {
					$(this).css('left', tab_left);
					tab_left += $(this).outerWidth() + 4;
					
					$(this).find('a').click(function() {
						$("#details li.active")
							.removeClass('active').addClass('non-active')
							.find('.content').hide();
							
						$(this)
							.parent().parent().addClass('active').removeClass('non-active')
							.find('.content').show();
						
						return false;
					});
				});
	});
	
});

