var lastUsedImageNumber = 0;

function getImageFileName() {

	var IMAGE_PATH = "images/";
	
	var imageFiles = [ "pooles_stretcher_carry.jpg", "dcro_vehicle.jpg", "p4160005.jpg", "p4160007.jpg", "giants_stretcher_carry.jpg", "clip10.jpg", "Clip 1.jpg", "clip2.jpg", "clip5.jpg", "clip8.jpg", "malcolm bailey and DCRO Van.jpg" ];

	var imageFileNum;
	
	do {
		imageFileNum = Math.floor( Math.random() * imageFiles.length );
	} while ( lastUsedImageNumber == imageFileNum );

	lastUsedImageNumber = imageFileNum;

	return IMAGE_PATH + imageFiles[ imageFileNum ];
}

function getInfoText() {

	var text = "DCRO was formed in 1952 and to date has been called out more than 350 " +
			   "times and has gone to the aid of more than 400 people and more than 50 animals.";
	return text;
}

function initPage() {
	setHeaderImageFileNames();
	//setNavigationLinks();
	setInfoText();
	setFooterText();
}

function initHomePage() {
	setInfoText();
}

function setFooterText() {
	
	var FOOTER_TEXT = "&copy; Copyright 2012 Derbyshire Cave Rescue Organisation";

	if ( document.getElementById( "footer" ) ) document.getElementById( "footer" ).innerHTML = FOOTER_TEXT;

}

function setHeaderImageFileNames() {
	if ( document.getElementById( "header_image_left" ) ) {
		document.getElementById( "header_image_left" ).src = getImageFileName();
		document.getElementById( "header_image_left" ).alt = "DCRO in action";
	}

	if ( document.getElementById( "header_image_right" ) ) {
		document.getElementById( "header_image_right" ).src = getImageFileName();
		document.getElementById( "header_image_right" ).alt = "DCRO in action";
	}

	if ( document.getElementById( "header_image_middle" ) ) {
		document.getElementById( "header_image_middle" ).src = "images/dcro_logosmall.jpg";
		document.getElementById( "header_image_middle" ).alt = "DCRO Logo";
	}
}

function setInfoText() {
	if ( document.getElementById( "infoText" ) ) document.getElementById( "infoText" ).innerHTML = getInfoText();
}

function openPage() {

	var password = this.document.testform.inputbox.value;
	var newLocation = password + ".html";
	fetch( newLocation );
}

function fetch( newLocation ) {

	var pageName = "xR1$3dsW";
	if ( newLocation == pageName + ".html" ) {
		location = newLocation;
	} else {
		location = "badpassword.html";
	}
}

