function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

function setBackgroundImageSize(){
	var pageWidth = ___getPageSize()[0];//берем новый размер экрана
	//alert($(".jCarouselLite ul").css('left').replace("px", "")+' '+pageWidth);$(".jCarouselLite ul li").width()
	var cur_slide = parseInt($(".jCarouselLite ul").css('left').replace("px", ""))/$(".jCarouselLite ul li").width();//вычисляем текущий активный слайдер
	//var cur_slide = parseInt($(".jCarouselLite ul").css('left').replace("px", ""))/parseInt($(".jCarouselLite ul").width())/parseInt($(".jCarouselLite ul").length/3);//вычисляем текущий активный слайдер
	$(".jCarouselLite").width(pageWidth+'px');//задаем новую ширину контейнера слайдера
	$(".jCarouselLite ul").width((pageWidth*$(".jCarouselLite ul li").size())+'px');//задаем новую ширину "портянки" элементов (ширина страницы*кол во элементов)
	$(".jCarouselLite ul li").width(pageWidth+'px');//задаем новую ширину контейнера элемента
	
	if(pageWidth>=1700){
		$(".jCarouselLite ul li").height(pageWidth/1700*670);
	}else if(pageWidth>=1024){
		$(".jCarouselLite ul li").height(670-((1700-pageWidth)*0.75)/2.5);
	}else{
		$(".jCarouselLite ul li").height(467);
	}
	
	$(".jCarouselLite ul").css('left', (pageWidth*cur_slide)+'px');
	
	/*$(".jCarouselLite ul li").height($(".jCarouselLite ul li img").height()+'px');//пересчет высоты (img имеет 100% ширину)
	$(".jCarouselLite ul").css('left', pageWidth*cur_slide+'px');*///пересчет смещения слайдера
}
var innerImgSize = {1:1};

