var api_key = '0fb889bc8e5b3eff7aa13b6ad80254d3';

var api;
function get_api() { 
    api = FB.Facebook.apiClient;
}

function maybe_trigger_share_dialog(post_id, exception) {

    if (post_id && post_id != "null") {
        record_sharing("fb_publish_wall")
    }

}

function validate(form, fields) {
    var error = 0
    for (var f=0;f<fields.length;f++) {
        label = form.find('label[for="' + fields[f] + '"]')
        label.removeClass('l-error')
        if (!form[0][fields[f]].value) {
            label.addClass('l-error')
            error++
        }
    }
    return error == 0
}

function trigger_share() {

    document.taf.fb_connect_status.value = 'connected'

    publish_dialog()

}

var names = new Array(
 'CNNBC: Glenn Beck Attacks YOU',
 'Hey, Glenn Beck attacked you - yes, YOU - on his show!'
 );

var descriptions = new Array(
  'Fox host Glenn Beck spent much of the last week claiming that you are linked to Stalin, Elvis, Joe Biden\'s cousin, and the guy who came up with the idea of taxes.',
  'You\'re not going to believe this, but Glenn Beck totally went after YOU - the person reading this very text right now - on FOX News the other day. You (of all people) have to see it.'
  );

function publish_dialog() {

    show_me = 1

    FB.Connect.streamPublish(
        '', {
            'name' : names[show_me],
            'href' : 'http://beck.cnnbcvideo.com/?showme=' + show_me + '&rc=fb.publish&fv=' + window.bv_id,
	    'description' : descriptions[show_me],
	    'media' : [{ 'type': 'image', 'src': 'http://s3.moveon.org/images/beck-zany.jpg', 'href': 'http://beck.cnnbcvideo.com/?rc=fb.publish&fv=' + window.bv_id }]
        }, '', '', 'Tell your friends about this Glenn Beck video',
        function(post,exception) { 
            maybe_trigger_share_dialog(post,exception) }
    );

    $.post('saw_share.pl', { "version" : show_me });
}

FB.init(api_key, "xd_receiver.html", { 
    ifUserConnected: trigger_share, 
    doNotUseCachedConnectState: true 
});

FB.ensureInit(get_api);

