Scroll = function(scroller, scroller_bar, menu, iwidth) {
	this.iWidth = iwidth;
	this.canDrag = false;
	this.prepared = false;
	this.shift_x;
	this.delta;
	this.scroller = scroller;
	this.scrollerBar = scroller_bar;
	this.menu = menu;
	this.scrollerStartShift;
	this.menuStartShift;
	this.scrollerTrackWidth = 734;
	this.menuTrackWidth;
	this.scrollerWidth;
	this.menuWidth = 800;
	this.step;
	this.dontmove = false;
	this.a = false;
	this.prepare = function() {
		if(get(this.scroller) && get(this.menu)) {
			this.scroller = get(this.scroller);
			this.scrollerBar = get(this.scroller_bar);
			this.menu = get(this.menu);
			this.scrollerStartShift = parseInt(this.scroller.style.left);
			this.menuStartShift = parseInt(this.menu.style.marginLeft);
			this.menuTrackWidth = parseInt(this.iWidth)+ this.menuStartShift;
			this.scrollerWidth = 20;
			this.scroller.style.paddingRight = this.scrollerWidth - 8 + "px";
			this.scrollerTrackWidth -= 8;
			this.menuTrackWidth -= this.menuWidth;
			this.delta = this.menuTrackWidth / this.scrollerTrackWidth;
			this.prepared = true;
		}
		return false;
	}
	this.fixForBrowsers = function(event) {
		if (!event) {
			event = window.event;
		}
		if(event.stopPropagation) event.stopPropagation();
		else event.cancelBubble = true;
		if(event.preventDefault) event.preventDefault();
		else event.returnValue = false;
	}
	this.setStep = function() {
		this.step = Math.round(this.menu.getElementsByTagName("td")['0'].offsetWidth * this.scrollerTrackWidth / this.menuTrackWidth);    
	}
	this.setPosition = function(newPosition) {
		if(newPosition <= this.scrollerTrackWidth + this.scrollerStartShift && newPosition >= this.scrollerStartShift) {
			this.scroller.style.left = newPosition + "px";
		}
		else {
			if(newPosition >= this.scrollerTrackWidth + this.scrollerStartShift) {
				this.scroller.style.left = this.scrollerTrackWidth + this.scrollerStartShift + "px";
			}
			if(newPosition < this.scrollerStartShift) {
				this.scroller.style.left = this.scrollerStartShift + "px";
			}
		}
		this.menu.style.marginLeft = Math.round( (parseInt(this.scroller.style.left) - this.scrollerStartShift) * this.delta * (-1) ) + this.menuStartShift + "px";
		return false;
	}
	this.drag = function(event) {
		if (!event) {
			event = window.event;
		}
		if (this.prepared) {
			this.canDrag = true;
			this.shift_x = event.clientX - parseInt(this.scroller.style.left);
			this.fixForBrowsers(event);
		}
		return false;
	}
	this.movescroller = function(event) {
		if (!event) {
			event = window.event;
		}
		if (this.prepared && !this.dontmove) {
			this.setStep();
			var clickX = event.layerX ? event.layerX : event.offsetX;
			var currentPosition = parseInt(this.scroller.style.left);               
			var i = (clickX > currentPosition) ? 1 : -1;
			var newPosition = 2*i*this.step + parseInt(this.scroller.style.left); 
			this.setPosition(newPosition);
			this.fixForBrowsers(event);
		}
		else {
			this.dontmove = false;
		}
		return false;
	}
	this.move = function(event) {
		if (!event) {
			event = window.event;
		}
		if (this.prepared && this.canDrag) {
			this.setPosition(event.clientX-this.shift_x);
			this.fixForBrowsers(event);
		}
		return false;
	}
	this.drop = function() {
		this.canDrag=false; 
	}
	this.scrollerClickHandler = function() {
		this.dontmove=true;    
	}
	this.handle = function(delta, event) {
		if (!event) {
			event = window.event;
		}
		var i = (delta < 0) ? 1 : -1;
		this.setStep()
		var currentPosition = parseInt(this.scroller.style.left);
		var newPosition = i*this.step + currentPosition; 
		this.setPosition(newPosition);
		this.fixForBrowsers(event);
	}
	this.cancelWheelAction = function(event) {
		if (!event) {
			event = window.event;
		}
		if (event.preventDefault) {
			event.preventDefault();
		}
		event.returnValue = false;
	}
	this.wheel = function(event) {
		var delta = 0;
		if (!event) {
			event = window.event;
		}
		if (event.wheelDelta) {
			delta = event.wheelDelta/120;
			if (window.opera) {
				delta = delta;
			}
		} 
		else if (event.detail) {
			delta = -event.detail/3;
		}
		if (delta) {
			this.handle(delta, event);
			this.cancelWheelAction(event);
			this.fixForBrowsers(event);
			return false;
		}
	}
}

