/*
    $Rev: 151962 $
    XXX: REQUIREMENTS
        -- OOP.js
        -- facebook/graph/base.js
*/


var BasePoster = {
    /*
       XXX: Must extend CommonInterface

       This class handles all functionality on the custom_share page
       that is necessary to perform:

            - Logging into Facebook
            - Displaying the user's FB friends
            - Posting an ecard to a user's FB wall

       This class is also in charge of creating an attachment (specific to 
       an ecard). This needs to be passed to Facebook to perform a wall post,
       and contains all info about the ecard and the post itself.

       For further definitions of some of the base calls, see CommonInterface.
    */

    userTemplate: '' +
            '<img id="agi-fbshare-mthumb" src="PICTURE" ' + 
             'border="0" alt"NAME" and title="NAME">' +
                '<div id="agi-fbshare-welcome">'+
                    'Hi <span id="agi-fbshare-user">NAME</span>,' +
                    '<span id="agi-fbshare-mstatus">' +
                        'You are signed into your Facebook account.' + 
                        '<br><a href="javascript:FB.logout()">not NAME</a>?' +
                    '</span>'+
                '</div>',

    friendTemplate: '' +
            '<li>' +
                '<a href="javascript:Poster.postProduct(UID)"><img ' +
                    'src="PICTURE" /></a>'+
                    '<span>NAME <a href="javascript:Poster.postProduct(' +
                        'UID)">post</a>' +
                    '</span>'+
            '</li>',

    init: function(friendRenderer, pageAttrs, FBAttrs) {
        /* Call our parent's init(), save off some attrs.
                
                @param friendRender given an HTML template, and a User
                                    object, it will swap in all the dynamic
                                    bits in the HTML template and return it.
                @param pageAttrs  page related values (dictionary)
                                    e.g. ``ahost``, ``source``
                @param FBAttrs  FB related values (dictionary)
                                  e.g. ``attachment``, ``friendID``
        */
        pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
        pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

        this.parent(friendRenderer, pageAttrs, FBAttrs);

        this.friendFbId = FBAttrs.friendFbId;
        this.numCols = FBAttrs.numCols || 3; // # users per row
        fixWallPostBug();
    },

    onLoggedOut: function () {
        /* Called when:
                -- user logs out
                -- it's determined user is logged out (on page load)
        */
        this.parent();
        this.friendFbId = undefined;
    },

    onLoggedIn: function() {
        /* Called when:
                -- user logs in
                -- it's determined user is logged in (on page load)

           -- fetch friends from FB
           -- render friend markup (+ display)
           -- render markup for user (+ display)
        */

        // friend ID passed to page; pop dialog
        if (this.friendFbId) {
            this.postProduct(this.friendFbId);
        }

        this.parent();
        this.showAllFriends();
        this.renderUser();
    },

    showAllFriends: function() {
        var friendsQuery = FB.Data.query(
                this.FQLQueries.friends, this.tokenObject.uid);

        friendsQuery.wait(OOP.hitch(this._showFriendsCallback, this));
    },

    _showFriendsCallback: function(users) {
        this.renderFriends(users);
    },

    renderFriends: function (users) {
        var friendRows = this.parent(
                users, this.friendTemplate, 'all', this.numCols);

        document.getElementById(this.friendListContainerId).innerHTML = 
            '<ul>' + friendRows + '</ul>';
    }
};


var SelfPoster = {

    /*
        XXX: Must extend BasePoster

        This module is for posting to the logged-in user's feed.
        There is no friend selector, and thus no friend renderer.

        The benefit of using this module is that it will do what's necessary
        to insert usage into the database before popping the "share" window.
    */

    userTemplate: '',
    friendTemplate: '',

    init: function(pageAttrs, FBAttrs) {
        /* Allow a user template to be passed in, but force the friend template
           to be empty (user cannot select a friend).
        */

        var nullFriendRenderer = undefined;

        pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
        pageAttrs.friendTemplate = this.friendTemplate;

        this.parent(nullFriendRenderer, pageAttrs, FBAttrs);
    },

    onLoggedIn: function() {
        /* Starting off, there will be no separate experience for logged in
           vs. logged out. (Need to override base method so that nothing
           special happens).

           FB *should* pop a login screen if user tries to post to FB and is
           not logged in.
        */
    },

    postProduct: function() {
        /* Record usage, pop the share dialog.

            TODO: Transition base.js's ``postProduct()``
                  to utilize the new way of posting to a user's feed.

                http://developers.facebook.com/docs/reference/javascript/FB.ui/
        */

        // Insert record + retrieve usage number
        var usageNumber = this.insertUsageRecord(
                this.ahost + this.processUsagePage,
                document.facebookHiddens);

        // use the new-ish way of posting to A feed
        this.attachment.method = "feed";

        // iframes seem unhappy on confirm page (displays *way* off center)
        this.attachment.display = "popup";

        FB.ui(this.attachment);
    }
};


