 /*****
     Author: V.Seshagiri Rao - @fissionlabs
 */
 
 var move = {
         sDiv : null,
         intervels : 1000,
         distance : 100,
         width : 100,
         _step : 0,
         _steps : 0,
         _shown : 0,
         _pow : 1,
         s_steps : 60,
         _smove : null,
         m_stop : 0,
         onLeftEnd:null,
         onRightEnd:null,
         init:function(_move) {
		     
		      var _sDiv = document.getElementById(""+_move.slideDiv);
		      var sDivs = _sDiv.getElementsByTagName("div");
		      this.sDiv = _sDiv;
	          this.intervels = _move.intervels;
	          this.width = _move.width;
	          this.distance = _move.distance;
	          this.s_steps = _move.steps;
	          this._pow = _move.pow;
	          this._shown = Math.round(_move.width/this.distance);
	          this._steps = sDivs.length - this._shown;
	          this.position(sDivs);
	          this.onLeftEnd = _move.onLeftEnd;
	          this.onRightEnd = _move.onRightEnd;
	          this.onMoving = _move.onMoving;
	     },
	     position:function(sDivs) {
	         var left = 0;
	         this.sDiv.style.left = 0+"px";
	         for(i=0;i<sDivs.length;i++) {
	            sDivs[i].style.position = "absolute";
	            sDivs[i].style.display = "block";
	            sDivs[i].style.left = left+"px";
	            left = left + this.distance;
	         }
	          
	     },
         move:function(direction) {
		       
		        if(direction=="left" && this._step < (this._steps)) {
		             
		             
			        this.smoothMove(parseInt(this.sDiv.style.left),direction,0);
			      		         
		        }
		        else if(direction=="right" && this._step > 0) {
		            
			        this.smoothMove(parseInt(this.sDiv.style.left),direction,0);
			        			        
		        }
		     },
		  m_move:function(direction) {
		      if(direction=="left") {
		            if(this._step < (this._steps)) {
		            this.m_stop = 0; 
			        this.smoothMove(parseInt(this.sDiv.style.left),direction,1);
			      	if(this.onMoving)this.onMoving();
			      	}
			      	else{
			      	if(this.onLeftEnd)this.onLeftEnd();
			      	}	         
		        }
		        else if(direction=="right") {
		            if(this._step > 0) {
		            this.m_stop = 0;
			        this.smoothMove(parseInt(this.sDiv.style.left),direction,1);
			        if(this.onMoving)this.onMoving();
			        }
			        else {
			        if(this.onRightEnd)this.onRightEnd();
			        }			        
		        } 
		  }, 
		  
		  stop:function() {
		      this.m_stop=1;
		      
		  },  
		  smoothMove:function(sPos,direction,type){
			  
			  var _ssteps = 0;
			  
			  if (this._smove) return;
			    this._smove = window.setInterval( function(){
				   
				   var _movement = Math.pow(((1 / move.s_steps)*_ssteps),move._pow) * move.distance;
				    
				   var movement = Math.ceil(_movement);
				    
				 
				   move.sDiv.style.left = (direction=="left" ? (sPos - movement) : (sPos + movement))+"px";
				   _ssteps++;
			     	if (_ssteps > move.s_steps) {
			     	window.clearInterval(move._smove); 
			     	move._smove = null;
			     	if(type==1 && move.m_stop==0) {
			        move.m_move(direction);
			         }
			     	
			     	}
				   
			  }
			  ,this.intervels);   
	          
	          if(direction == "left"){
			   ++move._step;
			   }
			   else {
			   --move._step;
			   } 
			   
			   
	          
	          }
     };