
var ejs_array_ = new Array();

function ejs() {
	
	this.id 			= ejs_array_.length;
	this.mode 			= 1;
	this.nb_message 	= 0;
	this.img_src 		= null;
	this.img_width 		= 0;
	this.hauteur 		= 40;
	this.largeur 		= 200;
	this.pause_seconde 	= 2;
	this.speed			= 5;
	this.actuel 		= 0;
	this.className		= 'ejs_scroll';
	this.timeout 		= null;
	
	this.pause 			= false;		// Says if pause possible (0:no, 1:yes) when onmouseover/out
	this.paused			= false;		// Says if is in pause or not
	
	this.message 		= new Array();
	
	ejs_array_.push(this);
	eval('document.body.ejs_'+this.id+' = this');
	
}

ejs.prototype.add_line = function (str_) 
{
	this.message.push(str_);
	this.nb_message = this.message.length-1;	
};

ejs.prototype.display =  function () 
{
	document.write('<DIV ID="ejs_scroll_relativ_'+this.id+'" STYLE="border:solid 0px red;position:relative;width:'+(this.largeur)+';height:'+(this.hauteur)+'">');
	if(this.img_src != null) 
		document.write('<IMG src="'+this.img_src+'">');
	document.write('<DIV ID="ejs_scroll_cadre_'+this.id+'"	 STYLE="border:solid 0px yellow;position:absolute;width:'+(this.largeur-2-this.img_width)+';height:'+(this.hauteur-2)+';top:1;left:'+(this.img_width > 0 ? this.img_width + 2 : 1)+';clip:rect(0 '+(this.largeur-2)+' '+(this.hauteur-2)+' 0)">');
	document.write('<DIV ID="ejs_scroller_'+this.id+'_1"	 CLASS="'+this.className+'" STYLE="border:solid 0px white;position:absolute;'+this.style+'width:'+(this.largeur-2-this.img_width)+';left:0;top:0;">'+this.message[this.actuel]+'</DIV>');
	document.write('<DIV ID="ejs_scroller_'+this.id+'_2"	 CLASS="'+this.className+'" STYLE="border:solid 0px black;position:absolute;'+this.style+'width:'+(this.largeur-2-this.img_width)+';left:0;top:'+this.hauteur+';">'+this.message[this.suivant]+'</DIV>');
	document.write('</DIV></DIV>');
	if(this.pause) {
		
		document.getElementById('ejs_scroll_relativ_'+this.id).onmouseover = new Function ('ejs_array_['+this.id+'].ejs_scroll_pause();');
		document.getElementById('ejs_scroll_relativ_'+this.id).onmouseout  = new Function ('ejs_array_['+this.id+'].ejs_scroll_pause();');
	}
};

ejs.prototype.ejs_scroll_start = function  ()
{
	if(this.mode == 1)
	{
		this.scroller_haut = document.getElementById('ejs_scroller_'+this.id+'_1');
		this.scroller_bas  = document.getElementById('ejs_scroller_'+this.id+'_2');
		this.mode = 0;
	}
	else
	{
		this.scroller_bas  = document.getElementById('ejs_scroller_'+this.id+'_1');
		this.scroller_haut = document.getElementById('ejs_scroller_'+this.id+'_2');
		this.mode = 1;
	}
	
	if(this.actuel == this.nb_message)		this.suivant = 0;
	else									this.suivant = this.actuel+1;
	
	this.top = 0;
	this.scroller_bas.innerHTML = this.message[this.suivant];
	this.timeout = window.setTimeout('ejs_array_['+this.id+'].ejs_scroll_action()', this.pause_seconde * 1000, 'JavaScript')
};

ejs.prototype.ejs_scroll_action = function  ()
{
	this.top -= 1;
	this.scroller_haut.style.top = this.top;
	this.scroller_bas.style.top  = this.top + this.hauteur;
	if((this.top + this.hauteur) > 0)
		this.timeout = window.setTimeout('ejs_array_['+this.id+'].ejs_scroll_action()', this.speed, 'JavaScript')
	else
		ejs_array_[this.id].ejs_scroll_stop();
};

ejs.prototype.ReturnId = function () {
	return (this.id);
};

ejs.prototype.ejs_scroll_stop = function () 
{
	this.actuel = this.suivant;
	ejs_array_[this.id].ejs_scroll_start();
};

ejs.prototype.ejs_scroll_pause = function () {
	//alert(this.timeout +' ++++ '+ this.paused);
	if (this.timeout != null && !this.paused) {
		//alert('  1   ' + this.timeout);
		this.timeout = window.clearTimeout(this.timeout);
		this.timeout = null;
		this.paused = true;
	}
	else if(this.timeout == null && this.paused) {
		//alert('  2   ' + this.timeout);
		this.timeout = window.setTimeout('ejs_array_['+this.id+'].ejs_scroll_action()', this.speed, 'JavaScript')
		this.paused = false;
	}
}

window.onload = function () {
	for(var i_=0;i_<ejs_array_.length;i_++)
		if(ejs_array_[i_].message.length>1) 
		 	ejs_array_[i_].ejs_scroll_start(); 
}; 
