var imgArray = new Array(
	'headWinter.jpg',
	'headSpring.jpg',
	'headSummer.jpg',
	'headAutumn.jpg'
);
var currencyArray = new Array(
	'head_winter_right_block.png',
	'head_winter_left_block.png',
	'head_spring_right_block.png',
	'head_spring_left_block.png',
	'head_summer_right_block.png',
	'head_summer_left_block.png',
	'head_autumn_right_block.png',
	'head_autumn_left_block.png'
);
var year = new Array();
//зима
year[0] = imgArray[0];
year[1] = imgArray[0];
year[11] = imgArray[0];
//весна
year[2] = imgArray[1];
year[3] = imgArray[1];
year[4] = imgArray[1];
//лето
year[5] = imgArray[2];
year[6] = imgArray[2];
year[7] = imgArray[2];
//осень
year[8] = imgArray[3];
year[9] = imgArray[3];
year[10] = imgArray[3];


var yearCur = new Array();
//зима
yearCur[0] = currencyArray[0];
yearCur[1] = currencyArray[0];
yearCur[11] = currencyArray[0];
//весна
yearCur[2] = currencyArray[2];
yearCur[3] = currencyArray[2];
yearCur[4] = currencyArray[2];
//лето
yearCur[5] = currencyArray[4];
yearCur[6] = currencyArray[4];
yearCur[7] = currencyArray[4];
//осень
yearCur[8] = currencyArray[6];
yearCur[9] = currencyArray[6];
yearCur[10] = currencyArray[6];

var yearLocoCur = new Array();
//зима
yearLocoCur[0] = currencyArray[1];
yearLocoCur[1] = currencyArray[1];
yearLocoCur[11] = currencyArray[1];
//весна
yearLocoCur[2] = currencyArray[3];
yearLocoCur[3] = currencyArray[3];
yearLocoCur[4] = currencyArray[3];
//лето
yearLocoCur[5] = currencyArray[5];
yearLocoCur[6] = currencyArray[5];
yearLocoCur[7] = currencyArray[5];
//осень
yearLocoCur[8] = currencyArray[7];
yearLocoCur[9] = currencyArray[7];
yearLocoCur[10] = currencyArray[7];

