/*
'=====================================================================
' Module Name:
' File name: head_foot.js
' Author: william.lu
' Project : my_bebo
' Copyright (c) all rights reserved by juuyou.com Co., LTD.
' Create on 2009/10/19
' Version: 1.0
'
'=====================================================================
'*********************************************************************
' Usage: 页头页尾JS函数集
'
'*********************************************************************
*/

/**  定义juuyou.headfoot命名空间  **/
juuyou.headfoot = {};

/**  切换系统消息的显示和关闭  **/
juuyou.headfoot.blRenewFlashDttm = true;
$(document).ready(function(){
	$(".j_foot_sys_info").live("click", function(){
		if(juuyou.headfoot.blRenewFlashDttm){
			juuyou.headfoot.blRenewFlashDttm = false;
		}else{
			juuyou.headfoot.blRenewFlashDttm = true;
		}
		$("#j_div_foot_sys_info").slideToggle("slow");
		if(juuyou.headfoot.blRenewFlashDttm){
			$("#j_fixed_info_gif").removeClass("fixed_info_gif");
			$("#j_fixed_info_gif").addClass("fixed_info_gif02");
			flashSysInfoDttm = juuyou.common.getNow();
			juuyou.headfoot.iniFlashSysInfo2();
		}
	});
});

/**  系统消息刷新  **/
var intervalFlashSysInfoProcess = setInterval("juuyou.headfoot.iniFlashSysInfo2()", 60000);
juuyou.headfoot.iniFlashSysInfo2 = function(){
	if(blFlashSysInfo){
		var url = "http://saywo.com/json/head_foot/flashSysInfo2.php?flashDttm=" + flashSysInfoDttm + "&jsonCallback=?";  
		$.getJSON(url,function(json){
			var data = $.trim(json.msg);
			if(data == juuyou.common.json.failure){			
			}else{
				var strTemp = data.substr(0, 11);
				if(strTemp == "Bad Request"){
					return;
				}
				if(data.length>3){
					var intTemp = data.indexOf("|");
					var intFlashTemp = data.indexOf("&");
					var intSysInfoCnt = data.substring(0, intTemp);
					var intFlashCnt = data.substring(intTemp+1, intFlashTemp);
					var strFlashData = data.substring(intFlashTemp+1);

					$("#j_span_sys_info_cnt").html(intSysInfoCnt);
					$("#j_sys_info_ul").html(strFlashData);

					if(intFlashCnt > 0){
						$("#j_fixed_info_gif").addClass("fixed_info_gif");
						$("#j_fixed_info_gif").removeClass("fixed_info_gif02");
					}

					//flashSysInfoDttm = juuyou.common.getNow();
				}
			}
		});  

		var messageURL = "http://saywo.com/message/messageCount.php?jsonCallback=?";  
		$.getJSON(messageURL,function(json){
			var data = $.trim(json.msg);
			if(data == juuyou.common.json.failure){			
			}else{
				var strTemp = data.substr(0, 11);
				if(strTemp == "Bad Request"){
					return;
				}
				$("#f_li_foot_message").html(data);
			}
		});
		var virtualGiftURL = "http://saywo.com/json/virtualGift/unreadVirtualGiftCount.php?jsonCallback=?";  
		$.getJSON(virtualGiftURL,function(json){
			var data = $.trim(json.msg);
			if(data == juuyou.common.json.failure){			
			}else{
				var strTemp = data.substr(0, 11);
				if(strTemp == "Bad Request"){
					return;
				}
				$(".f_virtual_gift_foot_count").html(data);
			}
		});		
	}
}

