function auto_category_rotator() {
	if(jQuery('.category-rotator-flag').hasClass('mouseout')){
		var active = jQuery('.category-rotator:visible .category-rotator-list li.active');
		var els_count = jQuery('.category-rotator:visible .category-rotator-list ul').children('li').length;
		var el_index = active.index();
		var el_index1 = el_index + 1;
		//alert('els_count - '+els_count+ ' index '+el_index1);
		if( el_index1 == els_count ){
			active.parent().find('li:first').mouseenter();
		}else{
			active.next().mouseenter();
		}
		jQuery('.category-rotator-flag').addClass('mouseout');
	}
}

jQuery(document).ready(function() {
	jQuery('.category-rotator-image div.block').fadeOut(10).hide();
	jQuery('.category-rotator-image').find('div.block:first').fadeIn(10);
	
	//jQuery('.category-rotator-list li:first').addClass('active');
	jQuery('.category-rotator-list ul li').removeClass('active');
	jQuery('.category-rotator-list ul').find('li:first').addClass('active');
	
	jQuery('.category-rotators .category-rotator').hide();
	jQuery('.category-rotators .category-rotator:first').show();
	jQuery('.category-rotator-pager li:first').addClass('active');
	
	jQuery('.category-rotator-list li').hover(//
		function () {
			if(!jQuery(this).hasClass('active')){
				jQuery(this).siblings('li').removeClass('active');
				jQuery(this).addClass('active');
				var index = jQuery(this).index();
				var index1 = index + 1;
				var img_wrapper = jQuery(this).closest('.category-rotator').find('.category-rotator-image');
				img_wrapper.find('div.block').stop(true, true).fadeOut(1500);
				img_wrapper.find('div.block:nth-child('+index1+')').stop(true, true).fadeIn(1000);
			}
		},
		function () {
			//jQuery(this).removeClass("hover");
		}
	);
	
	jQuery('.category-rotator-pager li').click(function() {
		jQuery(this).addClass('active').siblings().removeClass('active');
		var pager_index = jQuery(this).index();
		var pager_index1 = pager_index + 1;
		jQuery('.category-rotator').hide();
		jQuery('.category-rotator:nth-child('+pager_index1+')').show();
	});
	
	
	jQuery('.wrap-category-rotator').hover(
		function () {
			jQuery('.category-rotator-flag').removeClass('mouseout');
		},
		function () {
			jQuery('.category-rotator-flag').addClass('mouseout');
		}
	);


	$(function() {
		setInterval( "auto_category_rotator()", 12000 );
	});

	
});

