﻿var Slide = Class.create();
Slide.prototype = {
initialize: function(id, width) {

	this.action = "stop";
	this.id = id;
	this.width = width;
	
	
	},
	
	stop: function() {
		this.action="stop";
	},

	goLeft: function() {
		this.action="left";
		this.left();
	},
	
	goRight: function() {
		this.action="right";
		this.right();
	},
	
	left: function() {
		var th = this;
		this.sum = parseInt( $(this.id).getStyle('left') ) + $(this.id).getWidth() - this.width;
	
		if( this.sum < 0)  {
			this.stop();
		} else {
			$(this.id).style.left = parseInt($(this.id).getStyle('left'))-15+'px';

			if(this.action=='left') {	
				setTimeout(function () { th.left(); },50);
			}
		}
		
	},


	right: function () {
		var th = this;
		if( parseInt( $(this.id).getStyle('left') ) >= 0) {
			this.stop();
		} else {
		
			$(this.id).style.left = parseInt($(this.id).style.left)+15+'px';
		
			if(this.action=='right') {
				setTimeout(function () { th.right(); }, 50);
			}
		}
		
	}

}



