function Slideshow ()
{
	this.MAX_IMAGES		= 6;	// maximum images that will be shown
	this.position		= 0;	// keep track of the latest image
	this.image_holder 	= document.getElementById('slideshow');	// array that holds all images
	this.images = Array();

	if (this.image_holder == null) {
	    return false;
	}

	this.next_button;
	this.previous_button;
	var obj = this;

	var next_button = document.createElement('A');
	next_button.className		= 'next_button';
	next_button.onclick 		=  function()	{obj.showNext();};
	next_button.href			= 'javascript: void(0);';
	
	var previous_button = document.createElement('A');
	previous_button.className	= 'previous_button';
	previous_button.onclick 	=  function()	{obj.showPrevious();};
	previous_button.href		= 'javascript: void(0);';

	this.image_holder.appendChild(next_button);
	this.image_holder.appendChild(previous_button);
	
	this.fetchElements();	// fetch required images and buttons
	
	this.previous_button.style.display = 'none';	// initially hide 'previous-button'

	for(var i = 0; i < this.MAX_IMAGES; i++)
	{	
		if(this.images[i])
		{
			this.images[i].style.display = 'inline';	// show initial images
		}
	}

	this.position = this.MAX_IMAGES - 1;

	if (this.images.length < this.MAX_IMAGES) {
	    this.next_button.style.display = 'none';
	}
}

Slideshow.prototype.fetchElements = function ()
{
	var children = this.image_holder.getElementsByTagName('A');
	var length = children.length;
	
	for(var i = 0; i < length; i++)
	{
		if(children[i].className == 'next_button')
		{
			this.next_button = children[i];
		}
		else if(children[i].className == 'previous_button')
		{
			this.previous_button = children[i];
		}
		else
		{
			this.images[this.images.length] = children[i];
		}
	}
}

Slideshow.prototype.showNext = function ()
{
	this.images[this.position + 1].style.display = 'inline';
	this.images[this.position + (1 - this.MAX_IMAGES)].style.display = 'none';
	this.position++;	// increase image listing by one

	if(this.position == this.images.length - 1)	// if last images are shown, hide 'next-button'
	{
		this.next_button.style.display = 'none';
	}

	if((this.images.length + 1) % (this.position + 1) != 0 || this.position >= this.MAX_IMAGES)	// if first images are NOT shown, show 'previous-button'
	{
		this.previous_button.style.display = 'inline';
	}
}

Slideshow.prototype.showPrevious = function ()
{
	this.images[this.position].style.display ='none';	// hide shown image with highest position
	this.images[this.position - this.MAX_IMAGES].style.display ='inline';	// show previous image
	
	if(this.position > this.images.length - this.MAX_IMAGES)	// if last images are NOT shown, show 'next-button'
	{
		this.next_button.style.display = 'inline';
	}
	
	this.position--;	//	decrease position by one
	
	if(this.position < this.MAX_IMAGES)	// if first images are shown, hide 'previous-button'
	{
		this.previous_button.style.display = 'none';
	}
}

var s = new Slideshow();