/**
 *	Scroller Item
 */

function ScrollObject ( text, link, ttl ) {

	if ( ttl == "_blank" ){
		this.text = "<div style='line-height:" + ( itemHeight + 10 ) + "px; width: " + itemWidth + " ;height:" + itemHeight + "; overflow:hidden'><a href='" + link + "' target='_blank'>" + text + "</a></div>";

	}
	else{
		this.text = "<div style='line-height:" + ( itemHeight + 10 ) + "px; width: " + itemWidth + " ;height:" + itemHeight + "; overflow:hidden'><a href='" + link + "'>" + text + "</a></div>";
	}
	this.next = null;

	this.print = DrawObject;
}

function DrawObject () {

	document.write ( this.text );	
}

function setItemWidth(itemWidth){
  this.itemWidth = itemWidth
}

function setLayerWidth(layerWidth){
  this.layerWidth = layerWidth
}

/**
 *	Scroller
 */
//var itemWidth = 240;
var itemWidth = 234;
var itemHeight = 20;
//var layerWidth = 270;
var layerWidth = 228;
//var layerWidth = 240
//var layerHeight = 100;
var layerHeight = 100;
var itemsHeight = 0;

var scrollHeight = 4;
var scrollTime = 30;
var stopTime = 5000;
var currentTop = 0;
var movingHeight = 0;

var rootObject = null;
var mouseState = "off";

function CreateObject ( text, link, ttl ) {
	
	var temp = new ScrollObject ( text, link, ttl );
	
	if ( rootObject == null ) {

		rootObject = temp;
		rootObject.next = temp;
	
	} else {

		var current = rootObject;
		
		for ( var i=0 ; current.next != rootObject ; i++ )
			current = current.next;

		current.next = temp;

		temp.next = rootObject;
	}

	itemsHeight += itemHeight;

}




function DrawCommonScroller () {

	document.write ( "<div style='overflow:hidden; width:" + layerWidth + "; height:" + layerHeight + "' onMouseOver=\"mouseState='on'\" onMouseOut=\"mouseState='off'\">" );
	
	document.write ( "<div id='contentLayer' style='position:relative; left:5; top:" + currentTop + ";'>" );
	DrawObjects ( "ds01" );
	DrawObjects ( "ds02" );
	DrawObjects ( "ds03" );
	DrawObjects ( "ds04" );
	document.write ( "</div>" );
	
	document.write ( "</div>" );
}

function DrawObjects ( id ) {

	document.write ( "<div id='" + id + "'>" );

	rootObject.print ();
	var current = rootObject.next;
		
	for ( var i=0 ; current != rootObject ; i++ ) {
		
		current.print ();
		current = current.next;
	}

	document.write ( "</div>" );

}

function MoveScroller () {

	if ( mouseState != "on" ) {

		currentTop -= scrollHeight;
		movingHeight += scrollHeight;
		
		if ( ( itemsHeight + currentTop ) == 0 )
			currentTop += itemsHeight;
		
		document.all.contentLayer.style.top = currentTop;
		
		if ( movingHeight >= layerHeight ) {
	
			movingHeight = 0;
			setTimeout ( "MoveScroller()", stopTime );
	
		} else {
	
			setTimeout ( "MoveScroller()", scrollTime );
		}

	} else {
		
		setTimeout ( "MoveScroller()", scrollTime );
	}
}
