// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();
var is_gecko = (agt.indexOf('gecko') != -1); // firefox
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));


var current_id = 0;
var max_id = null;
var expanded_thumbs = 0;

function loadPhoto(img_id)
{	
	img_object = document.getElementById("ctlImage" + img_id);

	if (document.getElementById("ctlImage" + current_id) != null)
		document.getElementById("ctlImage" + current_id).style.cssText = "border: 5px solid #007BCE;";
		
	new_src = img_object.src.replace('/thumb', '');
	img = new Image();
	img.src = new_src;
	document.getElementById('ctlPhoto').src = img.src;
	img_object.style.cssText = "border: 5px solid #FFFF00;"; // IE + FireFox compatible :-) The World is at peace

	current_id = img_id;
}

function previousPhoto()
{		
	setMax();
	id = current_id - 1;
	if (id == -1)
		id = max_id;
		
	loadPhoto(id);
}

function nextPhoto()
{
	setMax();
	id = current_id + 1;
	if (id > max_id)
		id = 0;
		
	loadPhoto(id);	
}

function setMax()
{
	if (max_id == null) // work out the max for the first time
	{
		thumb_imgs = document.getElementById("image_thumbs").getElementsByTagName("img");
		max_id = thumb_imgs.length - 1;
	}
}

function expandThumbs(height)
{
	if (expanded_thumbs == 0)
	{
		document.getElementById("image_thumbs").style.cssText = "overflow: none;";
		expanded_thumbs = 1;
	}
	else
	{
		document.getElementById("image_thumbs").style.cssText = "overflow: auto; height: " + height + "px;";
		expanded_thumbs = 0;		
	}				
}

function email(name, text)
{
	name += "@brightondancediversion.com";
	if (text == "") 
		text = name;
	document.write('<a href="ma' + 'ilto:' + name + '">' + text + '</a>');
}

function confirm_delete(url)
{
	if (confirm("Are you sure you want to delete?"))
		document.location = url;
}
