$i = 0;
$j = 0;

function slideSwitch() {
	var $n = jQuery("#slideshow img").size();
	
	if ($i < $n)
	{
		$i++;
	}
	else {
		$i = 0;
		}
	
	/*if ($i == $n) $i = 0;*/
	
	//jQuery("#slideshow img").hide();
	jQuery("#slideshow img").fadeOut(2000);
	jQuery("#slideshow img").eq($i).fadeIn(2000);
}

function slideSwitch_nag() {
	var $n = jQuery("#block_nagrady img").size();
	
	if ($j < $n)
	{
		$j++;
	}
	else {
		$j = 0;
		}
	
	if ($j == $n) $j = 0;
	
	//jQuery("#slideshow img").hide();
	jQuery("#block_nagrady img").hide();
	jQuery("#block_nagrady img").eq($j).fadeIn(4000);
}


jQuery(document).ready(function()
{

   	jQuery("div#gr_category_menu ul li a").attr("id", "current");
	jQuery("div#gr_category_menu ul li a").removeAttr("id");
	
	jQuery("div#gr_category_menu ul li").hover(
	  function () {
		jQuery(this).attr("id", "current_m");
		jQuery(this).find(" div.gr_category_menu_img a").attr("id", "current");
	  },
	  function () {
		jQuery(this).removeAttr("id");
		jQuery(this).find(" div.gr_category_menu_img a").removeAttr("id");
	  }
	);
	
	jQuery(".great_predlozheniay_item:odd").after("<div class='great_predlozheniay_item_clear'><div></div></div>");

	jQuery("div#menu ul li").addClass("level1");
	jQuery("div#menu ul ul li").removeClass().addClass("level2");
	jQuery("div#menu ul li.level1").hover(
	  function () {
		  	jQuery("div#menu ul li ul").hide(); 
	  		jQuery(this).find("ul li:first").attr("style", "padding-top:4px;");
	  		jQuery(this).find("ul li:last").attr("style", "padding-bottom:4px;");
			jQuery(this).find("ul").show();
	  },
	  function () {
					
	  }
	);

	jQuery("div#menu ul ul").hover(
	  function () { 
			jQuery(this).show();
	  },
	  function () {
			jQuery(this).hide();
	  }
	);
	
	jQuery(".catalog_list_item_foto a.sdf, .small_foto_item a, #big_foto a, #variaty_obivki_body a, #big_foto_car a").lightBox();

	var count_goods = jQuery('#carousel_ul li').size();
	
	if(count_goods>4)
	{
	jQuery('#carousel_ul li:first').before(jQuery('#carousel_ul li:last'));  
	
	jQuery("#right_scroll").click(
			function(){
				var item_width = jQuery('#carousel_ul li').outerWidth() + 1;
				
				var left_indent = parseInt(jQuery('#carousel_ul').css('left')) - item_width;
				jQuery('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){    
					jQuery('#carousel_ul li:last').after($('#carousel_ul li:first')); 
					jQuery('#carousel_ul').css({'left' : '-180px'});
				}); 
			}
		);

	jQuery("#left_scroll").click(
			function(){
				var item_width = jQuery('#carousel_ul li').outerWidth() + 1;
				var left_indent = parseInt(jQuery('#carousel_ul').css('left')) + item_width;
				
				jQuery('#carousel_ul:not(:animated)').animate({'left' : left_indent},500,function(){    
						 
				jQuery('#carousel_ul li:first').before($('#carousel_ul li:last')); 
				
				jQuery('#carousel_ul').css({'left' : '-180px'});
				}); 
			}
		);
	}
	else {
		jQuery("#right_scroll").remove();
		jQuery("#left_scroll").remove();	
		jQuery("#carousel_ul").attr("style", "left:0px;")
	}
	
	jQuery(".news_block_itemodd").after('<div class="news_block_itemodd_sep"></div>');
	jQuery("div#header_img img.first").removeAttr("class");
	jQuery("#slideshow IMG:first").addClass("active");
	setInterval( "slideSwitch()", 8000 );

	jQuery("#footer_more a").click(
			function(){
				jQuery("div#seo_text, div#seo_text_var1").show();
			}
		);
	jQuery("#seo_text_close a").click(
			function(){
				jQuery("div#seo_text, div#seo_text_var1").hide();
			}
		);
	
	jQuery("#block_nagrady img:first").fadeIn(2000);
	setInterval( "slideSwitch_nag()", 8000 );
});