$(document).ready(function(){
	var wh = null
	//var pik = 700
	var pik = 1200
	resizePage()
	var headObj = $('#head');
	var imgSrc = 'url(/img/' + year[new Date().getMonth()] + ')'
	headObj.css('background-image', imgSrc)
	$('#hideIllustration').css('background-image', headObj.css('background-image').replace('head', 'head2').replace('Small', ''))


	function getPageSize(){
		var de = document.documentElement;
		var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
		var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
		arrayPageSize = [w,h];
		return arrayPageSize;
	}

	$(window).bind('resize', function() {
		resizePage()
	});

	function resizePage(){
		wh = getPageSize()
		if (wh[0] < pik) {
			//Уменьшаем страницу
			$('#center').width('1024px');
			//Уменьшаем шапку
			$('#headTown3').css('left', '905px');
			//валюта должна выдвигаться
			var imgCur = 'url(/img/' + yearCur[new Date().getMonth()] + ')';
			var imgCurRight = 'url(/img/' + yearLocoCur[new Date().getMonth()] + ')';
			$('#currency').mouseover(function() {
				$('#currency').css('left', '810px').css('background-image', imgCurRight)
				//Если ИЕ версии 6, то применяем фильтры прозрачности
				if ($.browser.msie && $.browser.version == '6.0') {
					$('#currency').css('background', 'none').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/" + yearLocoCur[new Date().getMonth()] + "', sizingMethod='image')")
				}
			}).mouseout(function() {
				$('#currency').css('left', '970px').css('background-image', imgCur);
				if ($.browser.msie && $.browser.version == '6.0') {
					$('#currency').css('background', 'none').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/" + yearCur[new Date().getMonth()] + "', sizingMethod='image')")
				}
			});
			//Уменьшаем главное меню
			$('#mainMenu').width('235px').find('div').css('padding-left', '15px');
			// подменю
			$('#dependedMenu').width('165px');
			$('div.dependedMenuLevel2ItemLink').width('140px')
			// поле контактная информация
			$('#contactInfo').width('415px');
			$('#contactInfoPeople').width('195px');
			$('#scrollTable').width('170px').find('td').width('150px').height('65px').find('div:not(:has(img))').width('150px').end().find('div.phoneContactInfo').hide().end().find('div.phoneContactInfoText').css('padding-left', '0px').css('padding-top', '0px');
			$('#scrollTable em').width('160px');
			$('#scrollBarLine img').css('top', '0px');
			$('#scrollTable').css('margin-top', '0px');
			// Новости
			//$('div.news').css('padding-right','10px');
			$('div.news').css('width','150px');
			//содержимое сайта
			$('#content').width('450px');
			$('div.photoReport').width('440px').find('div.photoReportImg').width('378px');
			$('span.headerGray').width('420px');
			$('div.aboutsMap img').width('440px').height('320px');
			$('#map').addClass('mapComtainerTownSmall').find('div.nameTown').each(function() {
				if (this.id.indexOf('Small') == -1) {
					this.id = this.id + 'Small';
					$(this).addClass('smallTown');
				}
			})
			$('div.aboutPrice').width('205px').height('150px').find('div.aboutPriceContent').width('80px').end().find('img').css('top', '46px');
			if ($.browser.msie && $.browser.version <= 6.0) {
				$('#aboutYellowPrice img, #aboutBluePrice img').css('top', '50px')
			}
			$('#aboutYellowPrice').css('margin-right', '30px');
			//Низ
			$('#foot').width('1024px');
			if ($.browser.msie && $.browser.version <= 6.0){ 
				$('#footCreated').css('padding-right', '85px');
				$('#footLocation').css('margin-right', '40px');
			} else {
				$('#footCreated').css('padding-right', '170px');
			}
			
			$('#chart, #chart *').width('415px');
			
			
			init();
		} else {
			//Увеличиваем страницу
			$('#center').width('1200px');
			//Увеличиваем шапку
			$('#headTown3').css('left', '980px')
			//Сбрасываем все события для валют
			$('#currency').unbind();
			//увеличиваем главное меню
			$('#mainMenu').width('250px').find('div').css('padding-left', '25px');
			//подменю
			$('#dependedMenu').width('200px');
			$('div.dependedMenuLevel2ItemLink').width('160px')
			// поле контактная информация
			$('#contactInfo').width('465px');
			$('#contactInfoPeople').width('245px');
			$('#scrollTable').width('230px').find('td').width('230px').height('82px').find('div:not(:has(img))').width('175px').end().find('div.phoneContactInfo').show().end().find('div.phoneContactInfoText').css('padding-left', '10px').css('padding-top', '10px');
			$('#scrollTable em').width('210px');
			$('#scrollBarLine img').css('top', '0px');
			$('#scrollTable').css('margin-top', '0px');
			// новости
			$('div.news').css('width','185px');
			//содержимое сайта
			$('#content').width('620px');
			$('div.photoReport').width('610px').find('div.photoReportImg').width('570px');
			$('span.headerGray').width('580px');
			$('div.aboutsMap img').width('580px').height('360px');
			$('#map').removeClass('mapComtainerTownSmall').find('div.nameTown').each(function() {
				this.id = this.id.replace('Small', '');
				$(this).removeClass('smallTown');
			});
			$('div.aboutPrice').width('260px').height('100px').find('div.aboutPriceContent').width('108px').end().find('img').css('top', '18px');
			$('#aboutYellowPrice').css('margin-right', '90px');
			
			$('#foot').width('1200px');
			if ($.browser.msie && $.browser.version <= 6.0){ 
				$('#footCreated').css('padding-right', '130px');
				$('#footLocation').css('margin-right', '85px');
			} else {
				$('#footCreated').css('padding-right', '220px');
			}
			$('#chart, #chart *').width('465px');
			
			init();
		}
	}
	
	$("a[rel='lightbox-foto']").lightBox()
	//Свернуть шапку, если он уже была свернута
	if ($.cookie('smallHead') == 'true') {
		controlIllustration($('#hideIllustration').find('a').get(0));
	}
	//Если найдены названия компании в ссылке, то изменить вид ссылки
	var blocksDiv = $('#hiddenAboutFirm > div.commentFirm');
	var h1BlocksDiv = $('#hiddenAboutFirm > div.commentFirm')
	$('#content p a[href^=#]').each(function(){
		for (indexBlock = 0; indexBlock < blocksDiv.length; indexBlock ++) {
			if (h1BlocksDiv.eq(indexBlock).attr('rel') == $(this).attr('href')) {
				$(this).attr('href', '#part' + indexBlock).addClass('achor').click(function(){
					return addAbout(this);
				})
				this.setAttribute('onClick', 'return addAbout(this)');
			}
		}
	});
	//Развернуть первую ссылку
	$('a.achor').eq(0).click();
	
	//прокрутка фотогалереи
	$('img.photoReportNavigationLeft').each(function() {
		scrollPhoto(this);
	});
	settings = {
		tl: { radius: 20 },
		tr: { radius: 20 },
		bl: { radius: 20 },
		br: { radius: 20 },
		antiAlias: true,
		autoPad: true,
		validTags: ["div"]
	}
	var myBoxObject = new curvyCorners(settings, "aboutMap", "aboutPrice");
	myBoxObject.applyCornersToAll();
	
	var myBoxObject = new curvyCorners(settings, "aboutPrice");
	myBoxObject.applyCornersToAll();
	
	showGround(window.location.hash);
	
	
	//высота меню
	var height = 0;
	$('#dependedMenu > div').each(function() {
		var elemObj = $(this);
		height = height + parseInt(elemObj.innerHeight());
	});
	//Оперой 9.27 и ниже пользуются только пидарасы!
	if ($.browser.version <= 9.27) {
		height = 0;
		$('#dependedMenu div').each(function() {
			var elemObj = $(this);
			height = height + parseInt(elemObj.outerHeight());
		});
		height -= 300;
	}
	height += 25;
	if (height > 335) {
		$('#dependedMenu').height(height + 'px');
		$('#mainMenu').height(height - 3 + 'px');
	}
	var imgCur = 'url(/img/' + yearCur[new Date().getMonth()] + ')';
	$('#currency').css('left', '970px').css('background-image', imgCur);
	if ($.browser.msie && $.browser.version == '6.0') {
		$('#currency').css('background', 'none').css('filter', "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/img/" + yearCur[new Date().getMonth()] + "', sizingMethod='image')")
	}
});
