$(document).ready(function() {
	if (typeof window.innerWidth != 'undefined'){
		actualwidth = window.innerWidth;
	} else {
		actualwidth = document.getElementsByTagName('body')[0].clientWidth;
	}
	if (typeof window.innerHeight != 'undefined'){
			actualheight = window.innerHeight;
		} else {
			actualheight = document.getElementsByTagName('body')[0].clientHeight;
		}
		
	var girl_width = $("#girl_image").attr('width');
	var city_width = $("#city_image").attr('width');
	var girl_height = $("#girl_image").attr('height');
	var city_height = $("#city_image").attr('height');
	var winW = $(window).width();
	var wrapW = $('.wrapper').innerWidth();
	var girlContWidth = $("#girl_image").attr('width')-94;
	var cityContWidth = $("#city_image").attr('width')-410;
	if (winW > wrapW)
	{
		var addWidth = Math.round((winW - wrapW)/2);
		$(".index_girl").css('width',girlContWidth+addWidth);
		$(".index_bg").css('width',cityContWidth+addWidth);
	} else {
		$(".index_girl").css('width',girlContWidth);
		$(".index_bg").css('width',cityContWidth);
	}
	actualwidth = actualwidth-12;
		var koef = actualwidth / 1260;
		var koef2 = actualheight / 748;
		if (koef2 < koef){
			koef = koef2;
		}
		if (koef > 1){	
			koef = 1;
		}else if(koef <0.7){
			koef = 0.7;
		}
	var h_size = Number($("h1").css('font-size').replace('%','').replace('px',''));

	$("#girl_image").attr('width',Math.round(girl_width*koef));
	$("#city_image").attr('width',Math.round(city_width*koef));
	$("#girl_image").attr('height',Math.round(girl_height*koef));
	$("#city_image").attr('height',Math.round(city_height*koef));
	$("body").css('font-size',100.01*koef+"%");
	if (ept_second < 1){
		if (!isNaN(h_size)){
			Cufon.replace("h1", { fontFamily: 'Myriad Pro' });
		}
		//Cufon.replace(".menu ul li a span", { fontFamily: 'Myriad Pro' });
		Cufon.replace(".basket", {fontFamily: 'Myriad Pro'});
	}
	girlContWidth = $("#girl_image").attr('width')-Math.round(94*koef);
	cityContWidth = $("#city_image").attr('width')-Math.round(410*koef);
	if (winW >= wrapW){
		var addWidth = Math.round((winW - wrapW)/2);
		$(".index_girl").css('width',girlContWidth+addWidth);
		$(".index_bg").css('width',cityContWidth+addWidth);
	} else {
		$(".index_girl").css('width',girlContWidth);
		$(".index_bg").css('width',cityContWidth);
	}
	//(".wrapper").css('min-height',Math.round(($('.content').innerHeight())*koef));
	//alert($('.content').innerHeight());
	$('.page_wrapper').css('min-height',$('.content').innerHeight()+250);
	$(window).resize(function(){
		if (typeof window.innerWidth != 'undefined'){
			actualwidth = window.innerWidth;
		} else {
			actualwidth = document.getElementsByTagName('body')[0].clientWidth;
		}
		if (typeof window.innerHeight != 'undefined'){
			actualheight = window.innerHeight;
		} else {
			actualheight = document.getElementsByTagName('body')[0].clientHeight;
		}
		
		actualwidth = actualwidth-12;
		var koef = actualwidth / 1260;
		var koef2 = actualheight / 748;
		if (koef2 < koef){
			koef = koef2;
		}
		if (koef > 1){	
			koef = 1;
		}else if(koef <0.7){
			koef = 0.7;
		}
		$("#girl_image").attr('width',Math.round(girl_width*koef));
		$("#city_image").attr('width',Math.round(city_width*koef));
		$("#girl_image").attr('height',Math.round(girl_height*koef));
		$("#city_image").attr('height',Math.round(city_height*koef));
		//$(".wrapper").css('min-height',Math.round(($('.right').innerHeight())*koef));
		$("body").css('font-size',100.01*koef+"%");
		if (ept_second < 1){
			if (!isNaN(h_size))
			{
				$("h1").css('font-size',Math.round(h_size*koef)+"%");
			}
		
			Cufon.replace("h1", { fontFamily: 'Myriad Pro' });
			//Cufon.replace(".menu ul li a span", { fontFamily: 'Myriad Pro' });
		}
		var winW = $(window).width();
		var wrapW = $('.wrapper').innerWidth();
		var girlContWidth = $("#girl_image").attr('width')-Math.round(94*koef);
		var cityContWidth = $("#city_image").attr('width')-Math.round(410*koef);
		if (winW >= wrapW){
			var addWidth = Math.round((winW - wrapW)/2);
			$(".index_girl").css('width',girlContWidth+addWidth);
			$(".index_bg").css('width',cityContWidth+addWidth);
		} else {
			$(".index_girl").css('width',girlContWidth);
			$(".index_bg").css('width',cityContWidth);
		}
		$('.page_wrapper').css('min-height',$('.content').innerHeight()+250);
	});

	$('#fancybox-overlay').attr('title','Свернуть');
});

function getInnerWidth(object){
	return $(object).innerWidth();
}

