﻿///<reference path="Utils.js" />
///<reference path="FB.js" />
///<reference name="Prototype.js" />

//thumbUrl = "http://www.vmagine.com/Videos/Thumbnails/c15a540c-822f-4d64-82db-fca8ea70db78.jpg";
//videoSrc = "http://www.vmagine.com/FlashPlayer.swf?config={'videoFile':'http://www.vmagine.com/Videos/c15a540c-822f-4d64-82db-fca8ea70db78.flv'}";
//{"link":"<a href='http://apps.facebook.com/vmagine/?v=101'>vMagine</a>"}
//function PublishShareVideoFeed(uid, videoUrl, thumbUrl, isContentOwner, videoLink)
//{
//    //var templateId = isContentOwner ? "86426158120" : "88140398120";
//    //var playerUrl = $("hdnPlayerUrl").value+ 'FlashPlayer.swf';
//    var playerUrl = 'http://www.vmagine.com/FlashPlayer.swf';
//    var config = getPlayerConfigStr(videoUrl);
//    var videoSrc = playerUrl + "?config=" + config;
//    //var templateData =  {"video":{"preview_img":thumbUrl, "video_src":videoSrc}};
//    var link = "<a href='"+videoLink+"'>vMagine</a>";
//    var templateData = { "flash": { "imgsrc": thumbUrl, "swfsrc": videoSrc, "width": "176", "height": "144", "expanded_width": "176", "expanded_height": "170" }, "link": link }; 
//    var userMessage = {value:" wants to share this video from vMagine with you"};
//    callPopUpFBJSFunc(function()
//    {
//        publishFeed(uid, 120476663120, templateData, null, "Share this video with your friends", userMessage);
//    });
//}

//function PublishThumbsUpFeed(uid, videoUrl, thumbUrl)
//{
//    //var playerUrl = $("hdnPlayerUrl").value + 'FlashPlayer.swf';
//    var playerUrl = 'http://www.vmagine.com/FlashPlayer.swf';
//    var config = getPlayerConfigStr(videoUrl);
//    var videoSrc = playerUrl + "?config=" + config;

//    //var templateData =  {"video":{"preview_img":thumbUrl, "video_src":videoSrc}};
//    var templateData =  {"flash":{"imgsrc":thumbUrl, "swfsrc":videoSrc, "width":"176","height":"144", "expanded_width":"176","expanded_height":"170"}};
//    var userMessage = {value:" likes this video!"};
//    callPopUpFBJSFunc(function(){
//            publishFeed(uid, 88131503120, templateData, null, "Tell your friends you like this video", userMessage);
//        });
//}

////http://wiki.developers.facebook.com/index.php/Facebook.showFeedDialog
//function publishFeed(uid, template_bundle_id, template_data, body_general, user_message_prompt, user_message)
//{
//    //3.7.09 - Changing uid to null because post to profile has stopped working.
//    //var retVal = FB.Connect.showFeedDialog(template_bundle_id, template_data, uid, body_general, null, FB.RequireConnect.require, onPublishFeedComplete, user_message_prompt, user_message);
//    var retVal = FB.Connect.showFeedDialog(template_bundle_id, template_data, null, body_general, null, FB.RequireConnect.require, onPublishFeedComplete, user_message_prompt, user_message);
//}

function PublishShareVideoFeed(uid, videoUrl, thumbUrl, isContentOwner, videoLink) {
    var userMessagePrompt = "Share this video with your friends";
    var userMessage = "wants to share this video from vMagine with you";
    var attachment = getAttachment(videoUrl, thumbUrl);
    
    callPopUpFBJSFunc(function() {
        publishToStream(userMessage, attachment, userMessagePrompt);
    });
}

function publishToStream(user_message,  attachment,  user_message_prompt)
{
    //http://developers.facebook.com/docs/?u=facebook.jslib.FB.Connect.streamPublish
    
    var action_links = [{ "text": "Share videos on facebook", "href": "http://www.vmagine.com"}];
    FB.Connect.streamPublish(user_message,  attachment,  action_links,  null,  user_message_prompt,  onPublishToStreamComplete,  false,  null);
}

function getAttachment(videoUrl, thumUrl) {
    //http://wiki.developers.facebook.com/index.php/Attachment_(Streams)
    
    var videoSrc = getVideoSourceUrl(videoUrl);
    
    return { 'media':
                    [{  'type': 'flash',
                        'swfsrc': videoSrc,
                        'imgsrc': thumUrl,
                        'width': '176',
                        'height': '144',
                        'expanded_width': '176',
                        'expanded_height': '170'}]
                    };
}

function getVideoSourceUrl(videoUrl) {
    var playerUrl = 'http://www.vmagine.com/FlashPlayer.swf';
    var config = getPlayerConfigStr(videoUrl);
    var videoSrc = playerUrl + "?config=" + config;
    
    return videoSrc;
}

function getPlayerConfigStr(videoFile)
{
    var config = "{"
    config  +="'controlBarBackgroundColor':'0x3b3a3a',";
    config  +="'autoRewind':false,";
    config  +="'loop':false,";
    config  +="'showFullScreenButton':false,";
    config  +="'showStopButton':true,";
    config  +="'showPlayButton':true,";
    config  +="'showScrubber':true,";
    config  +="'showVolumeSlider':false,";
    config  +="'showMuteVolumeButton':false,";
    config  +="'showMenu':false,";
    config  +="'showPlayListButtons':false,";
    config  +="'videoHeight':144,";
    config  +="'controlsWidth':176,";
    config  +="'videoFile':'" + videoFile + "'";
    config  +="}";
    
    return config;
}

function onPublishToStreamComplete(post_id, exception)
{
    //alert(post_id);
}

