$(document).ready(function() {
	
	window.speed = 500;
	
	$('ul.langs li span').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	$('ul.cases li a').hover(function(){
		$(this).parent().parent().addClass('violet');
	},function(){
		$(this).parent().parent().removeClass('violet');
	});
	
	$('.number-block .number i span').hover(function(){
		$(this).parent().parent().parent().addClass('violet');
	},function(){
		$(this).parent().parent().parent().removeClass('violet');
	});
	
	$('.the-end span').hover(function(){
		$(this).addClass('end-hover');
	},function(){
		$(this).removeClass('end-hover');
	});
			
	$('.remember-number').hover(function(){
		$(this).parent().addClass('violet');
	},function(){
		$(this).parent().removeClass('violet');
	});

	if (document.getElementById('c1')) {
	
		$('ul.langs span:eq(0)').click(function(){
			window.current = 'c1';
			$('#c1').animate({left: '0'}, window.speed);
			$('#c2').animate({left: '1500px'}, window.speed);
			$('#c3').animate({left: '3000px'}, window.speed, function() {
				$('ul.langs span').addClass('link');
				$('ul.langs span').removeClass('active');
				$('ul.langs span:eq(0)').removeClass('link');
				$('ul.langs span:eq(0)').addClass('active');
				correct_height();
			});
			$.post('lang.html', {'lang': 'ru'});
		});
	
		$('ul.langs span:eq(1)').click(function(){
			window.current = 'c2';
			$('#c1').animate({left: '-1500px'}, window.speed);
			$('#c2').animate({left: '0'}, window.speed);
			$('#c3').animate({left: '1500px'}, window.speed, function() {
				$('ul.langs span').addClass('link');
				$('ul.langs span').removeClass('active');
				$('ul.langs span:eq(1)').removeClass('link');
				$('ul.langs span:eq(1)').addClass('active');
				correct_height();
			});
			$.post('lang.html', {'lang': 'en'});
		});
	
		$('ul.langs span:eq(2)').click(function(){
			window.current = 'c3';
			$('#c1').animate({left: '-3000px'}, window.speed);
			$('#c2').animate({left: '-1500px'}, window.speed);
			$('#c3').animate({left: '0px'}, window.speed, function() {
				$('ul.langs span').addClass('link');
				$('ul.langs span').removeClass('active');
				$('ul.langs span:eq(2)').removeClass('link');
				$('ul.langs span:eq(2)').addClass('active');
				correct_height();
			});			
			$.post('lang.html', {'lang': 'jp'});
		});
	
		$.post('lang.html', {'lang': 'en'});
		window.current = 'c2';
		correct_height();
		
		if (window.location.href.indexOf('#') > 0) {
			var parts = window.location.href.split('#');
			var lang = parts[1];
			if (lang == 'jp') {
				$('ul.langs span:eq(2)').click();
			}
			if (lang == 'ru') {
				$('ul.langs span:eq(0)').click();
			}
		}
		window.onresize = function() {
			correct_height();
		}
		
	} else {
		
		$('.number span').click(function() {
			nval = 0;
			while(nval < 11) {
				nval = parseInt(Math.random(11,999) * 1000);
			}
			$('.number span').html(nval);
		});
		
		$('ul.langs span:eq(0)').click(function(){
			window.current = 'c1';
			$('#c1a').animate({left: '0'}, window.speed);
			$('#c1b').animate({left: '0'}, window.speed);
			$('#c2a').animate({left: '1500px'}, window.speed);
			$('#c2b').animate({left: '1500px'}, window.speed);
			$('#c3').animate({left: '3000px'}, window.speed, function() {
				$('ul.langs span').addClass('link');
				$('ul.langs span').removeClass('active');
				$('ul.langs span:eq(0)').removeClass('link');
				$('ul.langs span:eq(0)').addClass('active');
				correct_height2();
			});
			$.post('lang.html', {'lang': 'ru'});
		});
	
		$('ul.langs span:eq(1)').click(function(){
			window.current = 'c2';
			$('#c1a').animate({left: '-1500px'}, window.speed);
			$('#c1b').animate({left: '-1500px'}, window.speed);
			$('#c2a').animate({left: '0'}, window.speed);
			$('#c2b').animate({left: '0'}, window.speed);
			$('#c3').animate({left: '1500px'}, window.speed, function() {
				$('ul.langs span').addClass('link');
				$('ul.langs span').removeClass('active');
				$('ul.langs span:eq(1)').removeClass('link');
				$('ul.langs span:eq(1)').addClass('active');
				correct_height2();
			});
			$.post('lang.html', {'lang': 'en'});
		});
	
		$('ul.langs span:eq(2)').click(function(){
			window.current = 'c3';
			$('#c1a').animate({left: '-3000px'}, window.speed);
			$('#c1b').animate({left: '-3000px'}, window.speed);
			$('#c2a').animate({left: '-1500px'}, window.speed);
			$('#c2b').animate({left: '-1500px'}, window.speed);
			$('#c3').animate({left: '0px'}, window.speed, function() {
				$('ul.langs span').addClass('link');
				$('ul.langs span').removeClass('active');
				$('ul.langs span:eq(2)').removeClass('link');
				$('ul.langs span:eq(2)').addClass('active');
				correct_height2();
			});			
			$.post('lang.html', {'lang': 'jp'});
		});
		
		
		window.current = 'c2';
		correct_height2();
		
		window.onresize = function() {
			
			correct_height2();
			
		}
		
	}
	
});

function correct_height() {

	if(window.innerWidth){
    	window_width = window.innerWidth;
    	window_height = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth){
    	window_width = document.documentElement.clientWidth;
    	window_height = document.documentElement.clientHeight;
	} else if (document.body.clientWidth){
	    window_width = document.body.clientWidth;
	    window_height = document.body.clientHeight;
	}
	
	div_height = document.getElementById(window.current).clientHeight;
		if (window_height - 199 > div_height) {
			h = window_height - 199;
		} else {
			h = div_height;
		}
	$('.middle').css('height',h + 'px');

	if (window_width < 960)
		window_width = 960;
	pl = Math.round(window_width / 2) - 240;
	
	$('.js-padding').css('padding-left',pl + 'px');
	
}

function correct_height2() {

	if(window.innerWidth){
    	window_width = window.innerWidth;
    	window_height = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth){
    	window_width = document.documentElement.clientWidth;
    	window_height = document.documentElement.clientHeight;
	} else if (document.body.clientWidth){
	    window_width = document.body.clientWidth;
	    window_height = document.body.clientHeight;
	}
	
	
	if (window.current == 'c3') {
		div_height = document.getElementById(window.current).clientHeight;
		if (window_height - 180 > div_height) {
			h = window_height - 223;
		} else {
			h = div_height;
		}
	} else {
		div_height = document.getElementById(window.current+'b').clientHeight;
		h = div_height + 628;
	}
	
	$('.middle').css('height',h + 'px');
	
	if (window_width < 960)
		window_width = 960;
	pl = Math.round(window_width / 2) - 240;
	$('.js-padding').css('padding-left',pl + 'px');
	
}







