var currentIndex = 0;
var imageCache = [];

function NextImage() {
	if(currentIndex < image_set.length - 1) {
		currentIndex++;
		Updateimages();
	}
}
function PrevImage() {
	if(currentIndex > 0) {
		currentIndex--;
		Updateimages();
	}
}
function Updateimages() {
	var img_prev = document.getElementById('img_prev');
	var img_next = document.getElementById('img_next');
	var img_left = document.getElementById('img_left');
	var img_right = document.getElementById('img_right');
	var img_enlarge = document.getElementById('img_enlarge');
	var p_caption = document.getElementById('p_caption');

	if(currentIndex == 0) {
		img_left.style.display = 'none';
		img_prev.style.display = 'none';
	} else {
		img_left.style.display = '';
		img_prev.style.display = '';
		img_left.src = '_' + image_set[currentIndex - 1].src;
		img_left.alt = img_left.title = image_set[currentIndex - 1].title;
	}

	if(currentIndex == image_set.length - 1) {
		img_right.style.display = 'none';
		img_next.style.display = 'none';
	} else {
		img_right.style.display = '';
		img_next.style.display = '';
		img_right.src = '_' + image_set[currentIndex + 1].src;
		img_right.alt = img_right.title = image_set[currentIndex + 1].title;
	}

	img_enlarge.src = image_set[currentIndex].src;
	img_enlarge.alt = p_caption.innerHTML = image_set[currentIndex].title;

}
function InitAlbum() {
	var i, count, html, temp, startFrame;

	// Start in the middle if picture defined
	temp = window.location.href.split('pic=');
	startFrame = (temp.length == 2 ? temp[1] : '');

	count = 0;
	for(i in image_set) {
		imageCache[i] = new Image();
		imageCache[i].src = image_set[i].src;
		if(startFrame == image_set[i].src) { currentIndex = count; }
		count++;
	}

	html = ''
		+ '<div id="div_left"><img alt="" id="img_left" onclick="PrevImage()" src="/images/alpha.gif" alt="" /></div>'
		+ '<div id="div_enlarge"><img alt="" id="img_enlarge" onclick="NextImage()" src="/images/alpha.gif" alt="" /><p id="p_caption">&nbsp;</p></div>'
		+ '<div id="div_right"><img alt="" id="img_right" onclick="NextImage()" src="/images/alpha.gif" alt="" /></div>'
		+ '<div id="div_prev"><img alt="Previous Image" title="Previous Image" id="img_prev" onclick="PrevImage()" src="/images/album_prev.png" alt="" /></div>'
		+ '<div id="div_next"><img alt="Next Image" title="Next Image" id="img_next" onclick="NextImage()" src="/images/album_next.png" alt="" /></div>'
		+ '';
	document.getElementById('div_container').innerHTML = html;
	Updateimages();
}
function LoadAlbum(folder, filename) {
	var url = folder + '/?pic=' + filename;
	var strWidth = screen.availWidth;
	var strHeight = screen.availHeight;
	var tools = 'resizable,toolbar=no,location=no,scrollbars=no,width=' + strWidth + ',height=' + strHeight + ',left=0,top=0';
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}
