$(function() {

    // These first three lines of code compensate for Javascript being turned on and off. 
    // It simply changes the submit input field from a type of "submit" to a type of "button".

    var paraTag = $('input#submit').parent('p');
    $(paraTag).children('input').remove();
    $(paraTag).append('<input type="button" name="submit" id="submit" value=" " />');
    var paraTag2 = $('input#submitPopup').parent('p');
    $(paraTag2).children('input').remove();
    $(paraTag2).append('<input type="button" name="submitPopup" id="submitPopup" value=" " />');
    	
    $('input#submitPopup').click(function() {
        var nameP = $('#nameP').val();
    	var commentP = $('#commentP').val();
   	 	var emailAddressP = $('#emailAddressP').val();
   	 	var areaP = $('#areaP').val();

        $.ajax({
            type: 'post',
        		url: './js/contactform/sendEmailPopup.php',
        		data: 'name=' + nameP + '&emailAddress=' + emailAddressP + '&area=' + areaP + '&comment=' + commentP,

   	 	
            success: function(results) {
            $('#popupForm p.submit img.loaderIcon').fadeOut(100);
				$('#popupForm p.submit #submit').fadeIn(1000);
				$('#popupForm ul.response').css({"visibility":"visible", "display":"block", "opacity":"0.0", "filter":"alpha(opacity = 0)"});
				$('#popupForm ul.response').animate({"opacity":"1.0", "filter":"alpha(opacity = 100)"});
				$('#popupForm ul.response').html(results);
				$finishedTheFadeOut = "0";
				setInterval("hideConfirmation()", 7000 );
            }
        }); // end ajax
        return false;
    });
    

    $('#officialWebsiteLaunch input#submit').click(function() {
        var name = $('#officialWebsiteLaunch input#name').val();
   	 	var emailAddress = $('#officialWebsiteLaunch input#emailAddress').val();
    	var area = $('#officialWebsiteLaunch select#area').val();

        $.ajax({
            type: 'post',
        url: './js/contactform/sendEmail.php',
        data: 'name=' + name + '&emailAddress=' + emailAddress + '&area=' + area,

            success: function(results) {
            $('#officialWebsiteLaunch p.submit img.loaderIcon').fadeOut(100);
    		$('#officialWebsiteLaunch p.submit #submit').fadeIn(1000);
            $('#officialWebsiteLaunch ul#response').css({"visibility":"visible", "display":"block", "opacity":"0.0", "filter":"alpha(opacity = 0)"});
			$('#officialWebsiteLaunch ul#response').animate({"opacity":"1.0", "filter":"alpha(opacity = 100)"});
            $('#officialWebsiteLaunch ul#response').html(results);
            $finishedTheFadeOut = "0";
            setInterval("hideConfirmation()", 7000 );
            }
        }); // end ajax
        return false;
    });
});




function hideConfirmation() {
if($finishedTheFadeOut == "0") {
$('.officialWebsiteLaunch ul#response').fadeOut(1000);
$('.popupForm ul#response').fadeOut(1000);
$finishedTheFadeOut = "1";
}
}

$(function() {

	$('input#name').attr("value","name");
	$('input#emailAddress').attr("value","email address");		
		

	$('input#submit').hover(function() {
		$(this).css({"backgroundPosition":"bottom left"});
	}, function() {
		$(this).css({"backgroundPosition":"top left"});
	});
	
	
	$('textarea').focus(function() {
		if($(this).attr("value") == "Detroit, what do you think it's time for?") { $(this).attr("value",""); }
	});
	$('textarea').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","Detroit, what do you think it's time for?"); }
	});
	
	$('input.name').focus(function() {
		if($(this).attr("value") == "name") { $(this).attr("value",""); }
	});
	$('input.name').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","name"); }
	});
	
	$('input.emailAddress').focus(function() {
		if($(this).attr("value") == "email address") { $(this).attr("value",""); }
	});
	$('input.emailAddress').blur(function() {
		if($(this).attr("value") == "") { $(this).attr("value","email address"); }
	});
	
	$('a.timefor').click(function() {
		$('#backgroundPopup').css({"display":"block","visibility":"visible","opacity":"0.0"});
		$('#backgroundPopup').animate({"opacity":"0.9"});
		$('#popup').fadeIn();
		$('#popupClose').fadeIn();
	});
	
	$('.clock a').click(function() {
		$('#backgroundPopup').css({"display":"block","visibility":"visible","opacity":"0.0"});
		$('#backgroundPopup').animate({"opacity":"0.9"});
		$('#popup').fadeIn();
		$('#popupClose').fadeIn();
	});
	
	$('#backgroundPopup').click(function() {
		$(this).fadeOut(1000);
		$('#popup').fadeOut(400);
		$('#popupClose').fadeOut(400);
	});
	
	$('a.popupCloseButton').click(function() {
		$('#backgroundPopup').fadeOut(1000);
		$('#popup').fadeOut(400);
		$('#popupClose').fadeOut(400);
	});




$('ul#response').click(function() {
	$(this).hide();
});
$('ul.response').click(function() {
	$(this).hide();
});


});
