function Slide(id, orientation, title, w, h)
{
	this.ID = id;
	this.Orientation = orientation;
	this.Title = title;
	this.Width = w;
	this.Height = h;
}

var slides = new Array();

var imageindex = 0;
var playshow = true;
var playtimer = null;
var timeout = 5000;

function DisplayLargeImage() 
{ 
	if(slides[imageindex].ID > 0)
		window.open('gallerylarge.asp?id=' + slides[imageindex].ID + '&title=' + slides[imageindex].Title + '&w=' + slides[imageindex].Width + '&h=' + (slides[imageindex].Height + 20), 'gallerylarge', 'WIDTH=' + slides[imageindex].Width + ', HEIGHT=' + (slides[imageindex].Height + 20) + ', SCROLLBARS=NO');
	
	return false; 
}

function PreviousImage()
{
	StopSlideShow();
	
	if(imageindex > 0)
		SetSlide(slides[--imageindex]);
	
	return false;
}

function NextImage()
{
	StopSlideShow();
	
	if(imageindex < (slides.length - 1))
		SetSlide(slides[++imageindex]);
	
	return false;
}

function StartSlideShow()
{
	imageindex = (imageindex < (slides.length - 1)) ? imageindex + 1 : 0;
	
	SetSlide(slides[imageindex]);
	
	if(playshow)
		playtimer = setTimeout(StartSlideShow, timeout);
}

function StopSlideShow()
{
	playshow = false;
	playtimer = clearTimeout(playtimer);
}

function SetSlide(slide)
{
	document.getElementById('slide').style.backgroundPosition = (slide.Orientation == 1) ? '43px center' : '13px center'
	
	if(slide.ID > 0)
		document.getElementById('slide').style.backgroundImage = 'url(\'img/galleries/thumbs/' + slide.ID + '.jpg\')';
	else
		document.getElementById('slide').style.backgroundImage = 'url(\'img/galleries/noslide.gif\')';
		
	document.getElementById('slideshow').style.backgroundImage = 'url(' + ((slide.Orientation == 1) ? 'img/galleries/slide_p.gif' : 'img/galleries/slide_l.gif') + ')';
}

window.onload = function() 
{
	if(document.getElementById('slide'))
	{
		document.getElementById('slide').onclick = DisplayLargeImage;
		document.getElementById('prevslide').onclick = PreviousImage;
		document.getElementById('nextslide').onclick = NextImage;
		
		SetSlide(slides[0]);
		
		playtimer = setTimeout(StartSlideShow, timeout);
	}
}