var currentSideElement = '#the-scene-info';
var sliding = false;
var slideNext = '';

window.onload = function()
{
	resetMargins();
}

function displaySideElements (newSideElement)
{
//	$(currentSideElement).animate({ height: 'toggle' }, 150);
//	$('#'+newSideElement).animate({ height: 'toggle' }, 150);

	if ('#'+newSideElement != currentSideElement)
	{
		if (sliding == false)
		{
			sliding = true;
			slideNext = '';
			
			$(currentSideElement).slideUp(150, resetMargins);
			$('#'+newSideElement).slideDown(150, stopSliding);

			currentSideElement = '#'+newSideElement;
		} else {
			slideNext = newSideElement;
		}
	}
}

function stopSliding ()
{
	sliding = false;
	
	if (slideNext != '')
		displaySideElements (slideNext);

	document.getElementById('the-scene').style.backgroundPosition = '0 -18px';
	document.getElementById('the-entertainment').style.backgroundPosition = '0 -18px';
	document.getElementById('the-food').style.backgroundPosition = '0 -18px';
	document.getElementById('the-beach').style.backgroundPosition = '0 -18px';
	document.getElementById('the-activities').style.backgroundPosition = '0 -18px';
	document.getElementById('the-community').style.backgroundPosition = '0 -22px';

	if (currentSideElement == '#the-scene-info')
		document.getElementById('the-scene').style.backgroundPosition = '0 0';

	if (currentSideElement == '#the-entertainment-info')
		document.getElementById('the-entertainment').style.backgroundPosition = '0 0';

	if (currentSideElement == '#the-beach-info')
		document.getElementById('the-beach').style.backgroundPosition = '0 0';

	if (currentSideElement == '#the-food-info')
		document.getElementById('the-food').style.backgroundPosition = '0 0';

	if (currentSideElement == '#the-activities-info')
		document.getElementById('the-activities').style.backgroundPosition = '0 0';

	if (currentSideElement == '#the-community-info')
		document.getElementById('the-community').style.backgroundPosition = '0 0';

}

// IE Bug Fix - Margins default to 0px on nearby links when the nearby div slides up to 0px.
function resetMargins ()
{
	document.getElementById('the-scene').style.margin = '10px 0 10px 0';
	document.getElementById('the-entertainment').style.margin = '10px 0 10px 0';
	document.getElementById('the-beach').style.margin = '10px 0 10px 0';
	document.getElementById('the-food').style.margin = '10px 0 10px 0';
	document.getElementById('the-activities').style.margin = '10px 0 10px 0';
	document.getElementById('the-community').style.margin = '10px 0 4px 0';
}

function checkAndSubmitForm()
{
	var errors = '';
	var errorFound = false;
	
	if (document.getElementById('name').value == '')
	{
		errors = errors + "* Contact Name\n";
		errorFound = true;
	}

	if (document.getElementById('phone').value == '')
	{
		errors = errors + "* Contact Phone Number\n";
		errorFound = true;
	}

	if (document.getElementById('email').value == '')
	{
		errors = errors + "* Contact Email Address\n";
		errorFound = true;
	}

	if (document.getElementById('message-body').value == '')
	{
		errors = errors + "* Message Text";
		errorFound = true;
	}

	if (errorFound == true)
	{
		errors = 'You must complete the following fields before you can submit this form:\n\n' + errors;
		alert (errors);
		return false;
	} else {
		document.forms.contactForm.submit();
		return true;
	}
}