// JavaScript Document

// Multiple Slideshows with Captions
// copyright 30th July 2008 by Stephen Chapman
// http://javascript.about.com
// permission to use this Javascript on your web page is granted
// provided that all of the code below in this script (including these
// comments) is used without any alteration
function SlideShow(id,w,h,a) {
	
	var self = this;
	
	self.x = 0;
	self.h = new Image();
	self.h.src = a[1].img; 
	self.a = a;
	self.c = a.length;
	self.pre = id;
	self.id = document.getElementById(id);

	var i = document.createElement('img');
	
	i.id = self.pre+'img';
	i.style.w = w + 'px';
	i.style.h = h + 'px'; 
	i.alt = 'slideshow gallery';
	i.src = a[0].img;self.id.appendChild(i);
	self.id.appendChild(document.createElement('br'));

	var t = document.createTextNode(a[0].caption);

	var c = document.createElement('span');
	
	c.id = self.pre+'cap';
	c.appendChild(t);
	self.id.appendChild(c);
	self.id.appendChild(document.createElement('br'));
	t = document.createTextNode('< ');
	
	var p = document.createElement('span');
	
	p.appendChild(t);
	p.style.color = '#FFFFFF';
	p.style.cursor = 'pointer';
	
	p.onclick = function() {self.prevImg(self);};
	
	self.id.appendChild(p);
	t = document.createTextNode(' >');

	var n = document.createElement('span');
	
	n.appendChild(t);
	n.style.color = '#FFFFFF';
	n.style.cursor = 'pointer';
	
	n.onclick = function() {self.nextImg(self);};
	
	self.id.appendChild(n);
	
	return self;
	
}; 
	
	
SlideShow.prototype.update = function(self) {
		
	document.getElementById(self.pre+'img').src = self.a[self.x].img;
	
	var t = document.createTextNode(self.a[self.x].caption);
	var c = document.createElement('span');
	
	c.id = self.pre+'cap';
	c.appendChild(t);
	
	var sc = document.getElementById(self.pre+'cap');
	
	sc.parentNode.replaceChild(c,sc);

};
	
	
SlideShow.prototype.nextImg = function(self) {
	
	self.x++;
	if (self.x >= self.c) self.x = 0; 
	if (self.a[self.x+1]) self.h.src = self.a[self.x+1].img; 
	self.update(self);
	
}; 
	
	
SlideShow.prototype.prevImg = function(self) {
	
	self.x--;
	if (self.x < 0) self.x = self.c-1; 
	self.update(self)
	
;}