function resizePosts(){
	var count = 0;
	for (var i in innerImgSize){ count++;}
	
	if(count == 1){
			innerImgSize = new Array();
			var img_id = 1;
			$('.jCarouselLite').each(function(index){
					$(this).find('img').each(function(index){
							if($(this).css('position') == 'absolute'){
									innerImgSize['carusel_img_'+img_id] = Array();
									innerImgSize['carusel_img_'+img_id]['width'] = $(this).width();
									innerImgSize['carusel_img_'+img_id]['height'] = $(this).height();
									
									if($(this).css('margin-left').search('px')){
										innerImgSize['carusel_img_'+img_id]['margin-left-type'] = 'px';
										innerImgSize['carusel_img_'+img_id]['margin-left'] = $(this).css('margin-left').replace('px','');}
									else if($(this).css('margin-left').seach('%')){
										innerImgSize['carusel_img_'+img_id]['margin-left-type'] = '%';
										innerImgSize['carusel_img_'+img_id]['margin-left'] = $(this).css('margin-left').replace('%','');}
									else{
										innerImgSize['carusel_img_'+img_id]['margin-left-type'] = '';
										innerImgSize['carusel_img_'+img_id]['margin-left'] = $(this).css('margin-left');}
									
									innerImgSize['carusel_img_'+img_id]['top-type'] = '%';
									innerImgSize['carusel_img_'+img_id]['top'] = 40;
									/*if($(this).css('top').search('px')){
										innerImgSize['carusel_img_'+img_id]['top-type'] = 'px';
										innerImgSize['carusel_img_'+img_id]['top'] = $(this).css('top').replace('px','');}
									else if($(this).css('top').seach('%')){
										innerImgSize['carusel_img_'+img_id]['top-type'] = '%';
										innerImgSize['carusel_img_'+img_id]['top'] = $(this).css('top').replace('%','');}
									else{
										innerImgSize['carusel_img_'+img_id]['top-type'] = '';
										innerImgSize['carusel_img_'+img_id]['top'] = $(this).css('top');}*/
										
									$(this).addClass('carusel_img_'+img_id);
									img_id++;
								}
						});
				});
		}
		
	if($('body').width()>1010){
		for(i in innerImgSize){
			$('.'+i).width(innerImgSize[i]['width']);
			$('.'+i).height(innerImgSize[i]['height']);
			$('.'+i).css('top',innerImgSize[i]['top']+innerImgSize[i]['top-type']);
			$('.'+i).css('margin-left',innerImgSize[i]['margin-left']+innerImgSize[i]['margin-left-type']);
		}
	}else if($('body').width()>740){
		for(i in innerImgSize){
			$('.'+i).width(innerImgSize[i]['width']/3*2);
			$('.'+i).height(innerImgSize[i]['height']/3*2);
			$('.'+i).css('top',innerImgSize[i]['top']+innerImgSize[i]['top-type']);
			$('.'+i).css('margin-left',(innerImgSize[i]['margin-left']/3*2)+innerImgSize[i]['margin-left-type']);
		}
	}else if($('body').width()>580){
		for(i in innerImgSize){
			$('.'+i).width(innerImgSize[i]['width']/2);
			$('.'+i).height(innerImgSize[i]['height']/2);
			$('.'+i).css('top',innerImgSize[i]['top']+innerImgSize[i]['top-type']);
			$('.'+i).css('margin-left',(innerImgSize[i]['margin-left']/2.5)+innerImgSize[i]['margin-left-type']);
		}
	}else{
		for(i in innerImgSize){
			$('.'+i).width(innerImgSize[i]['width']/2);
			$('.'+i).height(innerImgSize[i]['height']/2);
			$('.'+i).css('top',(innerImgSize[i]['top']/2*3)+innerImgSize[i]['top-type']);
			$('.'+i).css('margin-left',(innerImgSize[i]['margin-left']/2.5)+innerImgSize[i]['margin-left-type']);
		}
	}
	
	$('#thumbs,#thumbwrapper').height($('body').width()/100*2+182*2+2);
	var count = Math.ceil($('body').width()/450);
	if(count>4)count=4;
		$('#thumbwrapper > #thumbs .thumb').css('width',((100-count*2)/count)+'%');
	/*if($('body').width()>2000)
		$('#thumbwrapper > #thumbs .thumb').css('width','18%');
	else if($('body').width()>1500)
		$('#thumbwrapper > #thumbs .thumb').css('width','23%');
	else if($('body').width()>900)
		$('#thumbwrapper > #thumbs .thumb').css('width','31.3%');
	else if($('body').width()>450)
		$('#thumbwrapper > #thumbs .thumb').css('width','48%');
	else
		$('#thumbwrapper > #thumbs .thumb').css('width','98%');*/
	
	$('#txtoptiz,#txtoptizwrapper').height($('body').width()/100*2+115*2+2);
		$('#txtoptizwrapper > #txtoptiz .thumb').css('width',((100-count*2)/count)+'%');
	/*if($('body').width()>2000)
		$('#txtoptizwrapper > #txtoptiz .thumb').css('width','18%');
	else if($('body').width()>1500)
		$('#txtoptizwrapper > #txtoptiz .thumb').css('width','23%');
	else if($('body').width()>900)
		$('#txtoptizwrapper > #txtoptiz .thumb').css('width','31.3%');
	else if($('body').width()>450)
		$('#txtoptizwrapper > #txtoptiz .thumb').css('width','48%');
	else
		$('#txtoptizwrapper > #txtoptiz .thumb').css('width','98%');*/
		
		
	if($('body').width()>980){
		$('div.adr-block').show();
		$('div.footer-wrapper > .footer').width(940);
	}else if($('body').width()>501){
		$('div.adr-block').hide();
		$('div.footer-wrapper > .footer').width(500);
	}else{
		$('div.adr-block').hide();
		$('div.footer-wrapper > .footer').width(273);
	}
	
	if($('body').width()>980){
		$('div.social-block > .sb-flickr-block').width(510);
		$('div.social-block > .sb-twi-block> .blockquote').show();
		$('div.social-block > .sb-twi-block').width(385);
		$('div.social-block').width(924);
	}else if($('body').width()>635){
		$('div.social-block > .sb-flickr-block').width(510);
		$('div.social-block > .sb-twi-block> .blockquote').hide();
		$('div.social-block > .sb-twi-block').width(70);
		$('div.social-block').width(584);
	}else{
		var count = Math.ceil((635-$('body').width())/83);
		$('div.social-block > .sb-flickr-block').width(507 - 83*count);
		$('div.social-block > .sb-twi-block> .blockquote').hide();
		$('div.social-block > .sb-twi-block').width(70);
		$('div.social-block').width(582 - 83*count);
	}
}

$(document).ready(function(){
	if($(".jCarouselLite").length)
		setBackgroundImageSize();
	$('.jCarouselLite').height('');
	$('.jCarouselLite ul').show()
	resizePosts();
});

window.onresize = function(){
	if($(".jCarouselLite").length)
		setBackgroundImageSize();
	resizePosts();
}
