/*
Author:		Topper Lu
Date:		2001-06-01
Version:	1.0
Require:	core.js
*/

function Message(text, href, target) {
	this.text = text || null;
	this.href = href || null;
	this.target = target;
}

Message.prototype.onclick = function() {
	if (this.href && this.target) {
		window.open(this.href, this.target);
	}
}

function MessageDisplayer(allMessages, x0, y0, w, h, fontSize, fontColor, timeout_1, timeout_2) {
	this.allMessages = allMessages || null;
	this.x0 = x0 || 0;
	this.y0 = y0 || 0;
	this.width = w || 400;
	this.height = h || 20;
	this.fontSize = fontSize || 12;
	this.fontColor = fontColor || '#000000';
	this.timeout_1 = timeout_1 || 150;
	this.timeout_2 = timeout_2 || 2000;
	//-- Do not change following datas --//
	this.messageContainer = null;
	this.messageIndex = -1;
	this.messagePosition = 0;
	this.index = MessageDisplayer._Instances.length;
	MessageDisplayer._Instances[this.index] = this;
	if (!this.allMessages) {
		this.allMessages = new Array();
		this.allMessages[0] = new Message("This is a Topper's MessageDisplayer JavaScript.", null, null);
	}
}

MessageDisplayer.prototype.draw = function() {
	document.write('<div style="position:absolute;left:'+this.x0+'px;top:'+this.y0+'px;width:'+this.width+'px;height:'+this.height+'px;border-width:0px;margin:0px;padding:0px;">');
	document.write('<span id="messageContainer_'+this.index+'"');
	document.write(' onclick="MessageDisplayer.onclick('+this.index+')"');
	document.write(' style="border-width:0px;margin:0px;padding:0px;font-size:'+this.fontSize+'px;line-height:'+this.height+'px;vertical-align:baseline;cursor:pointer;cursor:hand;color:'+this.fontColor+';"');
	document.write('></span></div>');
	this.messageContainer = getObj('messageContainer_'+this.index);
}

MessageDisplayer.prototype.showMessage = function() {
	if (this.messagePosition == 0) {
		if (++this.messageIndex == this.allMessages.length) {
			this.messageIndex = 0;
		}
	}
	var currMessage = this.allMessages[this.messageIndex];
	this.messageContainer.innerHTML = currMessage.text.substring(0, this.messagePosition);
	var timeout = this.timeout_1;
	if (++this.messagePosition > currMessage.text.length) {
		this.messagePosition = 0;
		timeout = this.timeout_2;
	}
	window.setTimeout('MessageDisplayer.showMessage('+this.index+')', timeout);
}

MessageDisplayer._Instances = new Array();

MessageDisplayer.showMessage = function(index) {
	MessageDisplayer._Instances[index].showMessage();
}

MessageDisplayer.onclick = function(index) {
	var messageDisplayer = MessageDisplayer._Instances[index];
	messageDisplayer.allMessages[messageDisplayer.messageIndex].onclick();
}
