function megaSlider(cW,cC,cI,sC)
{  
  this.caseWidth = cW;
  this.caseCount = cC; 
  this.containerId = cI;
  this.showingCount = sC;
  this.isMoving = false;
  this.interval = '';
  this.currentCase = 0;
  widthTotal = (cW * cC) + 10;
  $("#" + this.containerId).css('width',widthTotal + 'px');
  this.putInterval = function(timing,speed,direction) {
    var self = this;
    this.interval =  setInterval(function(){ self.scrollIt(speed,direction); }, timing);
  };
  this.removeInterval = function() {
   clearInterval(this.interval);
  };
  this.gotoSlide = function(slide_id){
   this.removeInterval();
   this.currentCase = slide_id;  
   $("#" + this.containerId).animate({ left: this.currentCase * this.caseWidth * -1 }, 1000,function(){ this.isMoving = false;});
  }
  this.scrollIt = function(speed,direction){
   if(!this.isMoving){
      switch(direction){
        case 'left':
          if(this.currentCase >= this.caseCount - this.showingCount){ this.currentCase = 0;}else{this.currentCase = this.currentCase + 1; }
        break;
        case 'right':
          if(this.currentCase == 0){ this.currentCase = this.caseCount - this.showingCount;}else{this.currentCase = this.currentCase - 1; }
        break;
      }
      $("#" + this.containerId).animate({ left: this.currentCase * this.caseWidth * -1 }, speed,function(){ this.isMoving = false;});
   }
  };
}  