var PicsWishesPoster = {
	userTemplate: '' +
        '<img id="agi-fbshare-mthumb" src="PICTURE" ' + 
         'border="0" alt"NAME" and title="NAME">' +
            '<div id="agi-fbshare-welcome">'+
                'Hi <span id="agi-fbshare-user">NAME</span>,' +
                '<span id="agi-fbshare-mstatus">' +
                    'You are signed into your Facebook account.' + 
                    '<br><a href="#" onClick="FB.logout();return false;">not NAME</a>?' +
                '</span>'+
            '</div>',

    friendTemplate: '' +
        '<li>' +
            '<a href="#" onClick="Poster.postProduct(UID);return false;"><img ' +
                'src="PICTURE" /></a>'+
                '<span>NAME <a href="#" onClick="Poster.postProduct(' +
                    'UID);return false;">post</a>' +
                '</span>'+
        '</li>'

};

var BMAPoster = {

    userTemplate: '' +
        '<h2 id="agi-fbshare-welcome">\n' +
            '<a href="#" onclick="Poster.postProduct()" ' +
             'style="text-decoration:underline">' +
                 'Post this eCard to your own wall' +
             '</a>\n' +
        '</h2>\n'+
        '<div id="agi-fbshare-mthumb">\n' +
            '<ul>\n' +
                '<li>\n' +
                    '<img src="PICTURE" onclick="Poster.postProduct()" ' +
                        'style="cursor:pointer"/>\n' +
                    '<div>\nNAME ' +
                        '<a href="#" onclick="Poster.postProduct()">' +
                            'post to your wall' +
                        '</a>\n' +
                    '</div>\n' +
                '</li>\n' +
            '</ul>\n' +
        '</div>\n',

    init: function(friendRenderer, pageAttrs, FBAttrs) {
        /* Call our parent's init(), save off some attrs.
           @param friendRender given an HTML template, and a User
                               object, it will swap in all the dynamic
                               bits in the HTML template and return it.
           @param pageAttrs  page related values (dictionary)
                             e.g. ``ahost``, ``source``
           @param FBAttrs  FB related values (dictionary)
                           e.g. ``attachment``, ``friendID``
         */
         pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
         pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

         this.parent(friendRenderer, pageAttrs, FBAttrs);

         this.friendFbId = FBAttrs.friendFbId;
         this.numCols = FBAttrs.numCols || 3; // # users per row
    }
};


var JLNotecardPoster = {
    /*
       XXX: Must extend BasePoster

       Specialized version of BasePoster for JL Notecard. We need to override
       the markup for the user container (where the user's info is shown).
    */

    userTemplate: '' +
        '<div id="agi-fbshare-mthumb">\n' +
            '<ul>\n' +
                '<li>\n' +
                    '<img src="PICTURE" onclick="Poster.postProduct()" ' +
                        'style="cursor:pointer"/>\n' +
                    '<div>\nYou ' +
                        '<a href="javascript:Poster.postProduct()">' +
                            'post' +
                        '</a>\n' +
                    '</div>\n' +
                '</li>\n' +
            '</ul>\n' +
         '</div>\n',

    friendTemplate: '' +
            '<li>' +
                '<a href="javascript:Poster.postProduct(UID)"><img ' +
                    'src="PICTURE" /></a>'+
                    '<span>NAME <a href="javascript:Poster.postProduct(UID, \'NAME\')">post</a>' +
                    '</span>'+
            '</li>',

    init: function(friendRenderer, pageAttrs, FBAttrs) {
        pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
        pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

        this.parent(friendRenderer, pageAttrs, FBAttrs);

        this.friendFbId = FBAttrs.friendFbId;
        this.numCols = FBAttrs.numCols || 4; // # users per row

        this.prodnum = pageAttrs.prodnum;
        this.messageId = 'fldMessage';
        this.sendCardFormId = 'frmSendCard';
        this.facebookFormId = 'facebookHiddens';

    },
         
    postProduct: function(friendFBID, friendName) {
        /* After checking the message and age field (if present),
           post the note card (call base's postProduct);
        */

    	// function lives in the Flash
        var wasSuccessful = set_customizations();

        if (!wasSuccessful) {
            OOP.log("error calling set_customizations() function");
            return;
        }

        // JLNotecard allows personaliztion by recipient name.
        // Here we get the facebook user name to post to.
        // Requires the to_name parameter to be in the facebook hiddens list
        var nameNode = document.getElementById('to_name');
        if (nameNode){
            nameNode.value = 'You';
            if (friendName)
                nameNode.value = friendName
        }

        this.parent(friendFBID);
    }

};

