	// CREATIONAL
	
	// COPYRIGHT  : 2005-2009 : CREATIONAL : WWW.CREATIONAL.NL : ALL RIGHTS RESERVED
	
	// JAVASCRIPT : Stock Ticker Scripts
	
	// COPYRIGHT  :	Doron Rosenberg, doronr@gmx.net and Bob Clary, Netscape Communications, 2001



	/* 	Stock Ticker.js 
		Version 0.2

		This script animates a ticker consisting of a parent element containing a sequence of child nodes, 
		the parent element is shifted to the left by shiftBy pixels every interval ms.
		As the second visible child node reaches the left of the screen, the first is appended to the end of the parent's children.

		See http://devedge.netscape.com/toolbox/examples/2001/stock-ticker/

		Change Log: Version 0.1 	Doron Rosenberg, August 1, 2001
            						- Initial Contribution
            
            		Version 0.2 	Bob Clary, August 1, 2001
									- Added runId property and removed run property, 
									- Removed animate() method since start() handles functionality
            						- Fixed problems with calling start() multiple times creating multiple threads resulting in an apparent speed up of the Ticker.

		Constructor CL_Ticker(name, id, shiftBy, interval)

		Methods
		=======
		CL_Ticker.start()
			   starts the animation of the Ticker
			   
		CL_Ticker.stop()
			   stops the animation of the Ticker
			   
		CL_Ticker.changeInterval(newinterval)
			   changes the shifting interval to newinterval

		Properties
		==========
		CL_Ticker.name
			String : name of global variable containing reference to the ticker object.
		
		CL_Ticker.id
			String : id of the element containing the Ticker data (= parent of child nodes),
		
		CL_Ticker.shiftBy
			Number : Number of pixels to shift the Ticker each time it fires.
			
		CL_Ticker.interval
			Number : Number of millisecond intervals between times Ticker fires
			
		CL_Ticker.runId
			Number : Value returned from setTimeout or null if the Ticker is not running
					 
		CL_Ticker.elm
			HTMLElement : Reference to element containing the Ticker data (= parent of child nodes)
		  
	*/

	function CL_Ticker(name, id, shiftBy, interval, direction) {
		
		if (!document.getElementById(id)) { return; } 
		
		this.name     = name;
		this.id       = id;
		this.shiftBy  = shiftBy ? shiftBy : 1;
		this.interval = interval ? interval : 100;
		this.direction = direction ? direction : 'h';
		this.runId	= null;

		this.elm = document.getElementById(id);

		// remove extra textnodes that may separate the child nodes of the Ticker

		var node = this.elm.firstChild;
		var next;

		while (node)  {
			next = node.nextSibling;
    		if (node.nodeType == 3) { this.elm.removeChild(node); }
    		node = next;
  		}

		if (this.direction !== 'h') {

			this.top = 0;
  			this.shiftTopAt = this.elm.firstChild.offsetHeight;
	  		this.elm.style.height = 2 * screen.availHeight + 'px';


		} else {
			
			this.left = 0;
  			this.shiftLeftAt = this.elm.firstChild.offsetWidth;
	  		this.elm.style.width = 2 * screen.availWidth + 'px';
		}

		this.elm.style.visibility = 'visible';

	}

	function CL_StartTicker() {
  		
		this.stop();
		
		if (this.direction !== 'h') {
		
			this.top -= this.shiftBy;
	
			if (this.top <= -this.shiftTopAt) {
				
				this.top = 0;
				this.elm.appendChild(this.elm.firstChild);  
				this.shiftTopAt = this.elm.firstChild.offsetHeight;
			}
	
			this.elm.style.top = (this.top + 'px');
		
		} else {
		
			this.left -= this.shiftBy;
	
			if (this.left <= -this.shiftLeftAt) {
				
				this.left = 0;
				this.elm.appendChild(this.elm.firstChild);  
				this.shiftLeftAt = this.elm.firstChild.offsetWidth;
			}
	
			this.elm.style.left = (this.left + 'px');

		}

  		this.runId = setTimeout(this.name + '.start()', this.interval);
	}

	function CL_StopTicker() {
		
		if (this.runId) { clearTimeout(this.runId); }
    	this.runId = null;
	}

	function CL_ChangeTickerInterval(newinterval) {

	  	if (typeof(newinterval) == 'string') { newinterval =  parseInt('0' + newinterval, 10); }
		if (typeof(newinterval) == 'number' && newinterval > 0) { this.interval = newinterval; }
    
	    this.stop();
    	this.start();
	}

	/* Prototypes for CL_Ticker */
	CL_Ticker.prototype.start = CL_StartTicker;
	CL_Ticker.prototype.stop = CL_StopTicker;
	CL_Ticker.prototype.changeInterval = CL_ChangeTickerInterval;
