var rotator = 
{
	rotatorDiv : null,
	rotatorInitialized : null,
	rotatorInterval : null,
	rotatorIntervalValue : 5000,
	paused : false,
	
	switcher : function ()
	{
		if (!this.paused)
		{
			var $active = $(this.rotatorDiv+' li.active');
			if ( $active.length == 0 ) $active = $(this.rotatorDiv+' li:last');
			var $next =  $active.next().length ? $active.next() : $(this.rotatorDiv+' li:first');
			$active.addClass('last-active');

			$next.css({
				opacity: 0.0
			});
			if ($next.hasClass("custom"))
			{
				if ($next.hasClass("playable"))
				{
					var $customContent = $next.find("div.customContent");
					$customContent.bind("click", function(e)
					{
						e.preventDefault();
						rotator.paused = true;
					});
				}

				$next.find("iframe").animate({
					opacity:1.0
				}, 1500);

			}

			$next.addClass('active')
			.animate({
				opacity: 1.0
			}, 1500, function() {
				rotator.slideTitle($next);
				$active.removeClass('active last-active');
			});
		}
	},

	slideTitle : function($active)
	{
		if ($active.find('.slidingText').length>0)
		{
			var $slidingText = $active.find('.slidingText');
			var $titleFrame = $('div.activeText').html($slidingText.html());
			var activeTextLeft = $titleFrame.css("left");
			$titleFrame.show();
			$titleFrame.animate({
				left: 0
			},2750, 'linear',function(){
				$titleFrame.fadeOut(2750, function(){
					$titleFrame.css({
						left:activeTextLeft
					})
				});
			});
		}
	},

	stopRotator : function ()
	{
		window.clearInterval(this.rotatorInterval);
	},

	rotatorInit : function (rotatorDiv)
	{
		if (this.rotatorInitialized == null)
		{
			this.rotatorDiv = rotatorDiv;
			$(this.rotatorDiv).bind("mouseover",function(){
				rotator.stopRotator();
			}).bind("mouseout", function(){
				if (!rotator.paused)
					rotator.rotate(rotator.rotatorIntervalValue, rotator.rotatorDiv);
			});
			this.rotatorInitialized = true;
			return true;
		}
		else return true;
	},

	rotate : function(interval, rotatorDiv)
	{
		if (this.rotatorInit(rotatorDiv))
		{
			if (interval > 1000)
				this.rotatorIntervalValue = interval;
			this.rotatorInterval = setInterval( "rotator.switcher()", this.rotatorIntervalValue );
		}
	}

}


