var Rotator = function (buttonPlayId, buttonStopId, buttonNextId, buttonPrevId, buttonPageNoIdPrefix, frameIdPrefix, totalFrameCount, rotationInterval, useButtons, opacStart, opacEnd, duration){
	this.totalFrames = totalFrameCount;
	this.clearttime = null;
	this.current=0;
	this.btnPlayId=buttonPlayId;
	this.btnStopId=buttonStopId;
	this.btnNextId=buttonNextId;
	this.btnPrevId=buttonPrevId;
	this.btnPageNoIdPrefix = buttonPageNoIdPrefix
	this.framesIdPrefix = frameIdPrefix;
	this.interval = rotationInterval;
	this.useButtons = useButtons;
	this.opacStart = opacStart;
	this.opacEnd = opacEnd;
	this.duration = duration;
}
function start1()
{
	if(this.current < (this.totalFrames+1))
	{
		if ( this.useButtons ) {
			document.getElementById(this.btnPlayId).style.visibility='hidden';
			document.getElementById(this.btnPlayId).style.display='none';
	
			document.getElementById(this.btnStopId).style.display='block';
			document.getElementById(this.btnStopId).style.visibility='visible';
		}

		this.goToFrame(this.current+1);

		var thisObject = this;
		var playMethodDelegate = function () {
			thisObject.play();
		}

		this.clearttime= setTimeout(playMethodDelegate, this.interval);

		if(this.current==this.totalFrames)
		{
			//this.current=1;
			this.current=0;
		}
	}
	else
	{
		if ( this.useButtons ) {	
			document.getElementById(this.btnPlayId).style.visibility='hidden';
			document.getElementById(this.btnPlayId).style.display='none';
			document.getElementById(this.btnStopId).style.display='block';
			document.getElementById(this.btnStopId).style.visibility='visible';
		}
	}

}

function stop1()
{
	with(this) {
		clearTimeout(clearttime);
		
		if ( useButtons ) {
			document.getElementById(btnStopId).style.visibility='hidden';
			document.getElementById(btnStopId).style.display='none';
			document.getElementById(btnPlayId).style.display='block';
			document.getElementById(btnPlayId).style.visibility='visible';
		}
	}

}

function BkActHomeStry(Id)	
  {if(this.current>1)
  	{
	  	if ( this.useButtons ) {
			document.getElementById(this.btnStopId).style.visibility='hidden';
			document.getElementById(this.btnStopId).style.display='none';
			document.getElementById(this.btnPlayId).style.display='block';
			document.getElementById(this.btnPlayId).style.visibility='visible';
		}
		
  		this.goToFrame(Id);
  	}
  }
	 
 function FwActHomeStry(Id)
  {
  	if(this.current<this.totalFrames)
  	{
  		this.goToFrame(Id);
  	}
  }
  
 function ActHomeStry(Id)
  { 
	if ( this.useButtons ) {
		if(Id==this.totalFrames)
		{
			
			document.getElementById(this.btnPrevId).style.visibility='visible';				
			document.getElementById(this.btnNextId).style.visibility='hidden';
			document.getElementById(this.btnStopId).style.visibility='hidden';
			document.getElementById(this.btnStopId).style.display='none';
						
			document.getElementById(this.btnPlayId).style.display='block';
			document.getElementById(this.btnPlayId).style.visibility='visible';		
		}
		else if(Id==1)
		{
			document.getElementById(this.btnNextId).style.visibility='visible';				
			document.getElementById(this.btnPrevId).style.visibility='hidden';				
		}
		else
		{
			document.getElementById(this.btnPrevId).style.visibility='visible';				
			document.getElementById(this.btnNextId).style.visibility='visible';		
		}
	}
	
	var i=1;
	for(i=1;i<=this.totalFrames;i++)
    	{
    		var StryId=this.framesIdPrefix + i
			if ( this.useButtons ) {
				var Container=this.btnPageNoIdPrefix + i
			}

			if(i==Id)
	  		{				
				this.current=i;
	
				if ( this.useButtons ) {
					document.getElementById(Container).className="current";
				}
			
				document.getElementById(StryId).style.visibility='visible';
				document.getElementById(StryId).style.display='block';
				
				var faderObject = new Fader(StryId, this.opacStart, this.opacEnd, this.duration);
				faderObject.play();
			}
	  		else
	  		{
		  		if ( this.useButtons ) 
			  		document.getElementById(Container).className="";
			  		
				document.getElementById(StryId).style.visibility='hidden';
				document.getElementById(StryId).style.display='none';		  
	  		}	
		}	
  }
  
Rotator.prototype.play = start1;
Rotator.prototype.pause = stop1;
Rotator.prototype.moveNextFrame = FwActHomeStry;
Rotator.prototype.movePrevFrame = BkActHomeStry;
Rotator.prototype.goToFrame = ActHomeStry;
