// JavaScript Document

$(document).ready(function(){

	if( !$("body").hasClass("inner") ) {
		$('#header .logo').css("display", "none");
		$('#header .logo_name').css("display", "none");
		$('#header .stk_logo').css("display", "none");
		$('#header .top_menu').css("display", "none");
		$('#carousel .button').css("display", "none");
		$('#specials').css("display", "none");
		$('#footer').css("display", "none");
		$('#block_item0').css("display", "none");
		$('#block_item0 .text_block').css("display", "none");
		$('#block_item0').fadeIn(100);
		setTimeout( function() {
			$('#block_item0 .text_block').fadeIn(200);
			}, 100
		);
		setTimeout( function() {
			$('#header .logo').fadeIn(200);
			$('#header .logo_name').fadeIn(200);
			$('#header .stk_logo').fadeIn(200);
			$('#header .top_menu').fadeIn(200); 
			$('#carousel .button').fadeIn(200);
			$('#specials').fadeIn(200);
			$('#footer').fadeIn(200);
			}, 300
		);
	}

	$("#specials").css("margin-top", Math.round( ( ( $(document).height(true) - $("#header").outerHeight(true) - $("#spacer").outerHeight(true) - $("#carousel").outerHeight(true) - $("#specials").outerHeight(true) ) > 0 ? ( $(document).height(true) - $("#header").outerHeight(true) - $("#spacer").outerHeight(true) - $("#carousel").outerHeight(true) - $("#specials").outerHeight(true) ) : 0 ) / 4 )+"px");
	
	var auto_slide = 0;
	$(".nav span").click( function(){
		auto_slide = 0;
		var current_id = $(this).attr('id');
		var current_index = 0;
		var next_id = '';
		var arr = [];
		$(".nav span").each( function(index) {
			arr[index] = $(this).attr('id');
			if( current_id == $(this).attr('id') ){
				current_index = index;
			}
		} );
		next_id = arr[current_index];
		$(".nav span").removeClass("act");
		$("#"+next_id).addClass("act");
		var current = $("#carousel .carousel_lenta .act");
		var next = $("#carousel .carousel_lenta #block_"+next_id);
		rotate( current, next, 700 );		
	} );
	
	$(".next").click( function(){
		auto_slide = 1;
		var current_id = $("#carousel .ic_item_act").attr('id');
		var current_index = 0;
		var next_id = '';
		var arr = [];
		$("#carousel .ic_item").each( function(index) {
			arr[index] = $(this).attr('id');
			if( current_id == $(this).attr('id') ){
				current_index = index;
			}
		} );
		next_id = arr[current_index + 1];
		if( !next_id ) { 
			next_id = arr[0];
		}
		$("#carousel .nav span").removeClass("ic_item_act");
		$("#"+next_id).addClass("ic_item_act");
		var current = $("#carousel .carousel_lenta .act");
		var next = $("#carousel .carousel_lenta #block_"+next_id);
		rotate( current, next, 700 );		
	} );
	
	
/*
	var i = 0;
	setInterval( function() { i = auto_rotate( $("#carousel .ic_item"), i++, auto_slide ) }, 4000 );
*/
	$(".see_in ins").click( 
		function(){
			id = $(this).attr("id");
			$(".see_in ins").removeClass("act");	
			$(this).addClass("act");	
			$(".bp_show").removeClass("bp_show");
			$(".products_"+id+"").addClass("bp_show");			
		} 
	);

	$(".scroll-content_direction").css("width", ( $(".scroll-content_direction table.default").outerWidth(true) ) - 10 );	
	$('.scroll-content_direction img').load(function() { 
		$(".scroll-content_direction").css("width", ( $(".scroll-content_direction table.default").outerWidth(true) ) - 10);	
	 });

	$(".bookmark").click( function(){
		$(".bookmark").removeClass("act");
		$(".bookmark_block .block_content").removeClass("act");
		$(this).addClass("act");
		$("#"+$(this).attr('id')+"_block").addClass("act");
	} );		
});

function auto_rotate( marked, ii, auto_slide ) {
	if( !auto_slide ) {
		id = "item"+ii;
		next_id = "item"+(ii + 1);
		if( !$("#"+next_id).hasClass("icon") ) {
			next_id = "item0";	
			ii = -1;
		} else if( !$("#"+id).hasClass("icon") && !$("#"+next_id).hasClass("icon")  ) {
			return 0;
		}	
		var current = $("#carousel .carousel_lenta #block_"+id);
		var next = $("#carousel .carousel_lenta #block_"+next_id);
		$("#carousel .carousel_lenta #block_"+id).removeClass("act");
		$("#carousel .nav span").removeClass("act");
		$("#"+next_id).addClass("act");
		rotate( current, next, 700 );			
		return ii + 1;
	}
}

function rotate( current, next, anim_speed ) {	
	current.fadeOut(anim_speed/2).removeClass('act');
	next.fadeIn(anim_speed).addClass('act');
};

