
(function( pb, $ )
{
	pb.tickerBar = function ()
	{
		this.tickerObject = null;
		this.scrollSize = 0;
		this.countItems = 0;
		this.scrollTimer = 0;
		this.scrollCounter = 0;
	}
	
	pb.tickerBar.prototype = 
	{
			register : function( tickerObject )
			{
				if(typeof( tickerObject ) != "object")
				{
					alert("TickerObject is not a object!")
				}
				else
				{
					var thisObject = this;

					tickerObject.show();
					
					this.tickerObject = tickerObject;
					this.countItems = this.tickerObject.find("li").length;
					this.scrollSize = 27; //(tickerObject.find(".content").get(0).scrollHeight / this.countItems );
				
					this.tickerObject.find("li a").bind("mousedown", function(){ return false; });	
					this.tickerObject.find("li a").bind("mouseover", function(){ thisObject.stopScroll( true ); } );	
					this.tickerObject.find("li a").bind("mouseout", function(){ if( $("table#ipopup").css("display") != "table"){ thisObject.stopScroll( false ); } } );	
					//this.tickerObject.find("li a").bind("click", this.moreInfo);	
					
					tickerObject.hide();
					
					delete thisObject;
				}
				
				delete tickerObject;
			}
			
		,	show : function()
			{
				var thisObject = this;
					thisObject.tickerObject.fadeIn();
					thisObject.tickerObject.find(".content").get(0).scrollTop = 0;
					thisObject.scrollTimer = setTimeout( function(){ thisObject.scroll(); }, 2000);		
				
				delete thisObject;
			}
			
		,	hide : function()
			{
				clearInterval(this.scrollTimer);
				clearTimeout(this.scrollTimer);
				
				this.scrollCounter = 0;
				this.tickerObject.hide();
			}
			
		,	scroll : function()
			{
				var thisObject = this;
				var scrollObject = thisObject.tickerObject.find(".content").get(0);
					thisObject.scrollCounter++;
					thisObject.scrollTimer = setInterval(function()
					{
						if(scrollObject.scrollTop == (thisObject.scrollCounter*thisObject.scrollSize) )
						{
							if(scrollObject.scrollTop == (scrollObject.scrollHeight-thisObject.scrollSize))
							{
								thisObject.scrollCounter = 0;			
								scrollObject.scrollTop = 0;
							}
							
							clearInterval(thisObject.scrollTimer);
							
							thisObject.scrollTimer = setTimeout( function(){ thisObject.scroll(); }, 2000);
						}
						else
						{							
							scrollObject.scrollTop += 1;
						}
		
					}, 25);
					
				
				delete thisObject, scrollObject;
			}
			
		,	stopScroll : function( stop )
			{
				var thisObject = this;
			
				if( stop )
					clearInterval(this.scrollTimer);
				else
					this.scrollTimer = setTimeout( function(){ thisObject.scroll(); }, 2000);
					
				delete 	thisObject;
			}
			
		,	moreInfo : function()
			{
				alert("Popup window");
				
				return false;
			}
	}
	
})( Pluxbox, jQuery );