
/*CommentSmiley start*/
//用于给评论增加表情功能
function initCommentSmiley(){
    //局部变量用于防止产生过多全局函数
    var obj={
        addSmileyBar:function(bib){
            if(bib.smileyBar)return;
            if(!bib.postCommentBox)return;
			var _bar=$se('dd','smiley','表情：');
			for(var i=1;i<=16;i++){
				var _img=$se('img');
				_img.src='plugins/CommentSmiley/onion/'+i+'.gif';
				_img.style.width='25px';
				_img.style.height='25px';
				_bar.appendChild(_img);
				_img.style.cursor='pointer';
				_img.style.marginRight='2px';
				
				_img.onclick=(function(s){
					return function(){
						var _fb=bib.postCommentBox.main;
						_fb.setValue('content',_fb.getValue('content')+'[s:'+s+']');
					}
				})(i);
			}
			bib.postCommentBox.box.firstChild.insertBefore(_bar,bib.postCommentBox.box.firstChild.lastChild);
			bib.smileyBar=true;
        }
        ,onToggleViewComment:function(topicId,dl){
			var bib=BlogItemBoxes[topicId];
			if(bib.showSmileyHook)return;
			bib.showSmileyHook=true;
			var self=this;
			var obj2={};
			obj2.showSmiley2=function(c){
				if(!c==c.parentNode.firstChild)return;
				self.showSmiley(bib.viewCommentBox);
			}
			X2.Observer.observeAsEvent(obj2,'showSmiley2',bib,'setOpen');
        }
        ,showSmiley:function(b){
            var _html=b.innerHTML;
			_html=_html.replace(/(\[s:(\d+)\])/g,'<img src="plugins/CommentSmiley/onion/$2.gif" alt=""/>');
			b.innerHTML=_html;
        }
        ,onTogglePostCommentBox:function(topicId,dl){
            var bib=BlogItemBoxes[topicId];
            if(bib.smileyBar)return;
			this.addSmileyBar(bib);
        }
    };
    try{
		X2.Observer.observeAsEvent(obj,'onTogglePostCommentBox',window,'togglePostCommentBox');
		X2.Observer.observeAsEvent(obj,'onToggleViewComment',window,'toggleViewComment');
	}catch(e){}
	
	//如果是单篇日志显示，需要对其中的评论进行替换
	if(window._firstTopicIdOfCommentList){
	    var _vcb=$('firstTopicIdOfCommentList'+_firstTopicIdOfCommentList);
	    obj.showSmiley(_vcb);
	    
	}
}

//绑定到初始化过程
X2.Observer.observe(window,'initCommentSmiley',window,'init');
/*CommentSmiley end*/

/*LatestArticles start*/
function PluginConfig_LatestArticles(myPcb){
    myPcb.showTip('正在获取数据，请稍候……');
    var json=new X2.Json('plugins/LatestArticles/ajax.aspx',myPcb.tipBox);
    json.onlogicalsuccess=function(jso){
	    var fb=new FormBox('commonFormBox');
	    fb.insertItem("text","count",{attributes:{maxLength:4,style:'width:40px;'},value:jso.singleInfo,foreLabel:'最新日志显示数量：'});
	    fb.insertItem("button","btnOk",{sameLine:true,className:'button',sameLine:true,value:'确定',tip:'* 只能是数字'});
	    myPcb.body.appendChild(fb.getBox());
	    myPcb.setWidth(420);
    	myPcb.hideTip();
    	
    	
	    fb.items['btnOk'].onclick=function(){
	        var count=fb.getValue('count');
	        if(!/^\d+$/g.test(count) || count==''){
	            myPcb.showTip('参数必须为数字！');
	            return;
	        }
	        myPcb.showTip('正在提交数据，请稍候……','noButton');
	        var json2=new X2.Json('plugins/LatestArticles/ajax.aspx',myPcb.tipBox);
	        json2.onlogicalsuccess=function(jso){
	            myPcb.showTip('参数设置成功！');
    	        
	        }
	        json2.open('setCount',{count:count});
	    }
	}
	json.open('getCount');
}
/*LatestArticles end*/
