function _sendToFriendSubmit(form) {
	var url = HTML_ROOT + '/includes/plugin_send_friend.inc.php?url=' + SEND_PAGE_URL;
	
	$.ajax( {
	   url: url,
	   type: 'POST',
	   data: $( 'form' ).serialize(),
	   success: _updateResponseInLitebox,
	   error: function( t ) { }
	} );
	
	return false;
}

function _updateResponseInLitebox(t) {
    
	/*
	 * Inject the content into the litebox, with additional form tags
	 * which pipe the submit through ajax
	 */
	
	$('#modal_form').html(
        '<form name="SendToFriend" id="SendToFriend">' + 
        t + 
        '</form>'
    );

	$('#modal_form script').each(function(e) {
		// eval in the context of the document.
		evalScript( e.html() );
	} );
	
	return false;
}

/*
 * t is a prototype transport
 * so this can be used as the onsuccess for a Ajax.Request(...)
 */
function _showResponseInLitebox(t) {
	/*
	 * Inject the content into the litebox, with additional form tags
	 * which pipe the submit through ajax
	 */
	$('#modal_form').html(
        '<form>' + 
        t + 
        '</form>'
    );

	$('#modal_form script').each(function(e) {
		// eval in the context of the document.
		evalScript( e.html() );
	} );

	_showLitebox();
	return false;
}

function modalOpen( dialog )
{
	dialog.overlay.show(); //fadeIn( 300, function () {
	    dialog.overlay.bind( 'click', function() { modalClose( dialog ); } );
		dialog.container.show();
		dialog.data.show();
	//});
	
	$( document ).pngFix();
}

function modalClose( dialog )
{
    dialog.container.hide();
	dialog.data.hide();
	dialog.overlay.hide(); //fadeOut( 300, function () {
		$.modal.close();
	//});
}

function _showLitebox() {
	
    $( '#modal_form' ).modal( {
        persist: true,
        onOpen: modalOpen,
        onClose: modalClose
    } );
    
	return false;
}

function showSendToFriend() {
	var url = HTML_ROOT + '/includes/plugin_send_friend.inc.php'
	
	$.ajax ( {
	    url: url,
	    type: 'GET',
	    data: 'url='+SEND_PAGE_URL,
	    success: _showResponseInLitebox,
	    error: function( t ) {  }
	} );
	
	return false;
}