function addFriend(fid) {
	$.post("/addFriend.htm", {fid:fid}, function(data){addFriendCallback(data);});
	$.mytuyaloading.show("正在添加好友...");
}
function addFriendCallback(data) {
	var result = eval("(" + data + ")");
	if(result.status == "success") {
		$.mytuyaloading.setMessage("添加好友成功！");
		if(document.getElementById('addFriendLink') != null)
			$('#addFriendLink').remove();
		if(document.getElementById('myspace_index_nav_friend') != null) {
			$('#myspace_index_nav_friend').html('我的好友');
		}
	} else {
		$.mytuyaloading.setMessage(result.message);
	}
	$.mytuyaloading.hide();
}

(function($){
	$.myplace = {
		id:null,
		name:null,
		uid:null
	};
	$.visitor = {
		uid:null
	}
	 $.tuba = {
		id:null,
		name:null,
		uid:null,
		joinTuba:function(){
			if($.visitor.uid == null) {$.tydialog("您还没有登录");window.setTimeout(function(){$.tydialog.close();}, 2000);return;};
			$.post('/joinTuba.htm', {tubaid:$.tuba.id}, function(data){$.tuba.joinTubaCallback(data);});
			$.tydialog("正在加入涂吧,请稍候...");
		},
		joinTubaCallback:function(data)	{
			var result = eval('(' + data + ')');
			if(result.status == 'success') {
				$.tydialog("您已经成功加入该涂吧");
				window.location.reload();
			} else {
				$.tydialog("错误:加入涂吧失败，您可能已经加入过该涂吧");
			}
			window.setTimeout(function(){$.tydialog.close();}, 2000);
		}
	};
	
	$.constant = {
		replydiv : '<div class="mytuya_review_myself"> \
	<div class="mytuya_review_portrait"><img src="{avatar}" /></div> \
	<div class="mytuya_review_content"> \
	<p><span class="mytuya_review_author"><a href="/myspace/{uid}/"  class="author">{nickname}</a></span><span class="fontpink">答</span></p> \
	<p><span>{reply}</span></p> \
</div></div>'
	};
	
	$.errortips = {
		showErrMsgAfter:function(errMsg, objectid) {
			if(document.getElementById('errMsg') != null) {
				$('#errMsg').remove();
			}
			$('<span id="errMsg"></span>').insertAfter(objectid).html(errMsg);
			window.setTimeout(function(){$('#errMsg').fadeOut("slow", function(){$(this).remove();});}, 2000);
		}
	}; 
})(jQuery);

$(document).ready(function(){
	setMenuAction();
});
function setMenuAction() {
	$(".menu_li").hover(function(){
	$(this).addClass("hover");
	}, function(){
		$(".candy_menu").slideUp(500);
		$(this).removeClass("hover");
	});

	$(".menu_li > span > img").click(function(){$(this).parent().siblings(".candy_menu").slideDown(500);});
}
function writeCookie(name, value, hours)
{
	var expire = "";
	if(hours != null)
	{
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
	document.cookie = name + "=" + escape(value) + expire + ";path=/";
}
function readCookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{ 
	offset = document.cookie.indexOf(search);
	if (offset != -1)
	{ 
	 offset += search.length;
	 end = document.cookie.indexOf(";", offset);
	 if (end == -1) end = document.cookie.length;
	 cookieValue = unescape(document.cookie.substring(offset, end))
	}
	}
	return cookieValue;
}