var JLPoster = {
    /*
       XXX: Must extend BasePoster

       Specialized version of BasePoster for JL. We need to override
       the markup for the user container (where the user's info is shown).
    */

    userTemplate: '' +
        '<div id="agi-fbshare-mthumb">\n' +
            '<ul>\n' +
                '<li>\n' +
                    '<img src="PICTURE" onclick="Poster.postProduct()" ' +
                        'style="cursor:pointer"/>\n' +
                    '<div>\nYou ' + 
                        '<a href="javascript:Poster.postProduct()">' +
                            'post' +
                        '</a>\n' +
                    '</div>\n' +
                '</li>\n' +
            '</ul>\n' +
         '</div>\n',

    friendTemplate: '' +
            '<li>' +
                '<a href="javascript:Poster.postProduct(UID)"><img ' +
                    'src="PICTURE" /></a>'+
                    '<span>NAME <a href="javascript:Poster.postProduct(' +
                        'UID, \'NAME\')">post</a>' +
                    '</span>'+
            '</li>',
    
    init: function(friendRenderer, pageAttrs, FBAttrs) {
        pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
        pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

        this.parent(friendRenderer, pageAttrs, FBAttrs);

        this.friendFbId = FBAttrs.friendFbId;
        this.numCols = FBAttrs.numCols || 4; // # users per row

        this.prodnum = pageAttrs.prodnum;
        this.messageId = 'fldMessage';
        this.sendCardFormId = 'frmSendCard';
        this.facebookFormId = 'facebookHiddens';

    },

    login: function() {
        /* Show appropriate header copy, then show login dialog.
        */
        this.showCorrectCopy('intro-middle');
        this.parent();
    },

    postProduct: function(friendFBID ) {
        /* After checking the message and age field (if present),
           post the ecard (call base's postProduct);
        */

        var message = this.hasPopulatedMessage();

        // empty message ?
        if (!message){
            alert('Please type your message first.');
            return;
        }

        // message too long ?
        if (message.length > 1000){
            alert('Sorry, the maximum length of a message is 1,000 characters.'+
                    ' Your message is ' + message.length + ' characters.');
            return;
        }

        // determine the [upper] age limit
        if (this.prodnum == '3111873') {
            var upperLimit = 12; 
        }
        else {
            var upperLimit = 99;
        }

        if (!this.isAgeValid(upperLimit)) {
            alert("Please enter recipient's age (between 1 and " +
                    upperLimit +")");
            return;
        }

        // populate pers then post it!
        this.populatePers();
        this.parent(friendFBID);
    },

    hasPopulatedMessage: function() {
        /*
            -- grab the message
            -- trim it (strip spaces from left and right)
            -- set the trimmed message back to the form
            -- return message
        */
        var messageOjbect = document.getElementById(this.messageId);

        if (!messageOjbect) {
            // weird error, don't punish user
            return true;
        }
        
        var message = messageOjbect.value;
        message = message.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        messageOjbect.value = message;

        return message;
    },

    isAgeValid: function(upperLimit) {
        /*
           There are (currently) two cards that have an age field.
           If present, verify if.
        */
        var ageField = document.forms[this.sendCardFormId].fldAge;

        if (!ageField) {
            // weird error, don't punish user
            return true;
        }

        // product has no age field
        if (ageField.type == 'hidden') {
            return true;
        }

        var age = Number(ageField.value) || -1;

        // is entered age valid ?
        if((age < 1) || (age > upperLimit)) {
            return false;
        }

        return true;
    },

    populatePers: function() {
        /* Populate a few extra fields that are needed 
           for the card send.
        */
        try {
            var sourceForm = document.forms[this.sendCardFormId];
            var targetForm = document.forms[this.facebookFormId];

            targetForm.message.value = sourceForm.fldMessage.value;
            targetForm.hdn.value = sourceForm.fldHeaderNum.value;
            targetForm.age.value = sourceForm.fldAge.value;
        }
        catch(err) { OOP.log(err); }
    },

    _showSignedIn: function() {
        this.parent();
        this.showCorrectCopy('intro-signed-in');
    },

    _showSignedOut: function() {
        this.parent();
        this.showCorrectCopy('intro-signed-out');
    },

    showCorrectCopy: function(id) {
        /*  Based upon the page state, show the correct page header copy.

            States are:
                -- signed out
                -- just clicked "Connect to FB" button
                -- signed in
        */
        var ids = ['intro-signed-in', 'intro-middle', 'intro-signed-out'];

        for (var i=0; i<ids.length; i++) {
            var copyContainer = document.getElementById(ids[i]);

            if (id == ids[i]){
                copyContainer.style.display = 'block';
            }
            else {
                copyContainer.style.display = 'none';
            }
        }
    }
};

