var IE = document.all?true:false;
var iwidth = 0;
var iheight = 0;

function get_preview_obj(){
	if (document.getElementById)
		return document.getElementById("preview_asiaphotopro");
}

function get_preview_style(){
	if (document.getElementById)
		return document.getElementById("preview_asiaphotopro").style;
}


function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hide_preview() {
	var sty = get_preview_style();
	sty.display = "none";
	sty.left = "-500px";
	document.onmousemove = '';
}

function show_preview(url, evt, title, description, imgwidth, imgheight)
{
	document.onmousemove=followmousemove;
	var newHTML;
	iwidth = imgwidth;
	iheight = imgheight;
	
    newHTML='<div style="padding:10px; background-color:#222; border:1px solid #000; width:'+imgwidth+';">';
    newHTML=newHTML+'<span class="yellow_bold">'+title+'</span><br/>';
    newHTML=newHTML+'<span class="white_small">'+description.replace(/\[[^\]]*\]/g,'')+'</span><br/><br/>';
	newHTML=newHTML+'<div align="center">';
	newHTML=newHTML+'<img src="'+url+'"';
	if(imgwidth>0&&imgheight>0){
		newHTML=newHTML+' height="'+imgheight+'" width="'+imgwidth+'"';
	}
	newHTML=newHTML+' border="0" /></div>';


    newHTML=newHTML+'</div>';


	get_preview_obj().innerHTML=newHTML;
    get_preview_style().display="inline";
	
	followmousemove(evt);
}

function followmousemove(evt){
	var e = (window.event) ? window.event : evt;
	var tempX;
	var tempY;
	var clientx = 0;
	var clienty = 0;
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
		clientx = event.clientX;
		clienty = event.clientY;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX
		tempY = e.pageY
		clientx = e.clientX;
		clienty = e.clientY;
	}  

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
		
	if(clientx < (docwidth / 2))
	{
		tempX = tempX + 15;
	}
	else
	{
		tempX = tempX - iwidth - 60;
	}

	var offsetfrommouse = 50;
    if (docheight - clienty < (iheight + 2*offsetfrommouse)){
      tempY = clienty + truebody().scrollTop - Math.max(0,(2*offsetfrommouse + iheight + clienty - docheight));
    } else {
      tempY = truebody().scrollTop + clienty;
    }

	get_preview_style().left=(tempX)+"px";
	get_preview_style().top=(tempY)+"px";
}

function temp()
{
	if(clienty < (docheight / 3))
	{
		tempY = tempY - 20;
	}
	else if(clienty < (docheight * 2 / 3))
	{
		tempY = tempY - (iheight / 2) - 40;
	}
	else
	{
		tempY = tempY - iheight - 20;	
	}
	
}