
/*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*/
