var mygallery;

function startImageRotate(){
	mygallery=new fadeSlideShow({
		wrapperid: "homeImageRotator",
		dimensions: [903, 478],
		imagearray: [
			["images/homeImage0.jpg", "spotlight/", "_self"],
			["images/homeImage1.jpg"],
			["images/homeImage2.jpg"],
			["images/homeImage3.jpg"]
		],
		displaymode: {type:'auto', pause:4000, cycles:0, wraparound:true},
		persist: false, 
		fadeduration: 1000,
		descreveal: "none",
		togglerid: "",
		onslide:function(curimage, index){
			var buttonsHTML = imageButtons(index);
			document.getElementById('homeImageButtonWrapper').innerHTML=buttonsHTML;
		}
	})
}


function homepageImageButtonChanger(id){
	mygallery.navigate(parseInt(id));
	
	var buttonsHTML = imageButtons(parseInt(id));
	document.getElementById('homeImageButtonWrapper').innerHTML=buttonsHTML;
}

function imageButtons(id){
	var buttonsHTML = "";
	switch (id){
		case 0:
			buttonsHTML += "<div id=\"homeImageButton\"><a><img src=\"images/homeImageOn.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton0\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('1');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton1\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('2');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton2\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('3');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton3\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
		break;
		case 1:
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('0');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton0\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a><img src=\"images/homeImageOn.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton1\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('2');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton2\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('3');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton3\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
		break;
		case 2:
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('0');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton0\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('1');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton1\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a><img src=\"images/homeImageOn.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton2\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('3');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton3\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
		break;
		case 3:
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('0');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton0\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('1');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton1\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a href=\"javascript:homepageImageButtonChanger('2');\"><img src=\"images/homeImageOff.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton2\" onMouseOver=\"this.src='images/homeImageOn.jpg'\" onMouseOut=\"this.src='images/homeImageOff.jpg'\" /></a></div>";
			buttonsHTML += "<div id=\"homeImageButton\"><a><img src=\"images/homeImageOn.jpg\" width=\"12\" height=\"12\" border=\"0\" id=\"homeButton3\" /></a></div>";
		break;
	}
	
	return buttonsHTML;
}

function contactSubmit(){
	var name = document.getElementById('namer').value;
	var email = document.getElementById('email').value;
	var more = document.getElementById('more').value;
	
	var errorText = "Please complete the ";
	var submit = true;
	
	if (name == ""){
		submit = false;
		
		if (email != "" && more != ""){
			errorText += "name";
		}else{
			errorText += "name, ";
		}
	}
	
	if (email == "" || !isValidEmail(email)){
		submit = false;
		
		if (more != ""){
			if (name != ""){
				errorText += "email";
			}else{
				errorText += "and email";
			}
		}else{
			errorText += "email, ";
		}
	}
	
	if (more == ""){
		submit = false;
		
		if (name != "" && email != ""){
			errorText += "'tell us more'";
		}else{
			errorText += "and 'tell us more'";
		}
	}
	
	errorText += " field(s).";
	
	if (submit == true){
		document.getElementById('contactForm').submit();
	}else{
		document.getElementById('errorText').innerHTML = errorText;
	}
}

function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	if(strEmail.search(validRegExp) == -1){
		return false;
	}
	return true;
}

function changeDisplayMonth(newMonth){
	for (var i = 0; i < 3; i++){
		document.getElementById("month"+i).style.display = "none";
	}

	document.getElementById("month"+newMonth).style.display = "block";
}

var winProps;
function popUpProps(url, width, height, props)
{
	var left = 300;
	var top = 300;
	var propsCentered = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + props;

	winProps = window.open(url, 'AflWindowBlank', propsCentered);
	winProps.focus();
}
