$(document).ready(function() {

	$("#send-to-a-friend-dialog").dialog({
		title: "SummerHill Homes - Email a Friend",
		modal: true,
		autoOpen: false,
		width: 497
	});	
	
	$('#send-to-a-friend-link').click(function(e){
		
		if(e.preventDefault){
            e.preventDefault();
        }else{
            e.returnValue = false; 
        };
        
        open_send_to_friend();
		
	});

	// This click event should be triggered from within the iframe.
	// See the bottom of: http://forum.jquery.com/topic/issue-closing-a-dialog-that-contains-an-iframe-from-within-the-iframe
	
	$('#but_closeChildFromChild').click(function () {
		close_send_to_friend();
	});
	
});

function open_send_to_friend()
{
	$("#send-to-a-friend-dialog").load('/send-to-friend/frame?location=' + window.location, function(){
		$("#send-to-a-friend-dialog").dialog("open");
	});
}

function close_send_to_friend()
{
	$('#send-to-a-friend-dialog').dialog('close');
}
