var int;	
var intTrigger;
var isHide = false;	

var temInfo;
var temId;

var onlyId= "only_rand_id_";

var i = 0;

var ret_result;

var newBid;
var newNickname;
//停留时间
var STOP_TIME = 600;

var mxPosition;


//解决setTimout 带参数的问题

var Obj = function(){
		this.sthis = arguments[0];
		this.bid = arguments[1];
		this.type = arguments[2];
		
		this.actioveTips = function()
		{
			actioveTipss(this.sthis,this.bid,this.type);
		}

		var _self = this;
		this.waitAndStart = function(){
			intTrigger = setTimeout(function(){_self.actioveTips()}, 400);
		}
	}
	
function actioveTip()
{
	mxPosition = parseInt(arguments[0].clientX);
	var tipObj = new Obj(arguments[1],arguments[2],arguments[3]);
	tipObj.waitAndStart();	
}


function actioveTipss()
{								
	sthis = arguments[0];
	bid = arguments[1];
	type = arguments[2];
	
	
	//取得鼠标的位置，在屏幕的右边调用相对的样式，左边调用相对的样式
	var className;
	nx =mxPosition/parseInt(document.body.clientWidth);
	
	//如果飘窗，即将要消失了 如果换一个ID了。则要重新请求
	//这里要显示飘窗,如果有隐藏信息，则要清除
	if (sthis.id == "")
	{
		i = i+1;
		$(sthis).attr("id",onlyId+i);
	}
	
	if( sthis.id == temId)
	{		
		if (isHide == true)
		{	
			clearTimeout(int);
			isHide = false; 
			return false;
		}
		
		//这个还是有问题，不能很好解决，即将消失时再回到原始点，层是处于隐藏状态。
		var opacityStatus = $("#infoBox").css("opacity");
		if ( opacityStatus < 1)	//如果是半透明状态，返回正常值
		{
			$("#infoBox").css("opacity","1");
			$("#infoBox").show();
		}			
	}
	else 
	{
		if(isHide == true)
		{
			clearTimeout(int);
			isHide = false; 
		}
	}	
	
	//为了兼容多个弹出，每弹出一个新的，都清理以前的隐藏窗口
	$("#contenttips").remove();											  										  
	$(sthis).before("<div id='contenttips'></div>");
								
	$("#contenttips").load("http://www.aipai.com/app/www/templates/common/html/tips.html",'',function(){
		
		var number = Math.random(100);	
		$("#info_html").attr("src","http://www.aipai.com/app/www/templates/common/html/inf.html?"+number);
		
		//开始AJAX处理
		var infoDomain="http://www.aipai.com";			//基础域名
		//var bid=146388;
		var result = "bid="+bid+"&callback=loadUserInfo&action=getTips&rand="+number;
		
		$.ajax({
			type: 'GET',
			url: infoDomain+'/apps/getTips.php',
			dataType: 'jsonp',
			data: result
			
		});
		//结束AJAX处理		
		
		temInfo = $(sthis).html();
		
		className = "infoBox";
		
		if ( temInfo.indexOf("big.jpg")!=-1 || temInfo.indexOf("userdefault60.gif")!=-1)			//大图的显示位置
		{			
			$("#infoBox").removeClass();

			if(nx > 0.5)	//靠右的图片显示方法
			{
				$("#infoBox").css("margin","60px 0 0 -280px");
			}
			else
			{

				if(type == 'card')	//不同的类别，用不同的样式
				{
					$("#infoBox").css("margin","42px 0 0 -7px");
				}
				else
				{
					$("#infoBox").css("margin","60px 0 0 -7px");
				}
				
			}			
			
			$("#infoBox").addClass(className);
		}
		else if(temInfo.indexOf("middle.jpg")!=-1 || temInfo.indexOf("userdefault30.gif")!=-1 )		//中图的显示位置
		{
			$("#infoBox").removeClass();
			$("#infoBox").css("margin-top","29px");
			$("#infoBox").addClass(className);			
		}
		else		//文字的显示位置
		{
			$("#infoBox").removeClass();
			$("#infoBox").css("margin-top","15px");
			$("#infoBox").addClass(className);						
		}			
	});
	
	temId = sthis.id;
}

function onloadTips(sthis)
{
	//这里要显示飘窗,如果有隐藏信息，则要清除
	if (isHide == true)
	{
		clearTimeout(int);
		isHide = false; 
	}

	$("#contenttips").show();
}

function outTips(sthis)
{
	clearTimeout(intTrigger);
	if (isHide == false)	//1秒没有回到飘窗框，就自动消失
	{
		int = setTimeout("hideTipss()",STOP_TIME);
		isHide = true;
	}
	
	$("#infoBox").hover (
    	function () {onloadTips(sthis)},function () {hideTips()}
     );

}

function hideTips()
{
	if (isHide == false)	//显示状态操作
	{
		int = setTimeout("hideTipss()",STOP_TIME);
		isHide = true;
	}						
}

function hideTipss()
{	
	$("#infoBox").fadeTo("fast",0.25,function(){
		  $("#infoBox").hide();
	});	//退出动画

	isHide = false;	// 设置为可见状态
}

function loadUserInfo(ret)
{	
	ret_result = ret;	//将值传到另一个页面
	
	$("#userTitle").attr("href",ret["info"]["url"]);
	$("#userTitle").html(ret["info"]["nickname"]);
	
	$("#userBid").html("(宝宝号："+ret["info"]["bid"]+")")
	
	newBid = ret["info"]["bid"];
	newNickname = ret["info"]["nickname"];
	
	//显示隐藏
	$("#titl").show();
	$("#titr").show();
}	


//短信函数
function sendMessageTips()
{
	checkLogin('sms',sendSms,newBid);
}

function addFriendTip()
{
	$(this).myDialog({type:'page', title:'加'+newNickname+'为好友',width:'426',height:'260',url:'/apps/friend.php?action=add&bid='+newBid});
}

function showTrigger()
{
	$("#contenttips").show();
}

//发送消息
function sendSms(bid)
{
	var url = 'http://www.aipai.com/sms.php?action=send&toid='+bid;
	window.open (url, "发短信");
}


