﻿$(function(){




var $embedCode = $("#embed-code")
		.dialog({
			title: "EMBED CODE",
			autoOpen: false,
			resizable: false,
			draggable: false,
			width: 500,
			height: 160,
			show: "blind"
		}),
	$embedCodeTextarea = $embedCode.find("textarea").click(function(){
			this.select();
		})
$("#btn-embed").click(function(){
	$forward.dialog("close");
	$embedCode.dialog("open");
})

var $forward = $("#forward")
		.dialog({
			title: "FORWARD TO A FRIEND",
			autoOpen: false,
			resizable: false,
			width: 300,
			height: 450,
			show: "blind",
			draggable: false,
			buttons: {
				submit: function(){
					$forward.submit();
				}
			}
		});

$forward.submit(function(){
	
	$forward.ajaxSubmit({
		type: "POST",
		url: "index.php",
		beforeSubmit: function(){
			var invalid = $forward.invalid();
			if( invalid.length ){
				$forward.find(".error").html(invalid.attr("message"));
				invalid[0].focus();
				return false;
			}
		},
		success: function(data){
			var response = (data == "true")
				? "Your message and this page has been forwarded to your friend. Go ahead. Send another one!"
				: "Sorry, there was an error submitting your stuff. Please try again.";
			if(data == "true"){
				$forward.find(".error").html("");
				$forward.find(".msg").html(response);
				$forward.find("[name=friends_name], [name=friends_email]").val("")[0].focus();
			}
			else
				$forward.find(".error").html(response);
				
		}
	});
	return false;
	
})
$("#btn-forward").click(function(){
	$forward.dialog("open");
	$embedCode.dialog("close");
});






})