// Declare global variables
var W3CDOM = (document.createElement && document.getElementsByTagName);
var headerImageElement = '';
var originalHeaderImageSrc = '';
var nav = '';
var mouseOvers = new Array();
var mouseClicks = new Array();

// Add the onLoad event to the page
window.onload = init;

function init()
{
	// Test the broswer supports the WC3 DOM
	if (!W3CDOM) return;
	// Store the pages original header image src/location
	headerImageElement = document.getElementById('headerimage');
	originalHeaderImageSrc = headerImageElement.src;
	nav = document.getElementById('nav');
	// Locate the block of images to work with
	var block1 = document.getElementById('allthumbs');
	if (block1) {
		var imgs = block1.getElementsByTagName('img');
		// Iterate through the images in the block
		for (var i=0;i<imgs.length;i++)
		{
			// Add the events to the images
			imgs[i].onmouseover = mouseGoesOver;
			imgs[i].onmouseout = mouseGoesOut;
			imgs[i].onclick = mouseGoesClick;
			// Remove the title stating the image click will open in a new window, as since the javascript and DOM are supported, and we're mousing over here instead, it won't
			// If the DOM is supported and javascript is on, and the user uses the keyboard to select the link - it will open in a new window
			imgs[i].title = '';
			// Get the image suffix (.gif, .jpg, etc)
			var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
			// Preload the larger header images
			mouseOvers[i] = new Image();
			mouseOvers[i].src = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_header" + suffix;
			mouseClicks[i] = imgs[i].src.substring(0,imgs[i].src.lastIndexOf('.')) + "_popup" + suffix;
			imgs[i].number = i;
		}
	}
	var block2 = document.getElementById('credits');
	if (block2) {
		var imgs = block2.getElementsByTagName('img');
		// Iterate through the images in the block
		for (var i=0;i<imgs.length;i++)
		{
			// Add the event to the images
			imgs[i].onclick = mouseGoesClick;
			// replace the word credit with popup
			mouseClicks[i] = imgs[i].src.replace(/credit/gi, "popup");
			imgs[i].number = i;
		}
	}
	
}

function mouseGoesOver()
{
	// When the user moves over a thumb, display it's larger header image as the main header
	headerImageElement.src = mouseOvers[this.number].src;
	//nav.style.display = 'none';
}

function mouseGoesOut()
{
	// When the user moves off the thumbs, replace the original header image
	headerImageElement.src = originalHeaderImageSrc;
	//nav.style.display = 'block';
}

function mouseGoesClick()
{
	// When the user clicks on an image, the click should be caught and a prefered window-size opened
	// Where javascript is not on or the browser does not support the DOM the click will not be caught, and the underlying HREF will allow the user to open a new window and see the image
	// alert(mouseClicks[this.number]);
	newwindow = window.open('photo.asp?photo=' + mouseClicks[this.number],'photo','height=328,width=700,top=20,left=20,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no')
	if (window.focus) {newwindow.focus()}
	return false;
}	
	
function validatePaymentTypeSelected(which_form)	
{
	if(which_form == 'single')
	{
		if (document.single_form.os0.value == 0)
			alert('Please select the payment type')
		else
			document.single_form.submit();
	}		
	if(which_form == 'couple')
	{
		if (document.couple_form.os0.value == 0)
			alert('Please select the payment type')
		else
			document.couple_form.submit();
	}		
	if(which_form == 'mixed')
	{
		if (document.mixed_form.os0.value == 0)
			alert('Please select the payment type')		
		else
			document.mixed_form.submit();
	}
}



