/***************************************************************************************************************
* Function			:	scrolltext.init(containerId, autoTime)
* Description		:	Enable banner framework. Toggle between unfixed numebr of banners.
* Parameter Usage	:	id	:	scroll text container id
*						dt	:	(Optional) time interval in seconds between each banner is shown, default is 5 seconds
* Location			:	/content/hongkongpws/banking/js/scrolltext.js
* Author			:	Mitch Leung
* Creation Date		:	2 July 2009
* Side effect		:	N/A
* Amendment History	:
* Date		By					Description
* ---------	------------	--------------------------------------------------------------------------------
***************************************************************************************************************/
var scrolltext = {
	startInterval:2000,	/* initial delay before text scroll */
	interval:100,		/* override interval if needed */
	timer:null,
	tickerHeight:50,	/* ticker height */
	contentHeight:0,	/* content height */
	roller:null,
	increment:1,		/* vertical movement unit */
	init:function(id,dt){
		if (id==null || id==''){
			return;
		}
		var e = document.getElementById(id);
		if (e){
			if (dt!=null && dt>0){
				this.interval = dt;
			}
			var divs = e.getElementsByTagName('div');
			if (divs.length>0){
				var i=0;
				var origin=null;
				for (i=0;i<divs.length;i++){
					if (divs[i].className=='scrollmessage'){
						origin=divs[i];
						break;
					}
				}
				if (origin!=null){
					this.contentHeight=parseInt(origin.offsetHeight);
					e.style.overflow='hidden';
					e.style.height=e.style.maxHeight=this.tickerHeight+'px';
					if (this.contentHeight>this.tickerHeight){
						/* scroll only when height is taller than screen height */
						this.roller=e;
						this.roller.scrollTop=0;
						/* clone original content */
						var newdiv=document.createElement('div');
						newdiv.innerHTML=origin.innerHTML;
						this.roller.appendChild(newdiv);
						newdiv=null;
						e.onmouseover=function(){
							clearTimeout(scrolltext.timer);
						};
						e.onmouseout=function(){
							clearTimeout(scrolltext.timer);
							scrolltext.timer=setTimeout('scrolltext.autoPilot()',scrolltext.interval);
						};
						this.timer=setTimeout('scrolltext.autoPilot()',this.startInterval);
					}
				}
				i=origin=null;
			}
			divs = null;
		}
		e = null;
	},
	autoPilot:function(){
		clearTimeout(this.timer);
		this.roll();
		this.timer=setTimeout('scrolltext.autoPilot()',this.interval);
	},
	roll:function(){
		this.roller.scrollTop+=this.increment;
		if (this.roller.scrollTop>=this.contentHeight){
			this.roller.scrollTop=0;
		}
	}
};
scrolltext.init('divscroll', 120);
