﻿function DTFacebook(initCallback) {
    this._apiKey = "a16d5127bf1c77afddc055119456e7d7";
    this._channelPath = "/xd_receiver.htm";
    this._initCallback = initCallback;
}

DTFacebook.prototype._apiKey;
DTFacebook.prototype._channelPath;
DTFacebook.prototype._initCallback;

DTFacebook.prototype.init = function() {
    var apiKey = this._apiKey;
    var channel = this._channelPath;
    var initCallback = this._initCallback;
    FB.Bootstrap.requireFeatures(["Connect", "Api"], function() 
    {
        FB.init(apiKey, channel, { "ifUserConnected": function() { initCallback(); } });
        /*FB.Connect.requireSession(function(result) {
            alert("wtf");
            FB.Connect.showPermissionDialog("publish_stream");
        });*/
    });
}

DTFacebook.prototype.postCommentFeed = function(blogurl, postid, blogname, name) {
    var attachment = "";
    var blogImage = "http://www.gravatar.com/avatar/" + dtBlogMailHash + ".png?s=110&r=X&d=identicon";

    if (postid != 0) {
        attachment = {
            'name': blogname + ' - Djungeltrumman.se',
            'href': 'http://www.djungeltrumman.se/' + blogurl + "/post/" + postid,
            'description': name + ' har kommenterat ' + blogname,
            'media': [{
                'type': 'image',
                'src': blogImage,
                'href': 'http://www.djungeltrumman.se/' + blogurl + "/post/" + postid}]
            };
        }
        else {
            attachment = {
                'name': blogname + ' - Djungeltrumman.se',
                'href': 'http://www.djungeltrumman.se/' + blogurl,
                'description': name + ' har kommenterat ' + blogname,
                'media': [{
                    'type': 'image',
                    'src': blogImage,
                    'href': 'http://www.djungeltrumman.se/' + blogurl}]
                };
            }
            FB.Connect.streamPublish('', attachment, null, null, '', function(post_id, exception) {
                if (post_id.length > 4) {
                    DTAjax.UserService_FacebookCommentStreamPublished(function(result) { });
                }
            }, true);
        }
