// Scroll Object v 2.0 - Eduard Prats

function Scroll(idLayer, clipWidth, clipHeight,width,height,speed){
	this.id = idLayer;
	if(document.getElementById) {
		this.scrollLayer = document.getElementById(idLayer).style;
		}
	else  if (document.layers) {
		this.scrollLayer = document.layers[idLayer];		
		}
	else if(document.all) {
		this.scrollLayer = document.all[idLayer].style;
		}
	else alert("Browser Not Supported!");
	
	this.x = clipWidth;
	this.y = clipHeight;
	this.clipX = 0;
	this.clipX2 = clipWidth;
	this.clipY = 0;
	this.clipY2 = clipHeight;
	this.width = width;
	this.height = height;
	this.speed = speed;
	this.obj = idLayer + "Scroll";
	eval(this.obj + "=this");
	
	// Init Clipping
	if(document.layers){
		this.scrollLayer.clip.top = 0;
		this.scrollLayer.clip.right = this.x;
		this.scrollLayer.clip.bottom = this.y;
		this.scrollLayer.clip.left = 0;
	}
	else this.scrollLayer.clip = "rect("+0+"px "+this.x+"px "+this.y+"px "+0+"px)";
	this.ScUp = false;
	this.ScDown = false;
	this.ScLeft = false;
	this.ScRight = false;
	this.i = 0;
}

function ScrollGoUp(){
	clearInterval(this.i);
	if(this.ScUp){
		if(this.clipY > 0){
			this.i = setInterval(this.obj+".fwd()",1);			
		}
	}
}

function ScrollGoDown(){
	clearInterval(this.i);
	if(this.ScDown){
		if(this.clipY < (parseInt(this.height) - this.y)){
			this.i = setInterval(this.obj+".bckwd()",1);
		}
	}
}

function ScrollGoLeft(){
	clearInterval(this.i);
	if(this.ScLeft){
		if(this.clipX > 0){
			this.i = setInterval(this.obj+".lft()",1);
		}
	}
}

function ScrollGoRight(){
	clearInterval(this.i);
	if(this.ScRight){
		if(this.clipX < (parseInt(this.width) - this.x)){
			this.i = setInterval(this.obj+".rght()",1);
		}
	}
}

function ScrollFwd(){
	if(document.layers){
		this.scrollLayer.top += this.speed;
		this.scrollLayer.clip.top -= this.speed;
		this.scrollLayer.clip.bottom -= this.speed;
		this.clipY -= this.speed;
		this.clipY2 -= this.speed;
	}
	else {
		var top = parseInt(this.scrollLayer.top) + this.speed;
		this.scrollLayer.top = (is.ns6)?top + "px":top +" px";
		this.clipY -= this.speed;
		this.clipY2 -= this.speed;
		this.scrollLayer.clip = "rect("+this.clipY+"px "+this.clipX2+"px "+this.clipY2+"px "+this.clipX+"px)";
	}
	this.goUp();
}

function ScrollBkwd(){
	if(document.layers){
		this.scrollLayer.top -= this.speed;
		this.scrollLayer.clip.top += this.speed;
		this.scrollLayer.clip.bottom += this.speed;
		this.clipY += this.speed;
		this.clipY2 += this.speed;
	}
	else {
		var top = parseInt(this.scrollLayer.top) - this.speed;
		this.scrollLayer.top = (is.gecko)?top +"px":top + " px";
		this.clipY += this.speed;
		this.clipY2 += this.speed;
		this.scrollLayer.clip = "rect("+this.clipY+"px "+this.clipX2+"px "+this.clipY2+"px "+this.clipX+"px)";
	}
	
	this.goDown();
}