var JLChristmasLetterPoster = {
    /*
       XXX: Must extend BasePoster

       Specialized version of BasePoster for JL Notecard. We need to override
       the markup for the user container (where the user's info is shown).
    */

    userTemplate: '' +
        '<div id="agi-fbshare-mthumb">\n' +
            '<ul>\n' +
                '<li>\n' +
                    '<img src="PICTURE" onclick="Poster.postProduct()" ' +
                        'style="cursor:pointer"/>\n' +
                    '<div>\nYou ' +
                        '<a href="javascript:Poster.postProduct()">' +
                            'post' +
                        '</a>\n' +
                    '</div>\n' +
                '</li>\n' +
            '</ul>\n' +
         '</div>\n',

    friendTemplate: '' +
            '<li>' +
                '<a href="javascript:Poster.postProduct(UID, \'NAME\')"><img ' +
                    'src="PICTURE" /></a>'+
                    '<span>NAME <a href="javascript:Poster.postProduct(UID, \'NAME\')">post</a>' +
                    '</span>'+
            '</li>',

    init: function(friendRenderer, pageAttrs, FBAttrs) {
        pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
        pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

        this.parent(friendRenderer, pageAttrs, FBAttrs);

        this.friendFbId = FBAttrs.friendFbId;
        this.numCols = FBAttrs.numCols || 4; // # users per row

        this.prodnum = pageAttrs.prodnum;
        this.messageId = 'fldMessage';
        this.sendCardFormId = 'frmSendCard';
        this.facebookFormId = 'facebookHiddens';

        this.copyContainerSignedIn = document.getElementById('jl-fbmess-signed-in');
        this.copyContainerSignedOut = document.getElementById('jl-fbmess-signed-out');

    },

    onLoggedIn: function() {
        /* Called when:
                -- user logs in
                -- it's determined user is logged in (on page load)

           -- fetch friends from FB
           -- render friend markup (+ display)
           -- render markup for user (+ display)
           -- display markup allowing sending by ecard
        */

        this.parent();

        // Allow user to flip back to ecard sending
        this.copyContainerSignedIn.style.display = 'block';
        this.copyContainerSignedOut.style.display = 'none';
    },

    onLoggedOut: function () {
        /* Called when:
                -- user logs out
                -- it's determined user is logged out (on page load)
           -- display markup allowing sending by ecard
        */
        this.parent();

        // Allow user to flip back to ecard sending
        this.copyContainerSignedIn.style.display = 'none';
        this.copyContainerSignedOut.style.display = 'block';
    },

    postProduct: function(friendFBID, friendName) {
        /* After checking the message and age field (if present),
           post the note card (call base's postProduct);
        */

        // function lives in the Flash
        var wasSuccessful = set_customizations();

        if (!wasSuccessful) {
            OOP.log("error calling set_customizations() function");
            return;
        }

        // JLNotecard allows personaliztion by recipient name.
        // Here we get the facebook user name to post to.
        // Requires the to_name parameter to be in the facebook hiddens list
        var nameNode = document.getElementById('to_name');
        if (nameNode){
            nameNode.value = 'You';
            if (friendName)
                nameNode.value = friendName
        }

        // Set the facebook recipients name in the pickup json stored in the facebook hiddens
        var pickupJson = dojo.fromJson(dojo.byId('facebookHiddens').json.value);
        pickupJson.recipient.name = nameNode.value;
        if (pickupJson.slideshow.images[0]){
            dojo.byId('facebookHiddens').hasphotos.value = 'True';
        } else {
            dojo.byId('facebookHiddens').hasphotos.value = '';
        }

        dojo.byId('facebookHiddens').json.value = dojo.toJson(pickupJson);
        dojo.byId('facebookHiddens').message.value = dojo.toJson(pickupJson);

        this.parent(friendFBID);
    }

};

