/*!
 * UI and Interactions for danielreynes.com
 *
 * Copyright (c) 2009 Daniel Reynes Creative
 *
 * Date: 2009-12-08 11:41:21 -0500 (Tue, 8 Jan 2009)
 * Revision: 0001
 */


var currentHeight = window.innerHeight;
			
var contactTop = 
{
	'padding-top' : ((currentHeight/2) + 6)
};

function repositionContact()
{
	currentHeight = window.innerHeight;
	contactTop = {'padding-top' : ((currentHeight/2) + 6)};
	$("div.contactArea").css({'padding-top' : ((currentHeight/2) + 6)});
	/* $(window).unbind('resize', repositionContact); */

};
				
$(document).ready
(

	function()
	{		
		/* CONTACT RELATED */
		/*
		$(window).bind('resize', repositionContact);
		
		$("div.contactArea").css(contactTop);
		*/
			
		$("img.outerContact").click
		(
		function(event)
			{
				if ($(this).attr('src') == '/resources/images/contact_off.jpg')
				{
					$(this).attr('src', '/resources/images/contact_close2.jpg');
					$("div.outerBrown").animate({top: - 300});	
					$("a.americanCensor").animate({top: -265});
				}
				else
				{
					$("img.outerContact").attr('src', '/resources/images/contact_off.jpg');
					$("div.outerBrown").animate({top: 0});
					$("a.americanCensor").animate({top: 35});
				}
				//event.preventDefault();
			}
		);
		
		
		$('.error').hide();
		$('.button').click(function(){
			//validate and process form
			
			$('.error').hide();
			
			var name = $("input#name").val();
				if (name == "")
				{
					$("label#name_error").show();
					$("input#name").focus();
					return false;
				}
			var email = $("input#email").val();
				if (email == "")
				{
					$("label#email_error").show();
					$("input#email").focus();
					return false;
				}
			var message = $("textarea#message").val();
				if (message == "")
				{
					$("label#message_error").show();
					$("input#message").focus();
					return false;
				}
				
			var ip = $("input#ip").val();
			var httpref = $("input#httpref").val();
			var httpagent = $("input#httpagent").val();
			
		
			var dataString = 'ip=' + ip + '&httpref=' + httpref+ '&httpagent=' + httpagent + '&name=' + name + '&email=' + email + '&message=' + message;
			
			$.ajax({
				type: "POST",
				url: "sendmail.php",
				data: dataString,
				
				success: function() {
					$('#contact_box').html("<div id='after_message'></div>");
					$('#after_message').css({'padding' : '10px', 'text-align' : 'center', 'color' : '#003846', 'font-family' : 'Arial, Helvetica, sans-serif'});
					$('#after_message').html("<h3>The Information You Requested Has Been Submitted!</h3>")
					
					.append("<p>We will be in touch soon.</p>")
					.hide()
					.fadeIn(1400, function() {
						$('#after_message').append("<img id='checkmark' src='/resources/images/check.png' />");
					});
				}
			});
		return false;
		});							
	}
);
