jQuery.fn.jobSendToFriend=function(){

	jQuery('#sendToFriendSubmit').click(function(){
		//jQuery('form', jQuery('#sendToFriendDialog')).submit();
            jQuery.post('/send/job/to/a/friend', jQuery('form', '#sendToFriendDialog').serialize(), function(data) {
                    jQuery('#sendToFriendResponse').fadeIn();
                    jQuery('#sendToFriendDialog').fadeOut();

                    jQuery('#sendToFriendResponse > p').html(data);
                });
	});
	jQuery('.sendToFriendCloseBtn').click(function(){
		jQuery('#sendToFriendDialog').fadeOut();
                jQuery('#sendToFriendResponse').fadeOut();
	});
        jQuery('#sendToFriendDialog > form').submit(function() {
            jQuery.post('/send/job/to/a/friend', jQuery('form', '#sendToFriendDialog').serialize(), function(data) {
                    jQuery('#sendToFriendResponse').fadeIn();
                    jQuery('#sendToFriendDialog').fadeOut();

                    jQuery('#sendToFriendResponse > p').html(data);
                });
            return false;
        });

	jQuery(this).each(function(n, el){
		el = jQuery(el);
		el.click(function(){
			jQuery('input[name=job]').val(el.attr('rel'));
			jQuery('#sendToFriendDialog')
				.css({
						left: el.position().left * 0.7,
						top: el.position().top + el.height()
					})
				.fadeIn();
                        jQuery('#sendToFriendResponse')
				.css({
						left: el.position().left * 0.7,
						top: el.position().top + el.height()
					})
		});
	});
};

jQuery(document).ready(function(){
	jQuery('.send-to-friend').jobSendToFriend();
        jQuery('#sendToFriendResponse').hide();
});
