// copyright © ePals 2008
// author: dave moore
// 
// this script translates forum posts.  it should be called on a jquery
// instance.  each post must have elements of the following classes:
//
// .ForumPostTitle - the title
// .ForumPostContentText - the message body
// .ForumPostTranslatedTitle - placeholder for the translated title
// .ForumPostTranslatedText - placeholder for the translated message body
//

(function($) {
    $.fn.translate = function(o) {
        return new $translate(this, o);
    };

    var defaults = {
        sourceID: 'EN',
        destID: 'ES',
        MsgBody: ''
    };

    $.translate = function(e, o) {
        this.options = $.extend({}, defaults, o || {});

        // translate the title

        var title = $(e).find(".ForumPostTitleArea").find(".ForumPostTitle").text();
        var body = $(e).find(".ForumPostBodyArea").find(".ForumPostContentText").text();

        //alert(body);

        $.post("/translate.aspx",
        { sourceID: this.options.sourceID, destID: this.options.destID, MsgBody: title },
                        function(data) {
            //alert(data);
            (e).find(".ForumPostBodyArea").find(".ForumPostTranslatedTitle").text(data);
        }
                );
        //        alert(this.options.MsgBody);
        // translate the body
        //        this.options.MsgBody = escape($(e).find(".ForumPostContentText").text());

        $.post("/translate.aspx",
        { sourceID: this.options.sourceID, destID: this.options.destID, MsgBody: body },
                        function(data) {
            //alert(data);
            (e).find(".ForumPostBodyArea").find(".ForumPostTranslatedText").text(data);
        }
                );
        //document.domain = oldDom;
    };

    var $translate = $.translate;

    $translate.fn = $translate.prototype = {
        translate: '1.0.0'
    };
    $translate.fn.extend = $translate.extend = $.extend;
    //shaz
})(jQuery);

