$(document).ready(function() {
});

  	/*打開送完成的按鈕*/
  	function showOK(){
  		$('#ok').show();
  	}
  	/*隱藏送完成的按鈕*/
  	function hideOK(){
  		$('#ok').hide();
  	}
  	/*打開需要協助的按鈕*/
  	function showNOK(){
  		$('#nok').show();
  	}
  	/*隱藏需要協助的按鈕*/
  	function hideNOK(){
  		$('#nok').hide();
  	}
  	/*打開送愛心的按鈕*/
  	function showSendHeart(){
	    	hideOK();
	    	hideNOK();
  		$('#sendheart').show();
  	}
  	/*隱藏送愛心的按鈕*/
  	function hideSendHeart(){
  		$('#sendheart').hide();
  	}
  	/*男生說話*/
  	function boySays(str){
  		$('#content').append("[cloud]不要發我好人卡! 說:\r\n");
  		$('#content').append('<div class="talkingtext boy">'+str+"</div>\r\n");
  		scrollToBottom();
  	}
  	/*女生說話*/
  	function girlSays(str){
	    	$('#content').append("小優~*我的新家在痞客邦 說:\r\n");
	    	$('#content').append('<div class="talkingtext girl">'+str+"</div>\r\n");
  		scrollToBottom();
  	}
  	function helpSays(str){
  		$('#content').append("痞客邦來幫你忙 說:\r\n");
  		$('#content').append('<div class="talkingtext help">'+str+"</div>\r\n");
  		scrollToBottom();
  	}
  	/*變更女生顯示圖片*/
  	function girlPic(picurl){
  		$('#dp1').src = picurl;
  	}
  	/*捲到最下*/
  	function scrollToBottom(){
  		if($('#content')[0].scrollTop + 266 < $('#content')[0].scrollHeight)
  		{
  			$('#content')[0].scrollTop = $('#content')[0].scrollHeight-266;
  		}
  	}
  	/*開關活動辦法*/
  	function showPolicy(){
	    	$.get('addhits.php', {'url':'policy'});
	    	$("#part").hide();
	    	$("#unit").hide();
  		$('#billboard').hide();
  		$('#policy').show();
  	}
  	function hidePolicy(){
  		$('#policy').hide();
	    	$("#part").show();
	    	$("#unit").show();
  	}
  	/*開關排行榜*/
  	function showBillboard(page){
	    $("#part").hide();
	    $("#unit").hide();
	    $.get('addhits.php', {'url':'board'});
	    $.post('get_bill.php', {'page':page}, function(data) {
		$("#billboard_content").html(data.content);
		$("#billboard_page").html(data.page);
  		$('#policy').hide();
  		$('#billboard').show();
	    }, 'json');
  	}
  	function hideBillboard(){
  		$('#billboard').hide();
	    	$("#part").show();
	    	$("#unit").show();
  	}
  	function gotoPage(p)
  	{
  		//$('commend')
  		//$('billboard_page')
  		alert("請在gotoPage function加上換頁的AJAX，更換下頁的內容到#commend，更新頁碼到#billboard_page")
  	}
  	function init(){
  		hideOK();
  		hideNOK();
  		hideSendHeart();
  		hidePolicy();
  		hideBillboard();
  	}

	function addMsg(stat, uid) {
	    var m;
	    var sec;
	    $('#content').empty();
	    hideOK();
	    hideNOK();
	    var ms = Math.floor(Math.random() * 4000) + 1000;
	    $.post('get_msg.php', {'stat': stat, 'u':uid}, function(data) {
		if (data) {
		   for (var i in data.msg) {
			m = data.msg[i];
			sec = parseInt(i) - 1;
			if (m.people) {
			    if ('girl' == m.people) {
			    	setTimeout("girlSays(\"" + m.content + "\");", sec * ms);
			    }

			    if ('boy' == m.people) {
			    	setTimeout("boySays(\"" + m.content + "\");", sec * ms);
			    }
			}
		    }
		    setTimeout("showOK();showNOK();", sec * ms);
		}
	    }, 'json');
	}

	function loadMsg(stat){
	    for (var i = 1 ;i <= stat; i++) {
		addMsg(i);
	    }
	}
	
	function addHelp(stat, uid){
	    $.post('get_msg.php', {'stat': stat, 'help':'true', 'u':uid}, function(data) {
		helpSays(data.help);
		helpTimes--;
		$("#times").text(helpTimes);
	    }, 'json');
	}



