var uid = new Date().getTime();
var flashProxy = new FlashProxy(uid, 'flash/flashgateway.swf');
var image;

window.onload = function() {
	// Get the total number of images
	base = document.getElementsByTagName("div")[8];
	total = base.getElementsByTagName("div").length;
	// Select the appropriate image, if there is a permalink
	var loc = window.location.toString();
	var direct = loc.indexOf('&');
	if(direct != -1) {
			var numPath = loc.split('&');
			var img = (numPath[1].charAt(numPath[1].length-1))-1;
			image = img;
	} else {
			image = 0;
	}
	highlight(image);
	flashProxy.call('startUp', total-1, image);
}
function goToImage(num) {
		flashProxy.call('goToImage', num);
}
function nextImage() {
	flashProxy.call('goToNextImage');
}
function previousImage() {
	flashProxy.call('goToPrevImage');
}
function toggle(dir) {
	flashProxy.call('toggleDisplay', dir);
}
function highlight(img, switcher) {
	if (switcher == "switch") {
		switchButton("pause");
	}
	var targetDiv = base.getElementsByTagName("div")[img];
	var targetLink = targetDiv.getElementsByTagName("a")[0].className = "selected";
	// Unhighlight previous image
	if (image != img) {
		unhighlight(image);
	}
	// Reassign image vars to new value
	image = img;
}
function unhighlight(img) {
	var targetDiv = base.getElementsByTagName("div")[img];
	var targetLink = targetDiv.getElementsByTagName("a")[0].className = "";
}
function debugMsg(string) {
	alert(string);
}