$(document).ready(function(){

	if(window.devicePixelRatio && (navigator.platform.indexOf("Mac") > -1)){
		$('#video').replaceWith('<iframe id="video" title="YouTube video player" width="350" height="293" src="http://www.youtube.com/embed/UgANQ4XZZmQ?rel=0&amp;wmode=Opaque&amp;html5=1" frameborder="0" allowfullscreen></iframe>');
	}

	$('#signup').submit(function(){

		$('#error, #success').remove();						 

		$.ajax({

		  url: "php/signup.php",

		  type: "POST",

		  cache: false,

		  data: "email="+$('#email').val(),

		  success: function(data){

			if (data == "Invalid Email."){

				signupError();

			}

			else if (data == "Success.")

				signupSuccess();

			else alert(data);	

		  },

		  error: function(e, xhr){

			alert("Error.  Please try again.");

		  }

		});

		return false;

	});

	

	$('#forwardToFriend').submit(function(){

		$('#error, #success').remove();						 

		$.ajax({

		  url: "php/forward.php",

		  type: "POST",

		  cache: false,

		  data: "textfield="+encodeURIComponent($('#from').val())+"&textfield2="+encodeURIComponent($('#to').val())+"&message="+encodeURIComponent($('#message').val()),

		  success: function(data){

			if (data == "Invalid Email."){

				forwardError(1);

			}

			else if (data == "Missing Fields."){

				forwardError(2);

			}

			else if (data == "Success.")

				forwardSuccess();

			else alert(data);	

		  },

		  error: function(e, xhr){

			alert("Error.  Please try again.");

		  }

		});

		return false;

	});


	$('#tellFriend').click(function(){

		$.modal('<iframe src="forward.html" height="365" width="492" allowtransparency="true" marginheight="0" marginwidth="0" frameborder="0" style="width:492px; height: 365px; border:none; z-index: 1; position: relative;overflow:hidden; background-color:transparent;">', {

			overlayClose: true

		});



		return false;

	});

	

	$('.closeLink').click(function(){ parent.$.modal.close(); });

	

});



function forwardError(type){

	switch (type){

		case 1 : $('#require').append('<div id="error"><ul><li>Invalid email format.</li></ul></div>');

		break;

		case 2 : $('#require').append('<div id="error"><ul><li>Missing required field(s).</li></ul></div>');

		break;

	}

}



function forwardSuccess(){

	$('#forwardForm').append('<div id="success">&#10004;</div>');

}



function signupError(){

	$('#leftBoxThree').append('<div id="error">Invalid email format.</div>');	

}



function signupSuccess(){

	$('#leftBoxTwo').append('<div id="success">&#10004;</div>');

	//ff mac

	if ((navigator.appCodeName == "Mozilla") && (navigator.platform.indexOf("Mac") > -1)){

		$('#success').addClass("righter");

	}

}
