var isIE = (document.all)?true:false;
var Vitesse = 2;

function scroll_Obj() {}

scroll_Obj.prototype.init = function(layer, varName) {
	var p = document.getElementById("parent" + layer);
	var c = document.getElementById("content" + layer);
	if ( isIE ) {
		this.clipWidth = parseInt(p.currentStyle.width);
		this.clipHeight = parseInt(p.currentStyle.height);
	} else {
		this.clipWidth = parseInt(p.offsetWidth);
		this.clipHeight = parseInt(p.offsetHeight);
	}
	this.srcTop = parseInt(p.offsetTop);
	this.contentHeight = parseInt(c.offsetHeight);
	this.top = this.srcTop;
	this.clipTop = 0;
	this.layer = layer;
	this.name = varName;
	this.bScroll = false;
}

scroll_Obj.prototype.scroll = function(iDirection) {
	var p = document.getElementById("parent" + this.layer);
	if ( (iDirection == -1) && ((this.clipTop - iDirection*Vitesse + this.clipHeight) >= this.contentHeight) ) {
		this.top = this.srcTop-(this.contentHeight-this.clipHeight);
		this.clipTop = this.contentHeight-this.clipHeight;
} else if ( (iDirection == 1) && ((this.clipTop - iDirection*Vitesse) <= 0) ) {
		this.top = this.srcTop;
		this.clipTop = 0;
	} else {
		this.top = this.top + iDirection*Vitesse;
		this.clipTop = this.clipTop - iDirection*Vitesse;
	}
	
	p.style.clip = "rect(" + this.clipTop + "px, " + this.clipWidth + "px, " + (this.clipHeight+this.clipTop) + "px, 0px)";
	p.style.top = this.top + "px";
}

scroll_Obj.prototype.scrollUp = function(bScroll) {
	if ( arguments.length > 0 ) {
		this.bScroll = bScroll;
	}
	this.scroll(1);
	if ( this.bScroll ) {
		this.Timer = setTimeout(this.name + ".scrollUp();",1);
	}
}

scroll_Obj.prototype.scrollDown = function(bScroll) {
	if ( arguments.length > 0 ) {
		this.bScroll = bScroll;
	}
	this.scroll(-1);
	if ( this.bScroll ) {
		this.Timer = setTimeout(this.name + ".scrollDown();",1);
	}
}

scroll_Obj.prototype.scrollStop = function() {
	this.bScroll = false;
}

scroll_Obj.prototype.scrollTo = function(y) {
	var p = document.getElementById("parent" + this.layer);
	if ( (this.contentHeight-y) < this.clipHeight ) {
		y = this.contentHeight-this.clipHeight;
	} else if ( y < 0 ) {
		y = 0;
	}
	this.top = this.srcTop - y;
	this.clipTop = y;

	p.style.clip = "rect(" + this.clipTop + "px, " + this.clipWidth + "px, " + (this.clipHeight+this.clipTop) + "px, 0px)";
	p.style.top = this.top + "px";
}

