if (document.layers)
document.captureEvents(Event.mouseover | Event.mouseout | Event.mousedown | Event.mouseup | Event.mousemove)

var ua = navigator.userAgent.toLowerCase();
var divw=0;
var divh=0;

if (document.getElementById || document.all)
	document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden;z-index:100;"></div>')

function gettrailobject()
{
	if (document.getElementById)
		return document.getElementById("imgtrailer")
	else if (document.all)
		return document.all.trailimagid
}

function gettrailobj()
{
	if (document.getElementById)
		return document.getElementById("imgtrailer").style
	else if (document.all)
		return document.all.trailimagid.style
}

function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail()
{
	if(document.MainForm.slider_auto.value=="0") {
		document.onmousemove='';
		gettrailobj().visibility="hidden";
	}
}

function showtrail(imagename, imagenum, license, caption, imageid, loginchk, ecaption)
{
	if(document.MainForm.disp_preview.value=="1" && loginchk=="1") 
	{
		//setTimeout("showImage('"+imagename+"','"+imagenum+"','"+license+"','"+caption+"','"+imageid+"')",1000)
		showImage(imagename, imagenum, license, caption, imageid, ecaption)
	}
}

function showImage(imagename, imagenum, license, caption, imageid, ecaption)
{
		var img = new Image
		img.src=imagename;
		// 読み込みが完了していない場合、waitさせる
		if(img.complete==false)
		{
			var start = new Date;
			while (1)
			{
				var cur = new Date;
				if (400 <= cur.getTime() - start.getTime())
				{
					break;
				}
			}
		}
		thw=img.width;
		thh=img.height;
		if (thw=="" || thw==0)
		{
			thw=img.width;
			if (thw=="" || thw==0)
			{
				thw=500;
			}
		}
		if (thh=="" || thh==0)
		{
			thh=img.height;
			if (thh=="" || thh==0)
			{
				thh=500;
			}
		}
		if (parseInt(img.width) < 500)
		{
			thw=500;
		}
		newHTML = '<table cellpadding=5 style="background-color: #FFFFFF; border: 1px solid #888;">';		
		newHTML = newHTML + '<tr><td align="center" style="padding: 8px 2px 2px 2px;"><img src="' + imagename + '" border="0"></td></tr>';
		newHTML = newHTML + '<tr><td class="blah">' + imagenum + ' ' + license + '</td></tr>';
		if (caption !="")
		{
			newHTML = newHTML + '<tr><td class="blah"><div style="width:' + thw + '">' + unescape(caption) + '</div></td></tr>';
		}
		if (ecaption !="")
		{
			newHTML = newHTML + '<tr><td class="blah"><div style="width:' + thw + '">' + unescape(ecaption) + '</div></td></tr>';
		}
		newHTML = newHTML + '</table>';

		//if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1)
		//{
			gettrailobj().left="-500px";
			divthw = parseInt(thw) + 2;
			gettrailobject().innerHTML = newHTML
			gettrailobj().visibility="visible";
			divw = parseInt(thw)+25;
			divh = parseInt(thh)+185;
			document.onmousemove=followmouse;
		//}
}


function followmouse(e)
{
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	if(typeof e != "undefined")
	{
		if(docwidth < 15+e.pageX+divw)
			xcoord = e.pageX-divw-5;
		else
			xcoord = 15+e.pageX;
		if(docheight < 15+e.pageY+divh)
			ycoord = 15+e.pageY-Math.max(0,(divh + e.pageY - docheight - truebody().scrollTop - 30));
		else
			ycoord = 15+e.pageY;
	}
	else if (typeof window.event != "undefined")
	{
		if(docwidth < 15+truebody().scrollLeft+event.clientX+divw)
			xcoord = truebody().scrollLeft-5+event.clientX-divw;
		else
			xcoord = truebody().scrollLeft+15+event.clientX;

		if(docheight < 15+truebody().scrollTop+event.clientY+divh)
			ycoord = 15+truebody().scrollTop+event.clientY-Math.max(0,(divh + event.clientY - docheight - 30));
		else
			ycoord = truebody().scrollTop+15+event.clientY;
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

