$(document).ready(function(){
	if($.browser.msie){
		$("a").attr("hideFocus", "true");
		try{if($.ie6) document.execCommand("BackgroundImageCache", false, true);}catch(e) {};
	}
});
/*ie6 status hover event handler*/
function h(){
	h.oldCl = $(this).css("background-color");
    this.style.backgroundColor = "#f7f7f7";
    $("div.actionsV2 a", this).each(function(){
    	this.style.display = "block";
    });
}
function o(){
    this.style.backgroundColor = h.oldCl || "";
    $("div.actionsV2 a", this).each(function(){
    	this.style.display = "none";
    });
    $("div.actionsV2 .like", this).each(function(){
    	this.style.display = "block";
    });
}
/*光标移至最后面*/
function focusEnd(o){
	try{
       if(top.$.browser.msie) top.$("#fixedFocusEndBug").focus();
	   o.focus();
	   if(o.selectionStart != undefined){
	       o.selectionStart = o.value.length;
	   }else{
		   var oTextRange = document.selection.createRange();
		   oTextRange.collapse(true);
		   oTextRange.moveStart("character",  o.value.length);
		   oTextRange.select();
		   o.focus();
	   }
   }catch(e){}
}
/*光标移至最前面*/
function focusStart(o){
	try{
	   o.focus();
	   if(o.selectionStart != undefined){
	       o.selectionEnd = 0;
	   }else{
		   var oTextRange = document.selection.createRange();
		   oTextRange.collapse(true);
		   oTextRange.moveEnd("character",  -o.value.length);
		   oTextRange.select();
		   o.focus();
	   }
	}catch(e){}
}
/*关注(需要查找当前页面元素，所以不能抽到top)*/
function streamFollow(uid, ele, sid) {
    $.postJSONEx("/dd/follow.ajax", {uid: uid || 0}, function(reply) {
       $(".follow_"+uid).fadeOut(function(){$(this).remove()});
       top.showMessage("关注成功");
       return false;
    },function(reply,error){
    	if (error == "REQUEST SEND") {
        	$(".follow_"+uid).fadeOut(function(){$(this).remove()});
            top.showMessage("关注此用户需要认证, 请等待");
            return false;
        } else if (error == "BLOCK") {
        	$(".follow_"+uid).fadeOut(function(){$(this).remove()});
            top.showMessage("您好像被他拉进黑名单了");
            return false;
        }else {
        	top.showMessage(top.ajaxError[error]||error);
        }
    });
}
/*光标移至最前面*/
function focusStart(o){
	try{
	   o.focus();
	   if(o.selectionStart != undefined){
	       o.selectionEnd = 0;
	   }else{
		   var oTextRange = document.selection.createRange();
		   oTextRange.collapse(true);
		   oTextRange.moveEnd("character",  -o.value.length);
		   oTextRange.select();
		   o.focus();
	   }
	}catch(e){}
}
/*关注(需要查找当前页面元素，所以不能抽到top)*/
function streamFollow(uid, ele, sid) {
    $.postJSONEx("/dd/follow.ajax", {uid: uid || 0}, function(reply) {
       $(".follow_"+uid).fadeOut(function(){$(this).remove()});
       top.showMessage("关注成功");
       return false;
    },function(reply,error){
    	if (error == "REQUEST SEND") {
        	$(".follow_"+uid).fadeOut(function(){$(this).remove()});
            top.showMessage("关注此用户需要认证, 请等待");
            return false;
        } else if (error == "BLOCK") {
        	$(".follow_"+uid).fadeOut(function(){$(this).remove()});
            top.showMessage("您好像被他拉进黑名单了");
            return false;
        }else {
        	top.showMessage(top.ajaxError[error]||error);
        }
    });
}
/*点页面处理函数*/
function gotoPage(page) {
    var href = window.location.href;
    window.location.href = href.indexOf("cp=") > -1 ? (href.replace(/cp=\d+/,"cp="+page)) : (href.indexOf("?") > -1 ? (href+"&cp="+page) : (href+"?cp="+page) );
}
/*阻止事件冒泡*/
function stopPropagation(e){
	if(e) e.stopPropagation();	
}
/*调整class为.adjust_photo的网页配图并显示*/
function adjustStreamImg(imgsCt, limit, classArr){
	if (!imgsCt || imgsCt.length == 0) return;
	imgsCt.each(function(){
		if($("img", this).length) return;
		var _this = this;
		$(this).hide();
		var oImg = new Image();
		var gif = false;
		oImg.onerror = function(){
		    $(_this).closest(".imgArea").remove();
			oImg = null;
		}
		oImg.onload = function(){
			if(!gif){
				var h = this.height, w = this.width;
				limit = limit?limit:{w:90, h: 80};
				if(w>limit.w){
					h = parseInt(limit.w*h/w,10)||0;
					w = limit.w;
				}
				if(h>limit.h){
					w = parseInt(w*limit.h/h,10)||0;
					h = limit.h;
				}
				$(this).css({width: w, height: h}).appendTo(_this);
				oImg.className= typeof(classArr)==="undefined"?"photo_url fl imgBd":classArr;
				$(_this).show();
				oImg = null;
				gif = true;
			}
		}
		oImg.src = $(this).attr("pic");
	});
}
/*头像错误*/
function imgError(sex, size){
	if(sex == 2) this.src = "/images/buddy_icon/g"+size+"x"+size+".jpg";
	else  this.src = "/images/buddy_icon/"+size+"x"+size+".jpg";
}
/*光标移至最后面*/
function focusEnd(o){
	try{
	   o.focus();
	   if(o.selectionStart != undefined){
	       o.selectionStart = o.value.length;
	   }else{
		   var oTextRange = document.selection.createRange();
		   oTextRange.collapse(true);
		   oTextRange.moveStart("character",  o.value.length);
		   oTextRange.select();
		   o.focus();
	   }
   }catch(e){}
}
/*
 * @Deprecated
 * */
