/*
author:rady huang
website: http://www.radys.cn
date: 2010-5-11 16:06
plugins name: rady.ui.share
need facebox support
version v1.0
usage: var share = new rady.ui.share({title:"Rady Blog",url:"http://www.radys.cn",content:"a web developer website."})
*/
if (typeof rady === 'undefined')
    var rady = window.rady = {};
if (typeof rady.ui === 'undefined')
    rady.ui = {};
(function($) {
    rady.ui.share = function(options) {
        this.opts = $.extend({}, rady.ui.share.defaults, options);

        this._title = this.opts.title;
        this._url = this.opts.url;
        this._content = this.opts.content;
        this._sharetype = this.opts.sharetype;

        this._init();
    };

    rady.ui.share.prototype = {
        _init: function() {
            var $this = this;
            var shareboxHtml = '\
			<div id="share-item-box">\
  <div class="item-title">分享到我的空间</div>\
   <div class="item-body">\
   <ul>\
   <li><label for="sharetitle">标题</label><input type="text" id="sharetitle" maxsize="50"/></li>\
   <li class="text"><label for="sharecontent">描述</label><textarea id="sharecontent"></textarea></li>\
   <li><label for="shareurl">地址</label><input type="text" id="shareurl" maxsize="200"/></li>\
   </ul>\
   </div>\
   <div class="item-button"><input type="hidden" id="sharetype"/><input type="button" id="btnshareitem" value="提交" /></div>\
</div>';

            $.facebox.settings.fadeout = 0;
            $.facebox.loading()
            $.facebox.reveal(shareboxHtml);

            $("#sharetitle").val($this._title);
            $("#sharecontent").val($this._content);
            $("#shareurl").val($this._url);
            $("#sharetype").val($this._sharetype);

            $this._bindEvent();
        },
        _bindEvent: function() {
            var $this = this;
            $("#btnshareitem").click(function() {
                var title = $("#sharetitle").val()
                if (!title) { alert('标题不能为空'); $("#sharetitle").focus(); return false; }
                var content = $("#sharecontent").val();
                if (!content) { alert('描述不能为空'); $("#sharecontent").focus(); return false; }
                var url = $("#shareurl").val()
                var sharetype = $("#sharetype").val()
                if (!url) { alert('地址不能为空'); $("#shareurl").focus(); return false; }
                $.getJSON("http://www.chinaaet.com/tools/ajax.aspx?otype=shareitem&content=" + escape(content) + "&title=" + escape(title) + "&sharetype=" + sharetype + "&url=" + url + "&jsoncallback=?", function(data) {
                    if (data.isok == false) { alert(data.message); }
                    else {
                        $.facebox.settings.fadeout = 2000;
                        $.facebox.loading()
                        $.facebox.reveal(data.message);
                    }
                })
            })
        }
    };

    //设计选项默认值
    rady.ui.share.defaults = {
        title: "test",
        url: "http://www.radys.cn",
        content: "content",
        sharetype: 1
    };
})(jQuery)
