function galleryScroll(v1, v2, v3, v4)
{
	this.tween = false;
	this.element = false;
	this.scrolling = "No";
	
	this.styleElement = "top";
	this.sizeElement = "offsetHeight";
	this.speed = 120;
	this.width = "auto";
	this.snap = false;
	
	this.init = function(maskId, leftUpId, rightDownId, settings)
	{
		if(settings)
		{
			if(settings.speed)
				this.speed = settings.speed;
			if(settings.width)
				this.width = settings.width;
			if(settings.snap)
				this.snap = settings.snap;
			if(settings.type && settings.type == "horizontal")
			{
				this.styleElement = "left";
				this.sizeElement = "offsetWidth";
			}
		}
		
		this.element = document.getElementById(maskId).firstChild;

		var moveLeftUp = document.getElementById(leftUpId);
		var moveRightDown = document.getElementById(rightDownId);

		if(this.getElementWidth() > this.element.parentNode[this.sizeElement])
		{
			var self = this;
			moveLeftUp.onmousedown = function(e) { return self.startScrollLeftUp(this, e ? e : window.event); };
			moveRightDown.onmousedown = function(e) { return self.startScrollRightDown(this, e ? e : window.event); };
		}
		else
		{
			moveLeftUp.style.display = "none";
			moveRightDown.style.display = "none";
			document.getElementById("gallery-mask").style.left = "-2px";
		}

		moveLeftUp.onclick = function() { return false; };
		moveRightDown.onclick = function() { return false; };
	}
	
	this.startScrollLeftUp = function(obj, evt)
	{
		if(((evt.which) ? evt.which : evt.button) != 1)
			return;

		var self = this;
		document.onmouseup = function() { self.scrollRelease(this); return false; };
		if(obj.setCapture)
			obj.setCapture();
	
		this.scrollStop();
	
		var posStart = this.getPosition();
		var posStop = 0;
		if(posStart != posStop)
		{
			this.tween = new Tween(this.element.style, this.styleElement, Tween.none, posStart, posStop, Math.abs(posStart - posStop) / this.speed, "px");
			this.tween.start();
		}

		this.scrolling = "UpLeft";
		return false;
	}
	
	this.startScrollRightDown = function(obj, evt)
	{
		if(((evt.which) ? evt.which : evt.button) != 1)
			return;

		var self = this;
		document.onmouseup = function() { self.scrollRelease(this); return false; };
		if(obj.setCapture)
			obj.setCapture();
	
		this.scrollStop(obj);
		
		var posStart = this.getPosition();
		var posStop = (this.getElementWidth() * -1) + this.element.parentNode[this.sizeElement];
		if(posStart != posStop)
		{
			this.tween = new Tween(this.element.style, this.styleElement, Tween.none, posStart, posStop, Math.abs(posStart - posStop) / this.speed, "px");
			this.tween.start();
		}
		
		this.scrolling = "RightDown";
		return false;
	}
	
	this.scrollStop = function()
	{
		if(this.tween)
			this.tween.stop();
		this.scrolling = "No";
		return false;
	}
	
	this.scrollRelease = function(obj)
	{
		var wasScrolling = this.scrolling;
		this.scrollStop();
		if(this.snap && wasScrolling != "No")
		{
			var posStart = this.getPosition();
			var posStop = 0;
			if(wasScrolling == "RightDown")
				posStop = Math.floor(posStart / this.snap) * this.snap;
			else if(wasScrolling = "LeftUp")
				posStop = Math.ceil(posStart / this.snap) * this.snap;
			if(posStart != posStop)
			{
				this.tween = new Tween(this.element.style, this.styleElement, Tween.none, posStart, posStop, Math.abs(posStart - posStop) / this.speed, "px");
				this.tween.start();
			}
		}
	
		document.onmouseup = null;
		if(obj.releaseCapture)
			obj.releaseCapture();
	}
	
	this.scrollToOffset = function(offset, time)
	{
		if(this.scrolling != "No")
			return false;

		if(this.tween)
			this.tween.stop();

		offset *= -1;
		var posStart = this.getPosition();
		if(posStart != offset)
		{
			this.tween = new Tween(this.element.style, this.styleElement, Tween.regularEaseIn, posStart, offset, time, "px");
			this.tween.start();
		}

		return true;
	}
	
	this.getPosition = function()
	{
		return this.element.style[this.styleElement] ? parseInt(this.element.style[this.styleElement], 10) : 0;
	}
	
	this.getElementWidth = function()
	{
		return (this.width == "auto") ? this.element[this.sizeElement] : this.width;
	}
	
	this.init(v1, v2, v3, v4);
}