var CNPPoster = {
    /*
       This class handles all functionality for posting to facebook
       from the create and print application.

            - Logging into Facebook
            - Displaying the user's FB friends
            - Posting a create and print card to a user's FB wall

            TODO: Transition base.js's ``postProduct()`` to allow the use of
            TODO  a callback function being passed to the FB.ui call.
            TODO  Our old connect code allowed similiar functionality,
            TODO  and could be useful in the graph architecture.

       For further definitions of some of the base calls, see CommonInterface.
    */

    init: function(friendRenderer, pageAttrs, FBAttrs) {
        /* Call our parent's init(), save off some attrs.

                @param friendRender given an HTML template, and a User
                                    object, it will swap in all the dynamic
                                    bits in the HTML template and return it.
                @param pageAttrs  page related values (dictionary)
                                    e.g. ``ahost``, ``source``
                @param FBAttrs  FB related values (dictionary)
                                  e.g. ``attachment``, ``friendID``
        */
        pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
        pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

        this.parent(friendRenderer, pageAttrs, FBAttrs);

        this.friendFbId = FBAttrs.friendFbId;
        this.numCols = FBAttrs.numCols || 3; // # users per row
        this.successPostCallback = pageAttrs.callBack;
    },

    postProduct: function(friendId) {
        /* Post a product to a friend's (or the user's) FB Wall.
                -- Insert usage
                -- Retrieve usagenum
                -- Swap usagenum into attachment
                -- Pop dialog
                -- On a succesful post, execute the successPostCallback

                If ``friendId`` is empty, it will post to user's wall.


            TODO: Transition base.js's ``postProduct()`` to allow the use of
            TODO  a callback function being passed to the FB.ui call.
        */

        // make copy so we can re-use ``this.attachment``
        var attachment = clone(this.attachment);

        // Insert record + retrieve usage number
        var usageNumber = this.insertUsageRecord(
                this.ahost + this.processUsagePage,
                document.facebookHiddens);

        // Swap usagenum into attachment
        this._attachUsageNumber(attachment, usageNumber);

        // Storing necessary page info for inclusion into the callback function
        // for posting to FB below.

        // Store long URL so we can update properties appropriately.
        original_long_url = attachment.href;
        public_short_url = this.generateShortUrl(attachment);

        if (public_short_url && public_short_url.length > 0) {
            attachment.href = public_short_url;

            for( var property_key in attachment.properties ) {
                var property = attachment.properties[property_key];

                if( property.href && property.href === original_long_url ) {
                    property.href = public_short_url;
                }
            }
        }

        // Pop dialog (for posting to FB Wall)
        FB.ui(
            {
            method: 'stream.publish',
            target_id: friendId,
            message: '',
            user_message_prompt: '',
            attachment: attachment,
            action_links: attachment.action_links || [{
                'text': this.site,
                'href': this.ahost + '?source=' + this.source
            }]
            },
            OOP.hitch(this.successPostCallback, this)
        );
    }

};