function get(id) {
	return document.getElementById(id);
}
function handleOnMouseUp(event) {
	first.drop(event);
}
function handleOnMouseMove(event) {
	first.move(event);
}
function handleOnClickBarFirst(event) {
	first.movescroller(event);
}
function handleOnMouseDownFirst(event) {
	first.drag(event);
}
function handleOnClickFirst(event) {
	first.scrollerClickHandler(event);
}
function handleOnMouseWheelFirst(event) {
	first.wheel(event);
}
var first;
$("#loading").css("display","block");
baseWidth='704';
anchor=window.location.hash;
anchor=anchor.substring(1);
base_id='img'+anchor;
function checkGallery(){lastImg="#img"+total;
	var offLast=$(lastImg).offset();
	var offFirst=$("#img1").offset();
	var offMain=$(".ul-holder-1").offset();
	if((offLast.left-baseWidth+64)<=(offMain.left)){$("#next").css("display","none");
	$("#prev").css("display","block")}else if((offFirst.left)>=(offMain.left-10)){$("#prev").css("display","none");
	$("#next").css("display","block")}else{$("#prev").css("display","block");
	$("#next").css("display","block")}}
function toogleMainPic(thisLi){checkGallery();
	thisLiNum=thisLi.replace("img","");
	thisLi="#"+thisLi;
	if(!$(thisLi).hasClass("active")) {
		var actId=$(".active").attr("id");
		if(!actId){actId=base_id}actId=actId.replace('img','');
		var ulPos=Number($("#gallery").css("left").replace("px",""));
		LiPos=thisLiNum*64;
		LiPosFromNull=LiPos+ulPos;
		if(actId<thisLiNum||actId>thisLiNum) {
			$("#gallery").stop(true,true);
			if(LiPosFromNull<=(-baseWidth/2)) {
				LiOverlap=LiPosFromNull+baseWidth/2;
				if(LiOverlap<=0){
					newPos=-(LiPos+baseWidth/2-64);
					$("#gallery").animate({left:newPos},1000,function(){checkGallery()})
				}
			} else {
				LiOverlap=LiPosFromNull-baseWidth/2;
				if(LiOverlap>0){
					newPos=ulPos-LiOverlap;
					newPos=-(LiPos-32);
					var wwidth=64*total;
					var limit=-(wwidth-0.5*baseWidth);
					if(newPos<limit){
						newPos=limit
					}
					$("#gallery").animate({left:newPos},1000,function(){checkGallery()})}
				}
			} else if (actId=='1') {
				$("#gallery").stop(true,true);
				newPos=-baseWidth/2;
				$("#gallery").animate({left:newPos},1000,function(){checkGallery()})
			} else if(actId==thisLiNum) {
				LiOverlap=LiPosFromNull-baseWidth/2;
				if(LiOverlap>0){
					newPos=-(LiPos-32);
					var wwidth=64*total;
					var limit=-(wwidth-0.5*baseWidth);
					if(newPos<limit){
						newPos=limit
					}
				$("#gallery").animate({left:newPos},3000,function(){checkGallery()})
			}
		}
		$(".active").fadeTo('fast',0.3);
		$(".active").removeClass("active");
		$(thisLi).addClass("active");
		$(thisLi).fadeTo('fast',1);
		$(thisLi).removeClass("h_on");
		var phLink=$(thisLi).children("a").attr("href");
		var phAdr=phLink.replace(/\/photography\/([^/]+)\/([^/]+)\/(.+)\.html/,'/images/photography/$1/$2/$3.jpg');
		var phName=phLink.replace(/\/photography\/([^/]+)\/([^/]+)\/(.*)\.html/,'$3');
		var alt=$(".active img").attr("alt");
		$("#texts p").css("display","none");
		var txt_id='#txt'+thisLiNum;
		if($(txt_id)) $(txt_id).fadeIn("slow");
		var loc='#'+phName;
		window.location=loc;
		$("#main-image").stop(false,false);
		$("#main-image #photo-wrapper").fadeOut(250,function(){
			$("#arr-wrapper").css("display","none");
			$("#main-image #loading").css("display","block");
			$(new Image()).load(function(){
				if (this.width > '800'){
					$("#main-image #photo").html('<div id="withscript"><div class="content"><div style="margin-left:0px;" id="movemenu" ><img src="'+phAdr+'" alt="'+alt+'" /></div><div class="menu_scrolling"><div id="scroller_bar"><div id="scroller" style="left: 20px;"><img alt="" src="/images/scroller/dot-black.gif" /></div></div><p>(перемещайте ползунок, чтобы посмотреть панораму целиком)</p></div>');
					first = new Scroll('scroller', 'scroller_bar', 'movemenu', this.width);
					first.prepare();
					document.onmousemove = handleOnMouseMove;
					window.onmouseup = handleOnMouseUp;
					get('scroller_bar').onclick = handleOnClickBarFirst;
					get('scroller').onmousedown = handleOnMouseDownFirst;
					get('scroller').onmouseup = handleOnMouseUp;
					get('scroller').onclick = handleOnClickFirst;
					tWidth = '800px';
				}
				else {
					$("#main-image #photo").html('<img src="'+phAdr+'" alt="'+alt+'" />');
					tWidth = this.width;
				}
				$("#arr-wrapper").css("width",tWidth);
				$("#main-image").css("width",tWidth);
				$("#photo").css("width",tWidth);
				$(".arr-holder").css("height",this.height);
				if ($(thisLi).hasClass("show-title")) {
					$("#photo-title").html(alt);
				}
				else {
					$("#photo-title").html('&nbsp;');
				}
				$("#main-image #loading").css("display","none");
				$("#arr-wrapper").css("display","block");
				$("#main-image #photo-wrapper").fadeIn(900,function(){
					progress='true';
					$("#main-image").css("opacity","1")
				})
			}).attr('src',phAdr)
		})
	}
}
jQuery(function(){try{
$("#main-image").css("height","560px");
$("#main-image-wrapper").css("height","560px");
$("#photo-wrapper").css("height","560px");
if (anchor) {
	base__id = "."+anchor;
	base_id=$(base__id).parent().attr("id");
}
if(!$('#'+base_id).attr("id")||!anchor){
	base_id='img1'
}
idsArray=new Array();
$("#gallery li").each(function(i){idsArray[i]=this.id; total=i});
total++;
mainwidth=64*total;
$("#gallery").css("width",mainwidth);
$("#imgnext").click(function(){if(progress!='false'){progress='false';
nextId=Number($(".active").attr("id").replace("img",""))+1;
if(nextId>total){nextId=1}nId="img"+nextId;
toogleMainPic(nId)}});
$("#imgprev").click(function(){if(progress!='false'){progress='false';
previd=Number($(".active").attr("id").replace("img",""))-1;
if(previd=='0'){previd=total}pId="img"+previd;
toogleMainPic(pId)}});
toogleMainPic(base_id);
$("#gallery").css("width",mainwidth);
$(".main-image_wrapper").css({'height':'600px'});
$("#gallery li").css({display:'none',opacity:0.3}).fadeIn(1500);
$("#gallery li").hover(function(){if(!$(this).hasClass("active")){$(this).fadeTo('fast',0.7);
$(this).addClass("h_on")}},function(){if(!$(this).hasClass("active")){$(this).fadeTo('fast',0.3);
$(this).removeClass("h_on")}});
$("#gallery li").click(function(){
	toogleMainPic(this.id);
	return false
});
$("#imgprev").bind("mouseenter",function(){$("#imgprev div").css("display","block")}).bind("mouseleave",function(){$("#imgprev div").css("display","none")});
$("#imgnext").bind("mouseenter",function(){$("#imgnext div").css("display","block")}).bind("mouseleave",function(){$("#imgnext div").css("display","none")});
$("#next").click(function(){$("#gallery").stop(true,true);
var left=$("#gallery").css("left");
var width=$("#gallery").css("width");
left=Number(left.replace('px',''));
width=Number(width.replace('px',''));
var newPos=left-64;
var limit=-(width-0.5*baseWidth+5);
if(newPos>limit){newPos=newPos+'px';
$("#gallery").animate({left:newPos},function(){checkGallery()})}});
$("#prev").click(function(){$("#gallery").stop(true,true);
var baseWidth=704;
var left=$("#gallery").css("left");
left=Number(left.replace('px',''));
var newPos=left+64;
var limit=-(0.5*baseWidth)+5;
if(newPos<=limit){newPos=newPos+'px';
$("#gallery").animate({left:newPos},function(){checkGallery()})}checkGallery()})}catch(e){alert(e)}});
