/* objecte Ticker que instanciarem per mostrar un ticker diferent cada vegada */
function Ticker(name, width, height, speed, color, pause) {
	this.name = name || "";
	this.width = width || "300px";
	this.height = height || "25px";
	this.speed = speed || 2;
	this.bgcolor = color || "#DEFDD9";
	this.pauseit = (pause) ? 1 : 0;
	this.content = '<nobr><font face="Arial"><a href="http://cometatech.com">Cometa Techonologies</a></font></nobr>';
	this.speed = (document.all)? this.speed : Math.max(1, this.speed - 1);
	this.copyspeed = this.speed;
	this.pausespeed = (this.pauseit == 0)? this.copyspeed: 0;
	this.iedom = document.all || document.getElementById;	
	this.actualwidth = '';
	this.crossTicker;
	this.nsTicker;
	/* funcions */
	this.populate = populate;
	this.scroll = scroll;
	this.print = print;
}

/* funcio que inicia el despla?ament */
function populate() {
	if (this.iedom) {		
		this.crossTicker = document.getElementById? document.getElementById("ieTicker_" + this.name) : eval('document.all.ieTicker_' + this.name);
		this.crossTicker.style.left = parseInt(this.width) + 8 + "px";
		this.crossTicker.innerHTML = this.content;
		this.actualwidth = document.all? eval('temp_' + this.name + '.offsetWidth') : document.getElementById("temp_" + this.name).offsetWidth;				
	} else if (document.layers)	{
		this.nsTicker = eval('document.nsTicker_' + this.name + '.document.nsTicker2_' + this.name);
		this.nsTicker.left = parseInt(this.width) + 8;
		this.nsTicker.document.write(this.content);
		this.nsTicker.document.close();
		this.actualwidth = this.nsTicker.document.width;
	}
	this.lefttime = setInterval(this.name + ".scroll()", 20);
}

/* funcio que fa l'scroll del ticker */
function scroll() {
	if (this.iedom) {
		if (parseInt(this.crossTicker.style.left) > (this.actualwidth * (-1) + 8)) {
			this.crossTicker.style.left = parseInt(this.crossTicker.style.left) - this.copyspeed + "px";
		} else {
			this.crossTicker.style.left = parseInt(this.width) + 8 + "px";
		}
	} else if (document.layers)	{
		if (this.nsTicker.left > (this.actualwidth * (-1) + 8))	{
			this.nsTicker.left -= this.copyspeed;
		} else {
			this.nsTicker.left = parseInt(this.width) + 8;
		}
	}
}

/* funcio que imprimeix el ticker */
function print() {	
	if (this.iedom) {
		document.write('<span id="temp_' + this.name + '" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">' + this.content + '</span>');
	}
	if (this.iedom || document.layers) {
		with (document)	{
			document.write('<table border="0" cellspacing="0" cellpadding="0"><td>');
			if (this.iedom)	{
				write('<div style="position:relative;width:' + this.width + ';height:' + this.height + ';overflow:hidden">');
				write('<div style="position:absolute;width:' + this.width + ';height:' + this.height + ';background-color:' + this.bgcolor + '" onMouseover="' + this.name + '.copyspeed=' + this.name + '.pausespeed" onMouseout="' + this.name + '.copyspeed=' + this.name + '.speed">');
				write('<div id="ieTicker_' + this.name + '" style="margin-top:1px; position:absolute;left:0px;top:0px"></div>');
				write('</div></div>');
			} else if (document.layers)	{
				write('<ilayer width=' + this.width + ' height=' + this.height + ' name="nsTicker_' + this.name + '" bgColor=' + this.bgcolor + '>');
				write('<layer name="nsTicker2_' + this.name + '" left=0 top=0 onMouseover="' + this.name + '.copyspeed=' + this.name + '.pausespeed" onMouseout="' + this.name + '.copyspeed=' + this.name + '.speed"></layer>');
				write('</ilayer>');
			}
			document.write('</td></table>');
		}
	}
}