var topVideo = 1;
var maxWidth = 725;
var totalVideos = 0;
var formValues = new Array('name (required)', 'email address (required)', 'street address', 'city, state, zip');
var mailingListAdded = false;

function setupPage()
{
	if (!document.getElementsByTagName)
	{
		return;
	}
	
	var anchors = document.getElementsByTagName("a");
	
	for (var i = 0; i < anchors.length; i++)
	{
		var a = anchors[i];
		
		if (a.getAttribute("href") && a.getAttribute("rel") == "external")
		{
			a.target = "_blank";
		}
	}
	
	var count = 1;
	
	while (document.getElementById("video" + count) != null)
	{
		totalVideos++;
		count++;
	}
	
	if (mailingListAdded)
	{
		var timeout = setTimeout("alert(\"You have now been added to the mailing list.\")", 500);
	}
}

window.onload = setupPage;

function activateVideo(number)
{
	for (var i = topVideo; i <= topVideo + 3; i++)
	{
		var video = document.getElementById("video" + i);
		
		if (i == number)
		{
			if (video.className.indexOf(" active") == -1)
			{
				video.className = video.className + " active";
			}
		}
		else
		{
			video.className = video.className.replace(" active", "");
		}
	}
}

function loadVideo(video, width)
{
	var player = document.getElementById("player");
	player.style.width = width;
	player.innerHTML = "";
	
	flashembed
	(
		"player",
		{
		 	src: "flash/FlowPlayerDark.swf",
			width: width, 
			height: 444
		},
		{
			config:
			{   
				autoPlay: true,
				autoBuffering: true,
				controlBarBackgroundColor: "0x333333",
				initialScale: "scale",
				videoFile: "../flash/" + video + ".flv"
			}
		} 
	);
	
	player.style.marginLeft = Math.round((maxWidth - width) / 2) + "px";
}

function focusBlur(focused, field, valueId)
{
	if (focused)
	{
		if (field.value == formValues[valueId])
		{
			field.value = "";
		}
	}
	else
	{
		if (field.value == "")
		{
			field.value = formValues[valueId];
		}
	}
}

function validateForm()
{
	var name = document.getElementById("name").value;
	
	if (name == formValues[0] || name == "")
	{
		alert("Please enter your name.");
		
		return false;
	}
	
	var email = document.getElementById("email").value;
	
	if (email == formValues[1] || email == "")
	{
		alert("Please enter your email address.");
		
		return false;
	}
	
	var address = document.getElementById("address").value;
	
	if (address == formValues[2])
	{
		address = "";
	}
	
	var city = document.getElementById("city").value;
	
	if (city == formValues[3])
	{
		city = "";
	}
	
	return true;
}
