// Scroll Object - Eduard Prats

function Scroll(idLayer, clipWidth, clipHeight,width,height,speed){
	this.id = idLayer;
	if (is.ns){ 
		this.scrollLayer = document.layers[idLayer];
	}
	else {
		this.scrollLayer = document.all[idLayer].style;
	}
	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.speedN = speed;
	this.speedQ = this.speedN * 3;
	
	this.obj = idLayer + "Scroll";
	eval(this.obj + "=this");
	
	// Init Clipping
	if (is.ns){
		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.VelScroll = 'N';
	this.speed = 2 ;
	this.i = 0;
}

function ScrollUp(){
	clearInterval(this.i);
	if(this.ScUp){
		if(this.clipY > 0){
			this.i = setInterval(this.obj+".fwd()",1);
		}
	}
}

function ScrollDown(){
	clearInterval(this.i);
	if(this.ScDown){
		if(this.clipY < (parseInt(this.height) - this.y)){
			this.i = setInterval(this.obj+".bckwd()",1);
		}
	}
}

function ScrollLeft(){
	clearInterval(this.i);
	if(this.ScLeft){
		if(this.clipX > 0){
			this.i = setInterval(this.obj+".lft()",1);
		}
	}
}

function ScrollRight(){
	clearInterval(this.i);
	if(this.ScRight){
		if(this.clipX < (parseInt(this.width) - this.x)){
				this.i = setInterval(this.obj+".rght()",1);
		}
	}
}

function ScrollFwd(){
	if(this.VelScroll=='Q') {
		this.speed = this.speedQ ;	
	}
	else{
		this.speed = this.speedN ;	
	}

	if(is.ns){
		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)";
	}
	this.up();
}

function ScrollBkwd(){
	if(this.VelScroll=='Q') {
		this.speed=this.speedQ ;	
	}
	else{
		this.speed=this.speedN ;	
	}	

	if(is.ns){
		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)";
	}
	this.down();
}

function ScrollLft(){
	if(VelScroll='Q') {
		this.speed==this.speedQ ;	
	}
	else{
		this.speed==this.speedN ;	
	}

	if(is.ns){
		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)";
	}
	this.left();
}

function ScrollRght(){
	if(VelScroll='Q') {
		this.speed==this.speedQ ;	
	}
	else{
		this.speed==this.speedN ;	
	}	
	if(is.ns){
		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)";
	}
	this.right();
}

function ScrollSetOnTop(){
	while(this.clipY > 0){
		if(is.ns){
			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(is.ns){
			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 Definition
Scroll.prototype.up = ScrollUp;
Scroll.prototype.down = ScrollDown;
Scroll.prototype.left = ScrollLeft;
Scroll.prototype.right = ScrollRight;
Scroll.prototype.setOnTop = ScrollSetOnTop;
Scroll.prototype.setOnLeft = ScrollSetOnLeft;
Scroll.prototype.fwd = ScrollFwd;
Scroll.prototype.bckwd = ScrollBkwd;
Scroll.prototype.lft = ScrollLft;
Scroll.prototype.rght = ScrollRght;