function slideshow(width, height, border_width, speed, step) {
	this.i_height = height;
	this.i_width = width;
	this.i_border = border_width;
	this.i_images = Array();
	this.i_speed = speed;
	this.i_step = step;
	
	this.i_pos = 0;
}

slideshow.prototype.addImage = function(image) {
	this.i_images[this.i_images.length] = image;
	return image;
}

slideshow.prototype.timeTrigger = function() {
	if (this.i_pause != true && this.i_drag != true) {
		this.i_pos+=(this.i_step);
		if (this.i_pos >= 0) {
			this.i_pos = this.i_start;
		}
		this.i_images[0].getImage().style.left = this.i_pos + "px";
	}
}

slideshow.handleMouseOver = function(e) {
	this.i_show.i_pause = true;
}

slideshow.handleMouseOut = function(e) {
	this.i_show.i_pause = false;
}

slideshow.handleMouseDown = function(e) {
	this.i_show.i_drag = true;
	this.i_show.i_l = CursorTracker.i_notify.length;
	CursorTracker.i_notify[this.i_show.i_l] = slideshow.prototype.handleDrag;
	CursorTracker.i_menu_item[this.i_show.i_l] = this.i_show;
	slideshow.i_bck = document.body.onmouseup;
	slideshow.i_show = this.i_show;
	slideshow.i_start_x = CursorTracker.getX();
	slideshow.i_start_pos = this.i_show.i_pos;
	document.body.onmouseup = slideshow.handleMouseUp;
}

slideshow.prototype.handleDrag = function(e) {

	var x = CursorTracker.getX();

	this.i_pos=slideshow.i_start_pos + (x - slideshow.i_start_x);

	if (this.i_pos >= 0 || this.i_pos <= (2 * this.i_start)) {
		this.i_pos = this.i_start;
		slideshow_i_start_pos = x;
	}
	this.i_images[0].getImage().style.left = this.i_pos + "px";
}

slideshow.handleMouseUp = function(e) {
	document.body.onmouseup = slideshow.i_bck;
	
	slideshow.i_show.i_drag = false;
	CursorTracker.i_notify.splice(slideshow.i_show.i_l, 1);
	CursorTracker.i_menu_item.splice(slideshow.i_show.i_l, 1);
	
	if (slideshow.i_bck != undefined) {
		slideshow.i_bck(e);
	}
}


slideshow.prototype.getSlideshow = function() {
	if (this.i_slideshow == undefined) {
		this.i_start = -1 * (this.i_images.length * (this.i_width + this.i_border));
	
		this.i_slideshow = document.createElement('DIV');
		this.i_slideshow.style.height = this.i_height + "px";
		this.i_slideshow.style.overflow = "hidden";
		this.i_slideshow.i_show = this;
		this.i_slideshow.onmouseover = slideshow.handleMouseOver;
		this.i_slideshow.onmouseout = slideshow.handleMouseOut;
		this.i_slideshow.onmousedown = slideshow.handleMouseDown;
		var m = this.i_images.length;
		// Double the images
		for (var g = 0; g < 2; g++) {
			for (var x = 0; x < m; x++) {
				this.i_images[this.i_images.length] = new slideshowImage(this.i_images[x].i_url);
			}
		}
		
		// Add them to the slideshow
		var q = this.i_slideshow;
		for (var x = 0; x < this.i_images.length; x++) {
			this.i_images[x].getImage().style.paddingLeft = (this.i_width + this.i_border) + "px";
			q.appendChild(this.i_images[x].getImage());
			q = this.i_images[x].getImage();
			q.style.height = this.i_height + "px";
		}
		q.innerHTML = "&nbsp;";
		
		
		this.i_images[0].getImage().style.position = "relative";
		this.i_images[0].getImage().style.left = "-" + Math.floor(((this.i_width + this.i_border) * this.i_images.length) / 2) + "px";
		
		this.i_pos = this.i_start;
		
		var me = this;
		setInterval(function() {
			me.timeTrigger();
		}, this.i_speed);
	}
	return this.i_slideshow;
}

function slideshowImage(image_url) {
	this.i_url = image_url;
}

slideshowImage.prototype.getImage = function() {
	if (this.i_image == undefined) {
		this.i_image = document.createElement('DIV');
		this.i_image.style.backgroundRepeat = "no-repeat";
		this.i_image.style.backgroundPosition = "0px 0px";
		this.i_image.style.backgroundImage = "url(" + this.i_url + ")";
	}
	return this.i_image;
}