juuyou.headfoot.iniFlashSysInfo = function(){
	if(blFlashSysInfo){
		$.ajax({
	 		type:"GET",
			url:"http://saywo.com/json/head_foot/flashSysInfo.php",
			async:true,
			data: {
				flashDttm: flashSysInfoDttm
			},
			success:function(data){
				var data = $.trim(data);
				if(data == juuyou.common.json.failure){			
				}else{
					var strTemp = data.substr(0, 11);
					if(strTemp == "Bad Request"){
						return;
					}
					if(data.length>3){
						var intTemp = data.indexOf("|");
						var intFlashTemp = data.indexOf("&");
						var intSysInfoCnt = data.substring(0, intTemp);
						var intFlashCnt = data.substring(intTemp+1, intFlashTemp);
						var strFlashData = data.substring(intFlashTemp+1);

						$("#j_span_sys_info_cnt").html(intSysInfoCnt);
						$("#j_sys_info_ul").html(strFlashData);

						if(intFlashCnt > 0){
							$("#j_fixed_info_gif").addClass("fixed_info_gif");
							$("#j_fixed_info_gif").removeClass("fixed_info_gif02");
						}

						//flashSysInfoDttm = juuyou.common.getNow();
					}
				}
			}
		});
	}
}


//电台控制
$(document).ready(function(){
	$(".j_a_foot_radio").live("click", function(){
		$("#j_div_foot_radio").slideToggle("slow");
		
		//var objI=$("#j_li_foot_radio").offset();
		//var strCss={left:objI.left-2,top:objI.top-120};
		//$("#j_div_foot_radio").css(strCss);
	});

	//$("#j_div_foot_radio").draggable({ cancel:'object' });
	juuyou.headfoot.initFlashRadioPlayer();
});

juuyou.headfoot.initFlashRadioPlayer = function(){
	var intR1 = Math.random();
	var sf1 = new SWFObject("http://saywo.com/interest/mp3_player.swf?temp="+intR1+"&config=http://saywo.com/interest/foot_config.xml?temp="+intR1,"j_foot_flash_radio","300","80","9","#FFFFFF");
	sf1.addParam("allowscriptaccess","always");
	sf1.addParam("flashvars","file=http://saywo.com/interest/musicRadioFeed.php");
	sf1.write("j_div_foot_radio_player");
}



var   driftTimeOutHandle; 


$(document).ready(function(){
var is_drift_out=true;
var is_message_txt_focus = false;
var is_comment_txt_focus = false;
$(".f_user_nick_name_a").live("mouseover", function(){
	clearTimeout(driftTimeOutHandle); 

	if(is_drift_out){
	 var targetId = $(".drift_profile");
	  var A_top = $(this).offset().top + $(this).outerHeight(true);  //  1
	  var A_left =  $(this).offset().left;
	  var strFriendUID = $(this).attr("uid");
		driftTimeOutHandle   =   setTimeout( function(){
	  targetId.css({"position":"absolute","top":A_top+"px" ,"left":A_left+"px"});
	  targetId.show();
	  is_message_txt_out = false;
		$.ajax({
	 		type:"POST",
			url:"../json/driftUserInfo.php",
			async:true,
			data: {
			friend_uid: strFriendUID
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$(".drift_profile").empty();
					$(".drift_profile").append(data);
					$("#f_drift_message_txt").live("focus",function(){  
						is_message_txt_focus = true;
					}) ;
					$("#f_drift_message_txt").live("blur",function(){  
						is_message_txt_focus = false;
					}) ;
					$("#f_drift_profile_comment_txt").live("focus",function(){  
						is_comment_txt_focus = true;
					}) ;
					$("#f_drift_profile_comment_txt").live("blur",function(){  
						is_comment_txt_focus = false;
					}) ;					
				}
			}
		});
		},500);
	}
});


$(".f_user_nick_name_a").live("mouseout", function(){
	is_drift_out = true;
	clearTimeout(driftTimeOutHandle); 
	setTimeout(function(){
	if(is_drift_out){
	var targetId = $(".drift_profile");
	targetId.hide();
	$(".drift_profile").empty();
	$(".drift_profile").append("<div class=\"drift_profile_box\">加载中...</div>");
	}
	},300);
});

$(".drift_profile").live("mouseover", function(){	
	is_drift_out = false;
});


$(".drift_profile").live("mouseout", function(){	
	if(!is_message_txt_focus && !is_comment_txt_focus){
		is_drift_out = true;
	setTimeout(function(){
		if(is_drift_out){
		 var targetId = $(".drift_profile");
		 targetId.hide();
			$(".drift_profile").empty();
			$(".drift_profile").append("<div class=\"drift_profile_box\">加载中...</div>");
		}
		},300);
	}
	});

});