function moreArtical(ele, sType, uid, extra_para, is_user_fav, statusType,attach_id,label) {
	ele.blur();
	sType = sType || "friends";
	var oUrl ={
		dm_sent: "/dd/dm_sent_more.ajax",
		dm_receive: "/dd/dm_receive_more.ajax",
		dm_system: "/dd/dm_system_more.ajax",
        followings: "/dd/followings_more.ajax",
        followers: "/dd/followers_more.ajax",
        conversations: "/dd/conversations_more.ajax"
    };
	is_user_fav = is_user_fav?true:false;
    var para = extra_para || {};
    if(!moreArtical.curPage) moreArtical.curPage = 1;
    moreArtical.curPage++;
    para.page = moreArtical.curPage;
    para.is_user_fav = is_user_fav;
    para.uid = uid||0;
    para.label = label || '';
    if(statusType) para.status_type = statusType;
    $(ele)[0].value = "正在读取中...";
    $(ele)[0].disabled = false;
    $.ajax({
        type: "GET",
        url: oUrl[sType],
        data: para,
        success: function(reply){
	        $(ele)[0].disabled = false;
	        $(ele)[0].value = "更多";    	
			if(!reply.trim()){
				$(ele).parent().hide();
				return true;
		     }
	    	 if(reply) {
	    		 var scripts = [];
	    		 $("#list_ct li:last").css('border-bottom', '3px solid #0B7ECE'); //4mm 2010-01-11
	    		 $(attach_id?"#"+attach_id:"#list_ct").append(oAdd);
	    		 var oFrag = document.createDocumentFragment();
	    		 var oUl = document.createElement("UL");
	    		 oUl.innerHTML = reply.replace(/<script[^>]*>([\s\S]+?)<\/script>/gi, function($0, $1){
	    			 scripts.push($1);
	    			 return "";
	    		 });
                 var oAdd = $(oUl.childNodes);
	    		 $(attach_id?"#"+attach_id:"#list_ct").append(oAdd);
	    		 $.globalEval(scripts.join("\r\n"));
	    		 try{if (_nomore_) $(ele).hide();}catch(e){}
	         }
        },
        dataType: "html"
    });
}
var rjXor = {
		decrypt: function(key, message, delimiter) {
	        if(!message) return "";
	        if(!delimiter) delimiter = "|";
			var message_a = message.split(delimiter);
			var result = "";
			for (var i = 0, l = message_a.length; i < l; i++) {
				var m = message_a[i];
				if(m){
					result += String.fromCharCode(m ^ key);
				}
			}
			return result;
		},
		encrypt: function(key, message, delimiter){
			if(!message) return "";
			if(!delimiter) delimiter = "|";
			var ret = [];
			for(var i = 0, l = message.length; i < l; i++){
				ret.push(message.charCodeAt(i)^key);
			}
			return ret.join(delimiter);
		}
}
//tag表情
var tagEmote = ["杯具","蛋疼","八卦","我擦","orz","求交往","囧死","幸福","感谢国家"];