$(document).ready(function(){

	$('#banners > div').mouseover(function(){
		$(this).addClass('active');
	});
	$('#banners > div').mouseout(function(){
		$(this).removeClass('active');
	});
	
	
	$('#banner_1 .next').click(function(){
		$('#banners').removeClass('banner_1');
		$('#banners').addClass('banner_2');
		$('#banners .block .info_icon').removeClass('show');
		return false;
	});
	$('#banner_2 .next').click(function(){
		$('#banners').removeClass('banner_2');
		$('#banners').addClass('banner_3');
		$('#banners .block .info_icon').removeClass('show');
		return false;
	});
	$('#banner_2 .previous').click(function(){
		$('#banners').removeClass('banner_2');
		$('#banners').addClass('banner_1');
		$('#banners .block .info_icon').removeClass('show');
		return false;
	});
	$('#banner_3 .previous').click(function(){
		$('#banners').removeClass('banner_3');
		$('#banners').addClass('banner_2');
		$('#banners .block .info_icon').removeClass('show');
		return false;
	});
	
	
	$('#banners .block .info_icon .info').click(function(){
		$('#banners .block .info_icon').addClass('show');
		return false;
	});
	$('#banners .block .info_icon .hide_popup').click(function(){
		$('#banners .block .info_icon').removeClass('show');
		return false;
	});
	
	
	$('#index_content .block .info_icon .info').click(function(){
		$('#index_content .block .popup').show();
		return false;
	});
	$('#index_content .block .info_icon .hide_popup a').click(function(){
		$('#index_content .block .popup').hide();
		return false;
	});
	
	
	$('#left .block .info_icon .info').click(function(){
		$('#left .block .popup').show();
		return false;
	});
	$('#left .block .info_icon .hide_popup a').click(function(){
		$('#left .block .popup').hide();
		return false;
	});
	
	//Высчитываем ширину блоков словаря внизу страницы
	var widthItemsBlock = $("#items .inner").width(),
		numberOfElems = 3,
		newWidthElems = (widthItemsBlock / 3) + 1;
	
	$(".item").css("width", newWidthElems + "px");
	
	
	if($('div#items')) {
	
		var cnt = $('div#items .inner > div.abs.items > div.item').length;
		var i = 3;
		
		var innerWidth = $('div#items .inner').width();
		var itemWidth = innerWidth / 3;

		$('.next_small').click(function () {
			if(i < cnt) {		  
				$('.items').animate({left: -(i-3)*itemWidth-innerWidth}, { duration: 1500, queue: false });
				i = i + 3;
			}
			if (i > 3) {
				$('.prev').html('<a href="#">&larr;</a>');
			}
			if (i == cnt || i - 1 == cnt) {
				$('.next_small').html('&rarr;');
			}
			return false;		
		});
		
		$('.prev').click(function () {
			if(i > 3) {
				$('.items').animate({left: -(i-3)*itemWidth+innerWidth}, { duration: 1500, queue: false });
				i = i - 3;
			}
			if(i < 4) {
				$('.prev').html('&larr;');
			}
			$('.next_small').html('<a href="#">&rarr;</a>');
			return false;
		});
		
		$('.prev').html('&larr;');
	}
	
	
	
	//Online Test
	clickButtonTest = function() {
		$('#get_results').unbind("click");
		$('#otvet_1, #otvet_2, #otvet_3, #otvet_4').hide();
		var count = 0;
		
		$('.test_block').find(":input[type=radio]").each(function() {
			if ($(this).attr("checked") == "checked") {
				count += parseInt($(this).attr('value'));
			}
		});
		
		if (count >= 0 && count <= 10) {
			$('#otvet_1').show();
		} else if (count >= 11 && count <= 15) {
			$('#otvet_2').show();
		} else if (count >= 16 && count <= 20) {
			$('#otvet_3').show();
		} else if (count >= 21 && count <= 25) {
			$('#otvet_4').show();
		}
		
		$(this).css("background", "url(/images/test_button2.jpg) no-repeat");
		return false;
	}
	
	changeRadioTest = function() {
		$(".one, .two, .three, .four, .five").unbind("change");
		$("#get_results").unbind("click");
		$("#get_results").css("background", "url(/images/test_button1.jpg) no-repeat");
		$('#otvet_1, #otvet_2, #otvet_3, #otvet_4, #otvet_5').hide();
		$(".one, .two, .three, .four, .five").bind("change", changeRadioTest);
		$("#get_results").bind("click", clickButtonTest);
	}
	
	$(".one, .two, .three, .four, .five").bind("change", changeRadioTest);
	$("#get_results").bind("click", clickButtonTest);
	
	
	
	//Заглушки для ie7
	if ($.browser.msie && $.browser.version <= "7.0") {
		$("#top_abs").css({
			"position" : "absolute",
			"left" : "0px"
		});
		
		$("#impaza").css({
			"position" : "absolute"
		});
		
		
	}
	
});
