// Scrolling Object
monitors = {};
monitor.speed=2;

function monitor(screenId,movieId,coord) {
	this.id = screenId;
	monitors[this.id] = this;
	this.animString = "monitors."+this.id;
	var myMovie = document.getElementById(movieId);
	var myScreen = document.getElementById(this.id);
	this.y = coord;
	this.maxY = (myMovie.offsetHeight - myScreen.offsetHeight > 0) ? myMovie.offsetHeight - myScreen.offsetHeight : 0;
	this.movieId = movieId;
	this.ready = true;
}
	
monitor.stopScroll = function(screenId) {
  if ( monitors[screenId] ) monitors[screenId].endScroll();
}

// Augmente la vitesse de défilement
monitor.speedUp = function(screenId) {
  if ( monitors[screenId] ) monitors[screenId].speed *= 4;
}

monitor.resetSpeed = function(screenId) {
  if ( monitors[screenId] ) monitors[screenId].speed = monitor.speed;
}

monitor.initScroll = function(screenId, way) {
	if ( monitors[screenId] ) {
		if ( way == "up" ) {
			monitors[screenId].fy = 1;
			monitors[screenId].endY = 0;
		}
		else {
			monitors[screenId].fy = -1;
			monitors[screenId].endY = -monitors[screenId].maxY;
		}
    	monitors[screenId].doScroll();
	}
}

/**********************/
/*                    */
/*     Prototypes     */
/*                    */
/**********************/

monitor.prototype.doScroll = function() {
	if (!this.ready) return;
	if (this.myInterval) clearInterval(this.myInterval);
	
	this.myMovie = document.getElementById(this.movieId);
	this.speed = monitor.speed;
	this.myInterval = setInterval(this.animString + ".changeMoviePosition()", 10); 
}

monitor.prototype.changeMoviePosition = function() {
	var y = this.y + this.fy * this.speed;
	if ( ( this.fy == -1 && y > -this.maxY ) || ( this.fy == 1 && y < 0 ) ) {
		this.myMovie.style.top = (this.y = y) + "px";
	}
	else {
		this.myMovie.style.top = (this.y = this.endY) + "px";
	}
}

monitor.prototype.endScroll = function() {
  if (!this.ready) return;
  if (this.myInterval) clearInterval(this.myInterval);
  this.myInterval = 0;
  this.myMovie = null;
}
  
