/********************************************************************************************

		ToolTip.js
		Copyright by FLYSO Blog, All rights reserved.

********************************************************************************************/


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/********************************************************************************************

	Dynamic Drive DHTML code library (www.dynamicdrive.com)

********************************************************************************************/

var offsetxpoint	=	-20;	// 
var offsetypoint	=	20;		// 
var ie	=	document.all;
var ns6	=	document.getElementById && !document.all;
var safari	=	isSafari();
var enabletip	=	false;

function showTip(messageContent)
{
	// 
  var desc = messageContent.split(';');

	messageContent = "";
	if (desc[3])
	{
		var imageAttr = "";
		if (parseInt(desc[4],10) >= parseInt(desc[5],10))
		{
			imageAttr = "width='100'";
		}
		else
		{
			imageAttr = "height='100'";
		}

		// messageContent = messageContent + desc[4] + "/" + desc[5] + imageAttr;
		messageContent = messageContent + "<img src='http://www.flyso.net/"+ desc[3] + "' " + imageAttr + " align='right' style='padding:3px; margin: 3px; border: 3px solid #cccccc;'>";
	}

	if (desc.length > 2)
	{
		messageContent = messageContent + "<strong>标题</strong> : " + desc[0] + "<br>";
	}
	else
	{
		messageContent = desc[0];
	}

	if (desc[6]) { messageContent = messageContent + "<strong>发布时间</strong> : " + desc[6] + "<br>"; }
	if (desc[1]) { messageContent = messageContent + "<strong>内容</strong> : " + desc[1] + "<br>"; }
	if (desc[2]) { messageContent = messageContent + "<strong>浏览次数</strong> : " + desc[2] + " 次<br>"; }
	if (desc[3]) { messageContent = messageContent + "<strong>图片大小</strong> : 宽度:" + desc[4] + "px, 高度:" + desc[5] + "px<br>"; }


  //ddrivetip(messageContent);

	var tipObject = MM_findObj('toolTipWindow');
	tipObject.innerHTML = messageContent;
	enabletip = true;
	return false;
}

function hideTip()
{
	// 
	var tipObject = MM_findObj('toolTipWindow');	
	enabletip = false;
	tipObject.style.visibility = "hidden";
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
function isSafari(){
	return navigator.userAgent.toLowerCase().indexOf("safari") + 1;
}

function positionTip(e)
{
	if (enabletip)
	{
		var tipobj = MM_findObj('toolTipWindow');
		
		var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
		var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
		//Find out how close the mouse is to the corner of the window
		var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
		var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;
		
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000
		
		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<tipobj.offsetWidth)
		{
			//move the horizontal position of the menu to the left by it's width
			tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
		}
		else if (curX<leftedge)
		{
			tipobj.style.left="5px"
		}
		else
		{
			//position the horizontal position of the menu where the mouse is positioned
			tipobj.style.left=curX+offsetxpoint+"px";
		}

		if(safari)
		{
			tipobj.style.top=curY+offsetypoint+"px";
		}
		else
		{
			//same concept with the vertical position
			if (bottomedge<tipobj.offsetHeight)
			{
				tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
			}
			else
			{
				tipobj.style.top=curY+offsetypoint+"px";
			}
		}
		tipobj.style.visibility="visible";
	}
}

document.onmousemove = positionTip;