ui_scroll = function (instance) {
    this.instance = instance;
};

ui_scroll.prototype = {
    start: function (container, layer, delay, inc) {
        this.inc = inc;
        this.delay = delay;
		this.container = document.getElementById(container);
		this.layer = document.getElementById(layer);
    },
    
    up: function () {
        this.moveV (1);
    },
    
    down: function () {
        this.moveV (-1);
    },
    
    left: function () {
        this.moveH (1);
    },
    
    right: function () {
        this.moveH (-1);
    },
    
    stop: function () {
       clearTimeout(this.timer);  
    },
    
    moveV: function (dir) {
    	height = this.layer.offsetHeight;
    	container_height = this.container.offsetHeight;
    	
    	if (dir==1 && parseInt(this.layer.style.top) < 0) {
    		this.layer.style.top = (parseInt(this.layer.style.top) + (this.inc*dir)) + "px";
    	} else if (dir==-1 && (height + parseInt(this.layer.style.top)) >= container_height) {
    		this.layer.style.top = (parseInt(this.layer.style.top) + (this.inc*dir)) + "px";
    	}
        this.timer = setTimeout(this.instance+".moveV("+dir+")", this.delay);
    },
    
    moveH: function (dir) {
    	width = this.layer.offsetWidth;
    	container_width = this.container.offsetWidth;
    	
    	if (dir==1 && parseInt(this.layer.style.left) < 0) {
    		this.layer.style.left = (parseInt(this.layer.style.left) + (this.inc*dir)) + "px";
    	} else if (dir==-1 && (width + parseInt(this.layer.style.left)) >= container_width) {
    		this.layer.style.left = (parseInt(this.layer.style.left) + (this.inc*dir)) + "px";
    	}
        this.timer = setTimeout(this.instance+".moveH("+dir+")", this.delay);
    }
}