$(document).ready(function(){
	$(".f_drift_message_a").live("click", function(){	
		$("#f_drift_profile_comment_div").hide();
		$("#f_drift_message_div").show();
	});	
	$("#f_drift_message_submit").live("click", function(){	
		var strDriftMessage = $("#f_drift_message_txt").val();
		if(strDriftMessage==""){
			return false;
		}
		var strFriendUid = $(this).attr("uid");
		$("#f_drift_message_div").hide();
		$("#f_drift_message_loading_div").show();
		$.ajax({
	 		type:"POST",
			url:"../json/sendMessage.php",
			async:true,
			data: {
			receiver_uid: strFriendUid,
			message: strDriftMessage
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$("#f_drift_message_txt").val("");
					$("#f_drift_message_loading_div").hide();
				}
			}
		});
		return false;
	});			
});	

$(document).ready(function(){
	$(".f_drift_profile_comment_a").live("click", function(){	
		$("#f_drift_message_div").hide();
		$("#f_drift_profile_comment_div").show();
	});	
	$("#f_drift_profile_comment_submit").live("click", function(){	
		var strDriftMessage = $("#f_drift_profile_comment_txt").val();
		if(strDriftMessage==""){
			return false;
		}
		if(strDriftMessage.length > 250){
			$("#f_drift_message_active_div").empty();
			$("#f_drift_message_active_div").append("<p><font color=\"red\" >最多250个字符</font></p>");
			return false;
		}
		var strFriendUid = $(this).attr("uid");
		$("#f_drift_profile_comment_div").hide();
		$("#f_drift_message_loading_div").show();
		$.ajax({
	 		type:"POST",
			url:"../json/profileCommentAdd.php",
			async:true,
			data: {
			memberId: strFriendUid,
			txtAreaComment: strDriftMessage
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					$("#f_drift_profile_comment_txt").val("");
					$("#f_drift_message_loading_div").hide();
				}
			}
		});
		return false;
	});			
});	
$(document).ready(function(){
	$(".f_drift_add_friend_a").live("click", function(){	
		var strUID = $(this).attr("uid");
		$.ajax({
	 		type:"POST",
			url:"../json/addFriend.php",
			async:true,
			data: {
			friendId: strUID
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					if($.trim(data) == juuyou.common.json.already){
						$(".f_drift_add_friend_a").hide();
						$("#f_drift_message_active_div").empty();
						$("#f_drift_message_active_div").append("<p><font color=\"red\" >已经是好友</font></p>");
					}else{
						$("#f_drift_message_active_div").empty();
						$("#f_drift_message_active_div").append("<p><font color=\"red\" >添加好友成功</font></p>");
					}
				}
			}
		});
		return false;
	});
});

$(document).ready(function(){
	$(".f_drift_add_follow_a").live("click", function(){	
		var strUID = $(this).attr("uid");
		$.ajax({
	 		type:"POST",
			url:"../json/follow/addFollow.php",
			async:true,
			data: {
			uid: strUID
			},
			success:function(data){
				if($.trim(data) == juuyou.common.json.failure){
				}else{
					if($.trim(data) == juuyou.common.json.already){
						$(".f_drift_add_follow_a").hide();
						$("#f_drift_message_active_div").empty();
						$("#f_drift_message_active_div").append("<p><font color=\"red\" >已经跟随</font></p>");
					}else{
						$("#f_drift_message_active_div").empty();
						$("#f_drift_message_active_div").append("<p><font color=\"red\" >跟随成功</font></p>");
					}
				}
			}
		});
		return false;
	});
});




