
$(function(){
	if(document.getElementById('foto_inner')){	
		$(window).resize(function(){
			var oFoto_inner  = document.getElementById('foto_inner');
			var iPosLeft = pageWidth()/2 + posLeft() - oFoto_inner.offsetWidth/2;
			oFoto_inner.style.left = ( iPosLeft > 0 ? iPosLeft : 0 ) + 'px';
			var iPosTop = pageHeight()/2 + posTop() - oFoto_inner.offsetHeight/2 + 6;
			oFoto_inner.style.top = ( iPosTop > 0 ? iPosTop : 0 ) + 'px';
		});
		
	}
})

function pageWidth() {return window.innerWidth != null ? window.innerWidth - 18 : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;}
	
function pageHeight() {return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;}
		
function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;}
		
function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;}
	
$(function(){
	$('#foto_inner_close').click(function(){
		$('#switches li.selected').removeClass('selected');
		$('.bigimgs img.selected').removeClass('selected');
		$('#foto_inner.show').removeClass('show');
	});
	
	var aSwitches = $('#switches li');
	var aBigImgs = $('.bigimgs img');
	for(var i = 0; i < aSwitches.length; i++){
		addClickAction(aSwitches[i], aBigImgs[i]);
	}
	
})

function addClickAction(from, to){
	$(from).click(function(){
		if(!$(from).is('.selected')){
			$('#switches li.selected').removeClass('selected');
			$('.bigimgs img.selected').removeClass('selected');
			$(from).addClass('selected');
			$(to).addClass('selected');
			if($('td.switches')){
				var oContainer = $('.bigimgs img.selected');
				var iContainerWidth = $(oContainer).width() + 35;
				var iMinWidth = $('.min_width').width() + 43;
				var oSwitches = $('td.switches');
				
				if(iContainerWidth >= iMinWidth){
					$(oSwitches).attr('width',iContainerWidth + 'px');
				}
				else {
					$(oSwitches).attr('width',iMinWidth + 'px');
				}
			}
		}
	})
}
	
function fotoBlock(currentId){
	
	var oFoto_inner  = document.getElementById('foto_inner');	
	var bigCurrentId = 'big' + [currentId+1];
	var bigCurrentIdInner = document.getElementById(bigCurrentId);
	var smallCurrentId = 'small' + currentId;
	var smallCurrentIdInner = document.getElementById(smallCurrentId);	
	
	if($('foto_inner')){
		var switchesContainer = document.getElementById('switches');
		if(switchesContainer){
			var iContainerWidth = $(bigCurrentIdInner,'selected').width() + 35;
			var iMinWidth = $('.min_width').width() + 43;
			var oSwitches = $('td.switches');
			
			if(iContainerWidth > iMinWidth){
				$(oSwitches).attr('width',iContainerWidth + 'px');
			}
			else {
				$(oSwitches).attr('width',iMinWidth + 'px');
			}
		};
		
		$('#switches li.selected').removeClass('selected');
		$('.bigimgs img.selected').removeClass('selected');
		$('#foto_inner .show').removeClass('show');
		
		var sSrc = bigCurrentIdInner.getAttribute('src');
		var body = $('body')[0];
		var ix = new Image;
		ix.onload = function(){
			$(body).append(ix);
			$(ix).remove();
			var iPosLeft = pageWidth()/2 + posLeft() - oFoto_inner.offsetWidth/2;
			var iPosTop = pageHeight()/2 + posTop() - oFoto_inner.offsetHeight/2 + 6;
			oFoto_inner.style.left = ( iPosLeft > 0 ? iPosLeft : 0 ) + 'px';
			oFoto_inner.style.top = ( iPosTop > 0 ? iPosTop : 0 ) + 'px';
			$('#foto_inner').addClass('show');
		}
		
		$(bigCurrentIdInner,'selected').removeClass('selected');
		$(smallCurrentIdInner).parent(smallCurrentIdInner,'selected').removeClass('selected');
		$(bigCurrentIdInner).addClass('selected');
		$(smallCurrentIdInner).parent(smallCurrentIdInner).addClass('selected');
		
		$(ix).attr('src', sSrc);
	}
};
	
$(function(){
	var b = $('div.incut_foto img.reducer')[0];
	if(b){
		var source = $(b).attr('src');
		b.onload = function(){
			$('div.incut_foto img.plus.hide').removeClass('hide').siblings('a').find('img.hide').removeClass('hide');
		};
		b.src=source;
	}
});