(function() {
	if ($("property-thumbs")) {
		var timer;
		var thumbs = $("property-thumbs");
		thumbs.style.width = thumbs.getWidth()+"px";
		thumbs.style.whiteSpace = "nowrap";
		var offX = thumbs.cumulativeOffset().left;
		var width = thumbs.getWidth();
		var margin = 50;
		var moveamt = 0;
		var f = function() {
			if (!moveamt)
				return;
			thumbs.scrollLeft += moveamt;
			window.setTimeout(f, 100);
		}
		thumbs.observe("mousemove", function(ev) {
			var X = ev.pointerX() - offX;
			if (X <= margin)
				moveamt = -5;
			else if (width - X <= margin)
				moveamt = 5;
			else
				moveamt = 0;
			f();
		});
		thumbs.observe("mouseout", function() {
			moveamt = 0;
		});

		var images = thumbs.select("img")
		images.each(function(img, n) {
			if (!n)
				img.addClassName("active");
			img.observe("click", function(ev) {
				$("googlemap").hide();
				$("property-image").show();
				images.invoke("removeClassName", "active");
				var img = ev.element().addClassName("active");
			});
		});

		$("prev").observe("click", function(ev) {
			images.invoke("removeClassName", "active");
			var img = prevImage()
			$(img.id.replace("imagechanger", "imagechangerthumb")).addClassName("active");
			ev.stop();
		});
		$("next").observe("click", function(ev) {
			images.invoke("removeClassName", "active");
			var img = nextImage()
			$(img.id.replace("imagechanger", "imagechangerthumb")).addClassName("active");
			ev.stop();
		});
	}
}).onLoad();