function ScrollLft(){
	if(document.layers){
		this.scrollLayer.left += this.speed;
		this.scrollLayer.clip.left -= this.speed;
		this.scrollLayer.clip.right -= this.speed;
		this.clipX -= this.speed;
		this.clipX2 -= this.speed;
	}
	else {
		var left = parseInt(this.scrollLayer.left) + this.speed;
		this.scrollLayer.left = (is.ns6)?left + "px":left + " px";
		this.clipX -= this.speed;
		this.clipX2 -= this.speed;
		this.scrollLayer.clip = "rect("+this.clipY+"px "+this.clipX2+"px "+this.clipY2+"px "+this.clipX+"px)";
	}
	this.goLeft();
}

function ScrollRght(){
	if(document.layers){
		this.scrollLayer.left -= this.speed;
		this.scrollLayer.clip.left += this.speed;
		this.scrollLayer.clip.right += this.speed;
		this.clipX += this.speed;
		this.clipX2 += this.speed;
	}
	else{
		var left = parseInt(this.scrollLayer.left) - this.speed;
		this.scrollLayer.left = (is.gecko)?left + "px":left + " px";
		this.clipX += this.speed;
		this.clipX2 += this.speed;
		this.scrollLayer.clip = "rect("+this.clipY+"px "+this.clipX2+"px "+this.clipY2+"px "+this.clipX+"px)";
	}

	this.goRight();
}

function ScrollSetOnTop(){
	while(this.clipY > 0){
		if(document.layers){
			this.scrollLayer.top += this.speed;
			this.scrollLayer.clip.top -= this.speed;
			this.scrollLayer.clip.bottom -= this.speed;
			this.clipY -= this.speed;
			this.clipY2 -= this.speed;
		}
		else{
			var top = parseInt(this.scrollLayer.top) + this.speed;
			this.scrollLayer.top = top +" px";
			this.clipY -= this.speed;
			this.clipY2 -= this.speed;
			this.scrollLayer.clip = "rect("+this.clipY+"px "+this.clipX2+"px "+this.clipY2+"px "+this.clipX+"px)";
		}
	}
	
}

function ScrollSetOnLeft(){
	while(this.clipX > 0){
		if(document.layers){
			this.scrollLayer.left += this.speed;
			this.scrollLayer.clip.left -= this.speed;
			this.scrollLayer.clip.right -= this.speed;
			this.clipX -= this.speed;
			this.clipX2 -= this.speed;
		}
		else{
			var left = parseInt(this.scrollLayer.left) + this.speed;
			this.scrollLayer.left = left + " px";
			this.clipX -= this.speed;
			this.clipX2 -= this.speed;
			this.scrollLayer.clip = "rect("+this.clipY+"px "+this.clipX2+"px "+this.clipY2+"px "+this.clipX+"px)";
		}
	}
	
}

function ScrollStop(){
	this.ScUp = false;
	this.ScDown = false;
	this.ScLeft = false;
	this.ScRight = false;
}

function ScrollUp(){
	this.ScUp = true;
	this.goUp();
}

function ScrollDown(){
	this.ScDown = true;
	this.goDown();
}

function ScrollLeft(){
	this.ScLeft = true;
	this.goLeft();
}

function ScrollRight(){
	this.ScRight = true;
	this.goRight();
}

//Function Definition
	Scroll.prototype.up = ScrollUp;
	Scroll.prototype.down = ScrollDown;
	Scroll.prototype.left = ScrollLeft;
	Scroll.prototype.right = ScrollRight;
	Scroll.prototype.goUp = ScrollGoUp;
	Scroll.prototype.goDown = ScrollGoDown;
	Scroll.prototype.goLeft = ScrollGoLeft;
	Scroll.prototype.goRight = ScrollGoRight;
	Scroll.prototype.setOnTop = ScrollSetOnTop;
	Scroll.prototype.setOnLeft = ScrollSetOnLeft;
	Scroll.prototype.fwd = ScrollFwd;
	Scroll.prototype.bckwd = ScrollBkwd;
	Scroll.prototype.lft = ScrollLft;
	Scroll.prototype.rght = ScrollRght;
	Scroll.prototype.stop = ScrollStop;