// Крутилка кртинок на главной
function change_slide(){
	var curSlide =  $(".blue_gr:visible");
	var nextSlide = curSlide.next(".blue_gr");
	if(!nextSlide.length){
		nextSlide =  $(".blue_gr:first")
	}
	var menu = nextSlide.attr("rel");
	
	curSlide.hide();
	$(".index_menu").removeClass("active");
	nextSlide.show();
	$(".item"+menu).addClass("active");
	return false;
}

$(document).ready(function() {
	
	if($(".blue_gr").length){
		setInterval(change_slide, 5000);
	}
	
	// Календарь в пресс центре
	$(".calendar a.change").click(function(){
		var arrow = $(this).parents(".years_arrow");
		var block = $(this).parents(".calendar");
		if (arrow.hasClass("future")){
			block.hide();
			block.next().show();
		} else if(arrow.hasClass("back")){
			block.hide();
			block.prev().show();
		}
		
		return false;
	});
	
	// Крутилка картинок в проектах
	$(".project_item_block .previous_photo").click(function(){
		var first_img = $(".news_img").find("img:visible");
		var prev_img = first_img.prev("img");
		if(prev_img.length){
			first_img.hide();
			prev_img.show();
			// Изменить счетчик
			var num = parseInt($(".pic_number").text());
			$(".pic_number").text(num-1);
			
			$(".next_photo").removeClass("disable");
		}
		if (!prev_img.prev("img").length){
			$(this).addClass("disable");
		}
		return false;
	});
	
	$(".project_item_block .next_photo").click(function(){
		var first_img = $(".news_img").find("img:visible");
		var next_img = first_img.next("img");
		if(next_img.length){
			first_img.hide();
			next_img.show();
			// Изменить счетчик
			var num = parseInt($(".pic_number").text());
			$(".pic_number").text(num-(-1));
			
			$(".previous_photo").removeClass("disable");
		}
		if (!next_img.next("img").length){
			$(this).addClass("disable");
		}
		return false;
	});
	
	// Переключатель картинок на главной
	$(".index_menu").click(function(){
		$(".index_menu").removeClass("active");
		$(this).addClass("active");
		var val = $(this).attr("rel");
		$(".blue_gr").hide();
		$(".slide"+val).show();
		
		return false;
	});
	
	// Крутилка для достижений
	$(".achieve_next").click(function(){
		var cur = $(".achieve:visible");
		var next = cur.next(".achieve");
		if (!next.length){
			next = $(".achieve:first");
		}
		cur.hide();
		next.show();
		return false;
	});
	
	// Крутилка для лицензий
	$(".licence_list .previous_photo").click(function(){
		var first_item = $(".licenses_item:visible");
		var prev_item = first_item.prev(".licenses_item");
		if(prev_item.length){
			first_item.hide();
			prev_item.show();
			$(".licenses_list").removeClass("licenses_list_activ");
			$("#"+parseInt(prev_item.attr("rel"))).parent().addClass("licenses_list_activ");
			// Изменить счетчик
			var num = parseInt($(".license_number").text());
			$(".license_number").text(num-1);
			
			$(".next_photo").removeClass("disable");
		}
		if (!prev_item.prev(".licenses_item").length){
			$(this).addClass("disable");
		}
		return false;
	});
	
	$(".licence_list .next_photo").click(function(){
		var first_item = $(".licenses_item:visible");
		var next_item = first_item.next(".licenses_item");
		if(next_item.length){
			first_item.hide();
			next_item.show();
			$(".licenses_list").removeClass("licenses_list_activ");
			$("#"+parseInt(next_item.attr("rel"))).parent().addClass("licenses_list_activ");
			// Изменить счетчик
			var num = parseInt($(".license_number").text());
			$(".license_number").text(num-(-1));
			
			$(".previous_photo").removeClass("disable");
		}
		if (!next_item.next(".licenses_item").length){
			$(this).addClass("disable");
		}
		return false;
	});
	
	$(".license_right_item").click(function(){
		$(".licenses_list").removeClass("licenses_list_activ");
		$(this).parent().addClass("licenses_list_activ");
		
		var id = parseInt($(this).attr("id"));
		$(".licenses_item").hide();
		$(".licence_list .l"+id).show();
		
		//изменить номер картинки
		$(".license_number").text($(this).attr("order"));
		return false;
	});
	
	
});


