var slideObjects = new Array();

function slideObj(obj, s, dir) {
	
	this.content = obj;
	this.container = document.createElement("div");
	this.content.parentNode.appendChild(this.container);
	this.container.appendChild(this.content);
	this.container.id = obj.id+"Container";

	this.step = s;
	this.dir = dir;
	this.top = 0;
	this.left = 0;
	this.running = false;
	this.objIndex = slideObjects.push(this)-1;
	
	this.slider = function () {
		switch (this.dir) {
			case 0: //stop
				this.stop();
				break;
			case 1: //up
				if (this.top-this.step>this.container.offsetHeight-this.content.offsetHeight)
					this.content.style.top = this.top-=this.step;
				else if (this.container.offsetHeight<this.content.offsetHeight) {
					this.stop();
					this.content.style.top = this.top = this.container.offsetHeight-this.content.offsetHeight;
				}
				break;
			case 2: //down
				if (this.top+this.step<0)
					this.content.style.top = this.top+=this.step;
				else {
					this.stop();
					this.content.style.top = this.top = 0;
				}
				break;
			case 3: //left
				if (this.left-this.step>this.container.offsetWidth-this.content.offsetWidth)
					this.content.style.left = this.left-=this.step;
				else if (this.container.offsetWidth<this.content.offsetWidth) {
					this.stop();
					this.content.style.left = this.left = this.container.offsetWidth-this.content.offsetWidth;
				}
				break;
			case 4: //right
				if (this.left+this.step<0)
					this.content.style.left = this.left+=this.step;
				else {
					this.stop();
					this.content.style.left = this.left = 0;
				}
				break;
		}
	}
	this.slide = function (direction) {
		this.dir = direction;
		if (!this.running) {
			this.interval = setInterval('slideObjects['+this.objIndex+'].slider()', 20);
			this.running = true;
		}
	}
	this.slide(this.dir);
	
	this.stop = function() {
		clearInterval(this.interval);
		this.running = false;
	}
}

function startSlide(obj, s, direction) {
	var i;
	for(i=0; i<slideObjects.length; i++) {
		if (slideObjects[i].content===obj) {slideObjects[i].step = s; slideObjects[i].slide(direction); return;}
	}
	new slideObj(obj, s, direction);
}
