$(document).ready(function(){
    bind_share_link();
    bind_share_form();
});

function bind_share_link(){
    $('.share-link').bind('click',function(e){
        e.preventDefault();
        new_form = $('#share-form-holder').clone(true).insertAfter(this);
        new_form.attr('id','share-form-1');
        $.facebox(new_form);
    });
}

function bind_share_form(){
    $('#share-form').ajaxForm({
        dataType: 'json',
        success: process_share,
        beforeSubmit: presubmit_share,
    });
}

function presubmit_share( form_data, obj, opts ){
    $('#share-form');
    return true;
}

function process_share(data){
    if(data.message == "success") $.facebox(data.done);
    else alert('We encountered some errors processing your data');
}