var PetContestPoster = {
    /*
       XXX: Must extend BasePoster

       Pet Contest Poster for BMA Pets Contest for BMA. We need to override
       the markup for the user container (where the user's info is shown).
    */

    userTemplate: '' +
        '<h2 id="agi-fbshare-welcome">\n' + 
            '<a href="#" onclick="Poster.postPetMessage()" ' +
             'style="text-decoration:underline">' +
                 'Post this contest to your own wall' +
             '</a>\n' + 
        '</h2>\n'+
        '<div id="agi-fbshare-mthumb">\n' +
            '<ul>\n' +
                '<li>\n' +
                    '<img src="PICTURE" onclick="Poster.postPetMessage()" ' +
                        'style="cursor:pointer"/>\n' +
                    '<div>\nNAME ' + 
                        '<a href="#" onclick="Poster.postPetMessage()">' +
                            'post to your wall' +
                        '</a>\n' +
                    '</div>\n' +
                '</li>\n' +
            '</ul>\n' +
         '</div>\n',

    friendTemplate: '' +
            '<li>' +
                '<a href="javascript:Poster.postPetMessage(UID)"><img ' +
                    'src="PICTURE" /></a>'+
                    '<span>NAME <a href="javascript:Poster.postPetMessage(UID)">post</a>' +
                    '</span>'+
            '</li>',

    init: function(friendRenderer, pageAttrs, FBAttrs) {
         pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
         pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

         this.parent(friendRenderer, pageAttrs, FBAttrs);
    },

    postPetMessage: function(friendId) {
        /* Post a product to a friend's (or the user's) FB Wall.

                -- If ``friendId`` is empty, it will post to user's wall.
        */

        // make copy so we can re-use ``this.attachment``
        var attachment = clone(this.attachment);

        // Pop dialog (for posting to FB Wall)
        FB.ui(
                {
                    method: 'stream.publish',
                    target_id: friendId,
                    message: '',
                    user_message_prompt: '',
                    attachment: attachment,
                    action_links: attachment.action_links || [{
                        'text': this.site,
                        'href': this.ahost + '?source=' + this.source
                    }]
                });
    }

};


var BackToSchoolContestPoster = {
    /* 
       XXX: Must extend BasePoster

       BackToSchool Contest Poster for AG Back To School Contet. 
       We need to override the markup for the user container 
       (where the user's info is shown).
    */

    userTemplate: '' +
        '<h2 id="agi-fbshare-welcome">\n' + 
            '<a href="#" onclick="Poster.postBackToSchoolMessage()" ' +
             'style="text-decoration:underline">' +
                 'Post to your own wall' +
             '</a>\n' + 
        '</h2>\n'+
        '<div id="agi-fbshare-mthumb">\n' +
            '<ul>\n' +
                '<li>\n' +
                    '<img src="PICTURE" onclick="Poster.postBackToSchoolMessage()" ' +
                        'style="cursor:pointer"/>\n' +
                    '<div>\nNAME ' + 
                        '<a href="#" onclick="Poster.postBackToSchoolMessage()">' +
                            'post to your wall' +
                        '</a>\n' +
                    '</div>\n' +
                '</li>\n' +
            '</ul>\n' +
         '</div>\n',

    friendTemplate: '' +
            '<li>' +
                '<a href="javascript:Poster.postBackToSchoolMessage(UID)"><img ' +
                    'src="PICTURE" /></a>'+
                    '<span>NAME <a href="javascript:Poster.postBackToSchoolMessage(UID)">post</a>' +
                    '</span>'+
            '</li>',

    init: function(friendRenderer, pageAttrs, FBAttrs) {
         pageAttrs.userTemplate = pageAttrs.userTemplate || this.userTemplate;
         pageAttrs.friendTemplate = pageAttrs.friendTemplate || this.friendTemplate;

         this.parent(friendRenderer, pageAttrs, FBAttrs);
    },

    postBackToSchoolMessage: function(friendId) {
        /* Post a product to a friend's (or the user's) FB Wall.
                
                -- If ``friendId`` is empty, it will post to user's wall.
        */

        // make copy so we can re-use ``this.attachment``
        var attachment = clone(this.attachment);

        // Pop dialog (for posting to FB Wall)
        FB.ui(
                {
                    method: 'stream.publish',
                    target_id: friendId,
                    message: '',
                    user_message_prompt: '',
                    attachment: attachment,
                    action_links: attachment.action_links || [{
                        'text': this.site,
                        'href': this.ahost + '?source=' + this.source
                    }]
                });
    }

};

