
function changeContents(layerId, moveLength, direction, delay) {

   var This = this;

   this.obj = $('#' + layerId)[0];
   this.length = $('#' + layerId).find('>li').length;
   this.moveLength = moveLength;
   this.direction = direction;
   this.delay = delay;
   this.timer = null;

   this.obj.onmouseover = function () { if(This.delay) window.clearInterval(This.timer); }
   this.obj.onmouseout = function () { if(This.delay) This.timer = window.setInterval(function () { eval('This.move' + ((This.direction=='prev')?'Prev':'Next') + '();'); } , This.delay); }

   if((direction=='prev')&&moveLength&&delay) this.movePrev();
   if((direction=='next')&&moveLength&&delay) this.moveNext();

}

changeContents.prototype.getFirstChild = function(obj) {   

   var fObj = obj.firstChild;   

   while(fObj.nodeType!=1) fObj = fObj.nextSibling;     

   return fObj;   

}

changeContents.prototype.getLastChild = function(obj) {   

   var lObj = obj.lastChild;   

   while(lObj.nodeType!=1) lObj = lObj.previousSibling;   
  
   return lObj;   

}

changeContents.prototype.movePrev = function() {   
   
   var This = this;

   if(this.length>this.moveLength) {   

    if((this.delay&&this.timer)||(!this.delay&&!this.timer)) {

     var saveObj = this.getLastChild(this.obj);   
     this.obj.removeChild(this.getLastChild(this.obj));   
     this.obj.insertBefore(saveObj, this.getFirstChild(this.obj));   

	}

   }  
   
   if(this.delay&&(this.timer==null)) this.timer = window.setInterval(function () { This.movePrev(); } , this.delay);

}   

changeContents.prototype.moveNext = function() {   
     
   var This = this;

   if(this.length>this.moveLength) {   

    if((this.delay&&this.timer)||(!this.delay&&!this.timer)) {

     var saveObj = this.getFirstChild(this.obj);   
     this.obj.removeChild(this.getFirstChild(this.obj));   
     this.obj.appendChild(saveObj);   

	}

   }

   if(this.delay&&(this.timer==null)) this.timer = window.setInterval(function () { This.moveNext(); } , this.delay);
   
}  
