/****
** Ticker class (pseudo-js-class)
*
* string: ObjectId - id for the ticker object (div or what ever)
*
** public properties
* integer: Speed - speed of the ticker (60)
* integer: Repeat - multiplies the ticker (12)
* integer: Limit - times to run (4)
* integer: Direction [top,right,bottom,left] - times to run (left)
* string: separator - string to clue the repeat
*   ("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
*
** public methods
* play, pause, rewind, toggle
*
**example:
* var JsStockticker = new Ticker ( "StockTicker" );
* JsStockTicker.play();
**/

function Ticker ( ObjectId, Separator )
{
	/*** public methods ***/
	// start ticker
	this.play = function ()
	{
		if ( this.Direction == 'right' || this.Direction == 'bottom' )
		{
			if ( Math.abs ( Pos ) == 0 )
			{
				Pos = TextObj.offsetWidth;
				if ( ++CountRuns >= this.Limit )
				{
					this.rewind ();
					return;
				}
			}
			eval ( "TextObj.style." + this.Direction + " = --Pos + 'px'" );
		}
		else
		{
			if ( Math.abs ( Pos ) > TextObj.offsetWidth )
			{
				Pos = 0;
				if ( ++CountRuns >= this.Limit )
				{
					this.rewind ();
					return;
				}
			}
			eval ("TextObj.style." + this.Direction + " = --Pos + 'px'" );
		}
		var _this = this; // trick for pseudo OO-JS
		Running = true;
		Timeout = window.setTimeout ( function() { _this.play (); }, this.Speed );
	}
	// pause ticker
	this.pause = function ()
	{
		Running = false;
		window.clearTimeout ( Timeout );
	}
	// reset ticker
	this.rewind = function ()
	{
		Running 					= false;
		Pos 						= 0;
		TextObj.style.left 	= Pos + 'px';
		CountRuns 					= 0;
		window.clearTimeout ( Timeout );
	}
	// switch between play/pause ticker
	this.toggle = function ()
	{
		if ( this.Running )
			this.pause ();
		else
			this.play ();
	}
	// initialize
	this.init = function ()
	{
		var tempTickerText 			= '';
		var tempSeparator 			= '';
		for ( var i = 0; i < this.Repeat; i++ )
		{
			tempTickerText+= tempSeparator + ObjHTML;
			tempSeparator = '<span class="TickerSeparator">' + this.Separator + '</span>';
		}
		Obj.innerHTML = "<span>" + tempTickerText + "</span>";
		Obj.onmouseover 				= function () { _this.pause (); };
		Obj.onmouseout 					= function () { _this.play (); };
		Obj.style.position 			= 'relative';
		Obj.style.overflow 			= 'hidden';
		TextObj									= Obj.getElementsByTagName("span")[0];
		TextObj.style.position 	= 'relative';
	}

	/*** public vars ***/
	// interval time (speed)
	this.Speed 							= 60;
	// multiplier
	this.Repeat 						= 12;
	// multiplier
	this.Limit 							= 4;
	// interval time (speed)
	this.Direction					= "left";
	// separator
	this.Separator 					= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

	/*** private part ***/
	// try to get object id
	if ( ObjectId )
		var id = ObjectId;
	else
	{
		this.error = "Object id not given"
		return false;
	}
	
	// starting position
	var Pos 								= 0;
	var Running							= false;
	var Timeout;
	var CountRuns						= 0;
	var Obj 								= document.getElementById ( id );
	var ObjHTML       			= Obj.innerHTML;
	// duplicate ticker based on TickerRepeat
	this.init ();
	// add special properties
	var _this 							= this; // trick for pseudo OO-JS
	var TextObj							= Obj.getElementsByTagName("span")[0];
}


  // Funktion für das Ereignis MouseOut bei dem Film
  function FilmOut ()
  {
    $('BildOver').src = 'images/blank.gif';
    $('BildOver').setStyle ({ border: 'none'});
  }

  // Funktion für das Ereignis MouseOver bei dem Film
  function BildShowOnClick ( source, XOffset, YOffset, Border )
  {
    $('BildOver').setStyle ({ border: '2px solid #518b58'});
		try
		{
    	$('BildOverLayer').style.left = event.clientX - XOffset;
    	$('BildOverLayer').style.top = event.clientY - 50 + document.body.scrollTop + YOffset;
    }
		catch ( e )
		{
	    $('BildOverLayer').style.left = '25px';
	    $('BildOverLayer').style.top = '25px';
		}
    eval ( '$("BildOver").src = "' + source + '"' );
  }
