var ContentRotator = Class.create( );
ContentRotator.prototype = {
  
  ctr : 0,
  btnPressed : 0,
  t : null,
  currIndex : 0,
  divHide : -1,
  formName : '',
  totRec : 0,
  delay : 5,
  pauseBtnImg : '',
  playBtnImg : '',
  initialize : function(formName,totRec, delay, playBtnImg, pauseBtnImg) {
     this.formName = formName;
     this.totRec = totRec; 
     this.delay = delay;
     this.playBtnImg = playBtnImg;
     this.pauseBtnImg = pauseBtnImg;
  },
  
  decrementCtr : function() {  
    this.currIndex = this.currIndex - 1;  
    
    if (this.currIndex < 0 ) {
      if (this.totRec == 1) {
        this.currIndex = 1;
      } else {
        this.currIndex = this.totRec - 1;
      
      }  
    }
  },
  
  next : function() {
    if (this.t != null) 
      clearTimeout(this.t);
     this.currIndex = this.currIndex + 1;     
     if (this.currIndex >= this.totRec ) {     
       this.currIndex = 0;
      }
  
     var divId_toUpdate = "divId_toUpdate_" + this.formName + "_" + this.currIndex;    
     var currInd = this.currIndex + 1;
     if (this.divHide > -1) {
        var divHiddenId = "divId_toUpdate_" + this.formName + "_" + this.divHide;
        $(divHiddenId).style.display = "none";
        $(divId_toUpdate).style.display = "block";
   
     } else {
        $(divId_toUpdate).style.display = "block";
    
     }
   this.divHide = this.currIndex;
   $("numPage" + this.formName).innerHTML = currInd + "/" + this.totRec;
   this.btnPressed = 1;
   $("PauseBtn" + this.formName).src =  this.playBtnImg;
 },
 
  prev : function() {
  if (this.t != null) 
    clearTimeout(this.t);   
    this.decrementCtr();   
    
    var divId_toUpdate = "divId_toUpdate_" + this.formName + "_" + this.currIndex;     
    var currInd = this.currIndex + 1;  
   if (this.divHide > -1) {
     var divHiddenId = "divId_toUpdate_" + this.formName + "_" + this.divHide;
     $(divHiddenId).style.display = "none";
     $(divId_toUpdate).style.display = "block";
   
    } else {
      $(divId_toUpdate).style.display = "block";    
    }
   this.divHide = this.currIndex;
   $("numPage" + this.formName).innerHTML = currInd + "/" + this.totRec;
   this.btnPressed = 1;
   $("PauseBtn" + this.formName).src =  this.playBtnImg;
  },
  
  browserStop : function() {
    if (this.t != null) 
      clearTimeout(this.t);
    this.btnPressed = 1;    
    $("PauseBtn" + this.formName).src =  this.playBtnImg;
  },
  
  
  clickPauseBtn : function() {
   
    var form_toUpdate= "ContentRotatorForm" + this.formName;  
    //alert(form_toUpdate);
    this.ctr = this.currIndex;
    if (this.btnPressed == 0) {
      if (this.t != null) {
      clearTimeout(this.t);
      this.t= null; 
      }
      this.btnPressed = 1;    
      $("PauseBtn" + this.formName).src =  this.playBtnImg;
    
    } else {   
      this.btnPressed = 0;
      this.showContentDiv();	
      $("PauseBtn" + this.formName).src =  this.pauseBtnImg;
  
    }
  },
 
  incrementCtr : function() {
      
    this.ctr = this.ctr + 1;
    if (this.ctr >= this.totRec ) {
      this.ctr = 0;
    }
  },
  
  showNormalDiv : function() {
  
  var divId_toUpdate = "divId_toUpdate_" + this.formName + "_" + this.ctr;   
  var currInd = this.ctr + 1;
  
    if (this.divHide > -1) {
     var divHiddenId = "divId_toUpdate_" + this.formName + "_" + this.divHide;
     $(divHiddenId).style.display = "none";
     $(divId_toUpdate).style.display = "block";
   
    } else {
      $(divId_toUpdate).style.display = "block";
    }
    this.divHide = this.ctr;
    $("numPage" + this.formName).innerHTML = currInd + "/" + this.totRec;
    this.currIndex = this.ctr;
  
  },
  
  showContentDiv : function() {    
    var methodName = "contObjNew_" + this.formName + ".showContentDiv()";
    this.showNormalDiv();
    this.incrementCtr(); 
    if (this.totRec > 1) {
      this.t=setTimeout(methodName,this.delay);
    }
  }
  
} // end of object declaration

