function createObject() {
	var request_type;
	
	try{
		// Opera 8.0+, Firefox, Safari
		request_type = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			request_type = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request_type = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your current browser of choice does not support the technologies required for online registration. Please use another browser.");
				return false;
			}
		}
	}

	return request_type;
}


var httpMakeContact = createObject();

function contactForm() {
	
	//Form Validation First
	if(document.getElementById('contactName').value=="") {
	
		alert('Please fill in your name.');
		document.getElementById('contactName').focus();
	
	} else if(document.getElementById('contactEmail').value=="") {
		
		alert('Please fill in your e-mail address.');
		document.getElementById('contactEmail').focus();
		
	} else if(document.getElementById('contactText').value=="") {
		
		alert('Please fill in some comments.');
		document.getElementById('contactText').focus();
		
	} else { //If all okay, send email
	
		nocache = Math.random();
		
		showProcessing();

		//Let's get the data from the form
		var contactName=encodeURI(document.getElementById('contactName').value);
		var contactEmail=encodeURI(document.getElementById('contactEmail').value);
		var contactText=encodeURI(document.getElementById('contactText').value);

		httpMakeContact.open('get', 'php/contactUsEmail.php?contactName='+contactName+'&contactEmail='+contactEmail+'&contactText='+contactText+'&nocache='+nocache);
		httpMakeContact.onreadystatechange = function processContactReply() {
			
			if(httpMakeContact.readyState == 4){
				var response = httpMakeContact.responseText;
				contactCompleted();
			}
			
		};
		httpMakeContact.send(null);

		
	
	}
	
}

function showProcessing() {
	
	document.getElementById('contactProcessing').style.display='block';
	document.getElementById('contactProcessing').style.visibility='visible';
	
	
}

function hideProcessing() {
	
	document.getElementById('contactProcessing').style.display='none';
	document.getElementById('contactProcessing').style.visibility='hidden';
	
	
}

function contactCompleted() {
	
	hideProcessing();
	document.getElementById('contactContainer').innerHTML='<div style="height: 406px; width: 426px;text-align:center;"><div style="margin-top:160px;color:#990031;"><h1>Thank you for contacting us!</h1></div></div>';

}

var images = new Array();
function preload() {
	for (i = 0; i < preload.arguments.length; i++) {
		images[i] = new Image();
		images[i].src = preload.arguments[i];
	}
};

preload(
	'img/menu_1_SDC.png',
	'img/menu_1_SDC_active.png',
	'img/menu_2_PTI.png',
	'img/menu_2_PTI_active.png',
	'img/menu_3_PG.png',
	'img/menu_3_PG_active.png',
	'img/menu_4_AB.png',
	'img/menu_4_AB_active.png',
	'img/menu_5_SU.png',
	'img/menu_5_SU_active.png',
	'img/menu_6_CR.png',
	'img/menu_6_CR_active.png',
	'img/menu_7_CU.png',
	'img/menu_7_CU_active.png',
	'img/menu_8_PH.png',
	'img/menu_8_PH_active.png'
);

$(function(){
	var setContentHeight = function() {
		var h = $(window).height();
		if(h<600) {
			$('#bottom_banner').css('display', 'none');
			var frame_height = 0;
			frame_height += Number($('#content_load').height());
			$('#frame').height(frame_height + "px");
		} else {
			$('#bottom_banner').css('display', 'inherit');
			var frame_height = 0;
			frame_height += Number($('#content_load').height());
			$('#frame').height(frame_height + "px");
			body_height = frame_height + 220;
			$("body").height(body_height);
		}
	};
		
	$(window).resize(setContentHeight);			
	/*Load the content*/
	var loadContent = function(menu) {
		$.ajax({
			type: "GET",
			url: "content/" + menu + ".html",
			dataType: "html",
			cache: false,
			success: function(newhtml){
				$('#content_load').fadeOut('slow', function() {
					$('#content_load').html(newhtml);
					
					setContentHeight();
					$('#content_load').fadeIn('slow');
				});
			}
		  });	
	}
	
	$('#menu1').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab1').slideDown('fast');
		loadContent('DayCamp');	
	});
	
	$('#menu2').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab2').slideDown('fast');
		loadContent('Preteen');
	});
	
	$('#menu3').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab3').slideDown('fast');
		loadContent('Programs');	
	});
	
	$('#menu4').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab4').slideDown('fast');	
		loadContent('About-GuestSpeakers');			
	});
	
	$('#menu41').click(function(){
		loadContent('About-GuestSpeakers');				
	});
	$('#menu42').click(function(){
		loadContent('About-Staff');				
	});
	$('#menu43').click(function(){
		loadContent('About-FAQ');				
	});
	$('#menu44').click(function(){
		loadContent('About-Leaders');				
	});
	
	$('#menu5').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab5').slideDown('fast');
		loadContent('SignUp');				
	});
	
	$('#menu6').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab6').slideDown('fast');
		loadContent('CampRates');				
	});
	
	$('#menu7').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab7').slideDown('fast');
		loadContent('ContactUs');				
	});
	
	$('#menu8').click(function(){
		$('.tab').slideUp('fast').delay('fast');
		$('#tab8').slideDown('fast');
		loadContent('Photos');				
	});
	
	var cloudMoved = false;
	var cloudMoved2 = false; 
	
	$(init);
	$('#tab1').slideDown('fast', function() {
		loadContent('DayCamp');	
	});
	
	function init(){
		clouds();
		clouds2();	
	}
	
	function clouds() {
		if (!cloudMoved)
		{
			$("#clouds")
				.css("left", $("#clouds").offset().left)
		}
	
		$("#clouds").animate(
				{left: $("body").width()},
				cloudMoved ? 120000 : 80000,
				"linear",
				function()
				{
					$(this).css("left", -parseInt($(this).css("width")))
					cloudMoved = true;
					init();
				}
			)
	}
	function clouds2() {
		if (!cloudMoved2)
		{
			$("#clouds2")
				.css("left", $("#clouds2").offset().left)
		}
	
		$("#clouds2").animate(
				{left: $("body").width()},
				cloudMoved2 ? 180000 : 150000,
				"linear",
				function()
				{
					$(this).css("left", -parseInt($(this).css("width")))
					cloudMoved2 = true;
					init();
				}
			)
	}
});


