var Scroller = function(scrollerName, imageID, textID)
{

	var _scrollerName = scrollerName;
	var _imageID = imageID;
	var _textID = textID;
	
	var _thumbnailCount = 0;
	
	var _moveUp = false;
	var _moveDown = false;
	
	var _timer = null;
	
	var _prefix = "scroller-thumbnail";
	
	var _moveSpeed = 15;
	
	this.setMoveSpeed = function(moveSpeed)
	{
		_moveSpeed = moveSpeed;
	};
	
	this.setPrefix = function(prefix)
	{
		_prefix = prefix;
	};
	
	this.startRendering = function()
	{
		_timer  = window.setInterval(tick, 40);
	};


	this.startMoveDown = function()
	{
		_moveDown = true;
	};
	
	this.stopMoveDown = function()
	{
		_moveDown = false;
	};
	
	this.startMoveUp = function()
	{
		_moveUp = true;
	};
	
	this.stopMoveUp = function()
	{
		_moveUp = false;
	};
	
	function moveUp()
	{
		if (_thumbnailCount > 0)
		{
			if ((parseInt(document.getElementById(_prefix+"-"+(_thumbnailCount - 1)).offsetTop) + parseInt(document.getElementById(_prefix+"-"+(_thumbnailCount - 1)).offsetHeight)
				- parseInt(document.getElementById(_scrollerName).offsetHeight)) > 0
			) 
			{
				//Hier geht man die ganzen Unterknoten durch
				for (var i = 0; i < _thumbnailCount; i++)
				{
					var obj = document.getElementById(_prefix + "-" + i);
					
					obj.style.top = (parseInt(obj.style.top) - _moveSpeed) + "px";
			
					
				}
			}
		}
		
	};
	
	
	function moveDown()
	{		
		if (_thumbnailCount > 0)
		{
			if ( (parseInt(document.getElementById(_prefix+"-0").style.top) ) < 0 ) 
			{
			
				//Hier geht man die ganzen Unterknoten durch
				for (var i = 0; i < _thumbnailCount; i++)
				{
					var obj = document.getElementById(_prefix+"-" + i);
					
					obj.style.top = (parseInt(obj.style.top) + _moveSpeed) + "px";
			
					
				}
		
			}
		}
	};
	
	function tick()
	{
		
		if (_moveUp)
		{
			moveUp();
		} else if (_moveDown)
		{
			moveDown();
		}
	};
	
	this.addThumbnail = function(thumbnail, picture, text, title)
	{
		var title_html = "";
		if (title != null && title != "")
		{
			title_html = 'alt="' + title + '"';
		}
		
		var html = '<div onmouseover="this.style.backgroundColor=\'#cacaca\'" onmouseout="this.style.background=\'none\'" class="scroller-thumbnail" style="top:'+((_thumbnailCount*(113 + 20))) +'px;" id="'+_prefix+'-'+_thumbnailCount+'"><a href="javascript: swap(\''+_imageID+'\',\''+picture+'\',\''+_textID+'\',\''+text+'\',\'' + title + '\');"><img ' + title_html + ' src="'+thumbnail+'" /></a></div>';

		
		document.getElementById(_scrollerName).innerHTML = document.getElementById(_scrollerName).innerHTML + html;
		
		_thumbnailCount++;
	};
	
	this.addThumbnailCount = function(count)
	{
			_thumbnailCount+= count;
	};
	
	
	
};
