function imageMoveLeft(width, space, containerId, speed){
    var container = document.getElementById(containerId);
    var innerContainer = container.parentNode;
    var excursion = 0;
  	if(width >= space){
	    excursion = space;
		width -= space;
	}else{
	    excursion = width;
		width = 0;
	}
	// TODO check scrollLeft.
	var scrollLeft = innerContainer.parentNode.scrollLeft;
	var scrollWidth = container.scrollWidth;
	if(scrollLeft >= scrollWidth){
	    innerContainer.parentNode.scrollLeft = 0;
	}

    innerContainer.parentNode.scrollLeft = innerContainer.parentNode.scrollLeft + excursion;

	if(width!=0){
		setTimeout("imageMoveLeft(" + width + ', ' + space + ", '" + containerId +  "')", speed);
	}
}

function imageMoveRight(width, space, containerId, speed){
    var container = document.getElementById(containerId);
    var innerContainer = container.parentNode;
    var excursion = 0;
  	if(width >= space){
	    excursion = space;
		width -= space;
	}else{
	    excursion = width;
		width = 0;
	}
	
	var scrollLeft = innerContainer.parentNode.scrollLeft;
	var scrollWidth = container.scrollWidth;
	
	
	
	if(scrollLeft == 0){
	    innerContainer.parentNode.scrollLeft = scrollWidth;
	}

    innerContainer.parentNode.scrollLeft = innerContainer.parentNode.scrollLeft - excursion;

	if(width!=0){
		setTimeout("imageMoveRight(" + width + ', ' + space + ", '" + containerId +  "')", speed);
	}
}

Scroller = function(containerId, leftButtonId, rightButtonId){
    this.container = document.getElementById(containerId);
    
    this.leftButton = document.getElementById(leftButtonId);
	this.rightButton = document.getElementById(rightButtonId);
    
    this.space = 5;
	this.speed = 1;
	this.scrollWidth = 120;
	
    this.initFlag = false;
	
		this.leftButton.scroller = this;
        this.leftButton.onclick = this.scrollLeft;

        this.rightButton.scroller = this;
        this.rightButton.onclick = this.scrollRight;


	
}

Scroller.prototype={
    init : function() {
	 
	 
	     if(this.isInit())
		      return;
	
	
	
				
			this.containerWidth = this.container.parentNode.parentNode.offsetWidth;
	 
        if(this.isScroll()){
            var container1 = this.container.cloneNode(true);
			
				
			 this.innerContainer = this.container.parentNode;	

			 
		    this.innerContainer.appendChild(container1);
			 this.initFlag = true;
			
			

			 
			 
		}

                
    },
	 isScroll : function(){
	 
	     return this.container.scrollWidth < this.containerWidth ? false : true;
	 },
	 isInit : function(){
	     return this.initFlag?true : false;
	 },
	scrollLeft : function(){
	
	
	
	     this.scroller.init();
		  
		  
		  
		  
	    if(this.scroller.isScroll())
		    this.scroller.moveLeft(this.scroller.scrollWidth);
        return false;
	},
	moveLeft : function(width){
		this.doMoveLeft(width, this.space, this.innerContainer.parentNode.scrollLeft);
	},
	doMoveLeft : function(width, space, scrollLeft){
        imageMoveLeft(width, this.space, this.container.id, this.speed);
	},
	scrollRight : function(){
	    this.scroller.init();
	    if(this.scroller.isScroll())
		    this.scroller.moveRight(this.scroller.scrollWidth);
        return false;
	},
	moveRight : function(width){
		this.doMoveRight(width, this.space, this.innerContainer.parentNode.scrollLeft);
	},
	doMoveRight : function(width, space, scrollLeft){
        imageMoveRight(width, this.space, this.container.id, this.speed);
	}
};
