﻿/// <reference path="./API/Agility.UGC.API.js" />


Agility.RegisterNamespace("Doritos.FacebookUtil");

(function(FacebookUtil) {

    FacebookUtil.PublishFaveToWall = function(VideoTitle, url, callback) {
        FacebookUtil.PublishToWall("fave", "Doritos® Viralocity – " + VideoTitle, "", url, callback);
    }
    FacebookUtil.PublishCommentToWall = function(VideoTitle, url, comment, callback) {
        FacebookUtil.PublishToWall("comment", "Doritos® Viralocity – " + VideoTitle, comment, url, callback);
    }
    FacebookUtil.PublishRatingToWall = function(VideoTitle, url, callback) {
        FacebookUtil.PublishToWall("rate", "Doritos® Viralocity – " + VideoTitle, "", url, callback);
    }


    FacebookUtil.PublishToWall = function(type, title, bodytext, url, callback) {
        try {

            var fb_id = FB.Connect.get_loggedInUser();

            if (fb_id > 0) {

                if (title == null || title == "") {
                    title = 'DoritosViralocity.ca - Name the flavour.  Get Rich.';
                }

                //determine context and present appropriate caption
                if (type == 'register') {
                    caption = '{*actor*} just registered at DoritosViralocity.ca for a chance to win up to $250K.';
                }
                else if (type == 'comment') {
                    caption = '{*actor*} just commented on the video ' + title + ' from DoritosViralocity.ca';
                }
                else if (type == 'fave') {
                    caption = '{*actor*} just fav’d the video ' + title + ' from DoritosViralocity.ca';
                }
                else if (type == 'rate') {
                    caption = '{*actor*} just rated the video ' + title + ' from DoritosViralocity.ca';
                }

                //Fill out FB Required fields for submission

                message = 'Stuff is happening like crazy at DoritosViralocity.ca';
                attachment = {
                    'name': title,
                    'href': url,
                    'caption': caption,
                    'description': bodytext,
                    'media': [{ 'type': 'image',
                        'src': 'http://www.proximitystore.com/viralocity/viralocity-fblogo.png',
                        'href': url}]
                    };

                    // Add any action links here if needed (these are the links at the very bottom of the post... not usually used.
                    action_links = { 'text': '',
                        'href': ''
                    };


                    FB.Connect.streamPublish('', attachment, '', '', '', callback, 'TRUE');
                }
            }
            catch (Err) {

            }
        }

    })(Doritos.FacebookUtil);
