// Copyright (C) 2002-2004 WEBCOM a.s.
// All rights reserved.

var selector = 0;
var timer 	 = new Array();
var position = new Array();
//--------------------------

function IR_Scroller(speed, width, height){
	this.selector   = selector;
	this.itemsCount = 0;
	this.items 		= new Array();
	this.speed 		= speed;
	this.movingStep	= 1;
	this.width 		= width;
	this.height 	= height;
	this.bgColor	= "white";
	//-----------------------------

	this.addItem = function(itemText){
		this.items[this.itemsCount] = itemText;
		this.itemsCount++;
	}
	
	this.create = function(){
		with(document){
			open();
			write("<div name='scroller"+ this.selector +"' id='scroller"+ this.selector +"' style='overflow: hidden; width:" + this.width + "pt; height:"+ this.height +"px'>");
			write("<div name='scrContent"+ this.selector +"' id='scrContent"+ this.selector +"' style='position: relative; left:0; top:0; width:" + this.width + "pt; height:"+ this.height +"px'>");
			for(i = 0; i !=  this.items.length; i++)
			{
				write("<div>"+ this.items[i] +"</div>");
			}
			write("</div>");
			write("</div>");
			close();
		}
		position[selector] = 0;
		selector++;
	}
	
	this.goDown = function(){
		goDown(this.movingStep, this.speed, this.selector);
	}
	
	this.goUp = function(){
		goUp(this.movingStep, this.speed, this.selector);
	}
	
	this.stop = function(){
		stopMoving(this.selector);
	}
}


function goDown(step, speed, selector){
	stopMoving(selector);
	timer[selector] = window.setInterval("down("+ step +", "+ selector +")", speed);
}

function goUp(step, speed, selector){
	stopMoving(selector);
	timer[selector] = window.setInterval("up("+ step +", "+ selector +")", speed);
}

function down(step, selector){
	document.getElementById("scrContent"+ selector).style.top = position[selector] +"px";
	position[selector] += step;
	if(document.getElementById("scrContent"+ selector).style.top == document.getElementById("scroller"+ selector).style.height){
		position[selector] = (document.getElementById("scrContent"+ selector).offsetHeight * -1);
	}
}

function up(step, selector){
	document.getElementById("scrContent"+ selector).style.top = position[selector] +"px";
	position[selector] -= step;
	if(document.getElementById("scrContent"+ selector).style.top == (document.getElementById("scrContent"+ selector).offsetHeight * -1)+"px"){
		position[selector] = parseInt(document.getElementById("scroller"+ selector).style.height.replace("px",""));
	}
}

function stopMoving(selector){
	window.clearInterval(timer[selector]);
}