$$.Rotator = function(obj)
{
	this.obj		= obj;
	this.id 		= 'ok';
	this.rate		= 5;
	this.limit		= 0;
	this.banners	= [];
	this.current	= 0;
	this.stopped 	= false;
	obj.rotator		= this;
	
	this.addBanner = function(id, link, imageSrc, text)
	{
		this.banners.push({			
				'link': 	link,
				'text':		text, 
				'imageSrc':	imageSrc, 
				'id': 		id});
		var i = document.createElement('img');
		i.src = imageSrc;
		i.onload = function()
		{
			this.loaded = true; 
		}
	}
	
	
	this.change = function(el)
	{
		$(this.obj).animate({ opacity: "hide" }, "slow");
		if(!el)
		{
			var el = this.banners[this.current];
		}
		var exe=this;
		setTimeout(	function()
			{
				exe.show(el);
			},
			500);
	}
	
	this.fixEvent = function(type, bannerId)
	{
		
	}
	
	this.initTimer = function()
	{
		var exe	= this;
		setTimeout(
				function()
				{
					if(!exe.stopped)
					{						
						exe.current + 1 < exe.banners.length ? exe.current++ : exe.current = 0;
						exe.change();
					}
				},
				this.rate * 1000
			);
	}
	
	this.left = function()
	{
		this.stopped = true;
		this.current > 0 ? this.current-- : this.current = this.banners.length - 1;
		this.show(this.banners[this.current]);
	}
	
	this.right = function()
	{
		this.stopped = true;
		this.current + 1 < this.banners.length ? this.current++ : this.current = 0;
		this.show(this.banners[this.current]);
	}
	
	this.run = function(id)
	{
		if(id)
		{
			for(var i=0; i<this.banners.length; i++)
			{
				if(this.banners[i].id==id)
				{
					this.current = i;
					break;
				}
			}
		}
		this.show(this.banners[this.current]);
	}
	
	this.show = function(el, startFlag)
	{
		var exe 	= this;
		var anchor 	= $(this.obj).find('a')[0];
		if(anchor)
		{
			anchor.onclick = function()
			{
				exe.fixEvent(1, el.id);				
			}
			anchor.href = el.link;
		}
		var img = $(this.obj).find('img')[0];
		if(img)
		{
			img.src = el.imageSrc;
			img.alt = img.altText = el.alt;
			if(startFlag)
			{
				$(this.obj).css('display', '');
			}
			else
			{
				$(this.obj).animate({ opacity: "show" }, "slow");
			}
		}
		this.fixEvent(0, el.id);
		this.initTimer();
	}
	
	
	return this;
}
