var currItem = -1,
	itemsCount;

function carousel(){
	$("#carousel img").eq(currItem).fadeOut(1000);
	currItem = (currItem + 1) % itemsCount;
	$("#carousel img").eq(currItem).fadeIn(1000);
}

$(document).ready(function(){

	/*---- carousel init ----------*/
	itemsCount = $("#carousel img").length;
	carousel();
	setInterval("carousel()", 5000);	
	


	/*---- catalog switcher ---------*/
	if ($.cookie('category') != null){
		showCategory();
	}
	
	function showBrands(){
		$("#brands").parent().hide();
		$("#brands").parent().next().hide();
		
		$("#category-title").show()
							.next().show();
							
		$(".content .catalog-kinds").hide();	
		$(".content .catalog-brands").show();		
		
		$.cookie('brands', 'y', { path: '/' });
		$.cookie('category', null);	
	};
	function showCategory(){
		$("#category").parent().hide();
		$("#category").parent().prev().hide();
		
		$("#brand-title").show()
						.prev().show();
		$(".content .catalog-kinds").show();
		$(".content .catalog-brands").hide();

		$.cookie('category', 'y', { path: '/' });	
		$.cookie('brands', null);		
	};
	
	$("#brands").click(function(){
		showBrands();
	});

	$("#category").click(function(){
		showCategory();
	});
	
	/*--- table design ---*/
	$(".content tr:even").css({"background":"url(images/table.png) repeat" });
	$(".content tr:even > td, .content tr:even > th").css({"height": 36});
    
    $('.news-detail a.detail-picture, .section-item a.image, a.fancybox').fancybox({overlayColor: '#000', overlayOpacity: 0.5});
})
