
var g_currentImage;
var g_mouseX;
var g_mouseY;

function showLargeImage(key)
{
	var name 				= 'largeimage_' + key;
	var elt 				= document.getElementById(name);
//	elt.style.top 	= (g_mouseY + 5) + 'px';
//	elt.style.left 	= (g_mouseX + 5) + 'px';		
	g_currentImage 	= elt;
	elt.style.visibility = 'visible';
}
function hideLargeImage(key)
{
	var name = 'largeimage_' + key;
	var elt = document.getElementById(name);
	elt.style.visibility = 'hidden';

}
function popupLargeImage(key)
{
	var name = 'largeimage_' + key;
	var elt = document.getElementById(name);

//	alert(name + ' ' + elt);

	var images = elt.getElementsByTagName('img');
		
  var innerWidth 	= 0;
  var innerHeight = 0;
  
  if( typeof( window.innerWidth ) == 'number' ) 
  {
		//Non-IE
	  innerWidth 	= window.innerWidth;
	  innerHeight 	= window.innerHeight;
	} 
	else 
	{
		if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{
			//IE 6+ in 'standards compliant mode'
		 	innerWidth 	= document.documentElement.clientWidth;
		  innerHeight = document.documentElement.clientHeight;
		} 
		else 
		{
			if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{
		  	//IE 4 compatible
		 		innerWidth 	= document.body.clientWidth;
		   	innerHeight = document.body.clientHeight;
		 	}
		}
	}


	var scrollTop 	= 0;
	var scrollLeft 	= 0;
 	if(document.documentElement)
 	{
		scrollTop 	= document.documentElement.scrollTop;
		scrollLeft 	= document.documentElement.scrollLeft;
	}
	else
	{
		scrollTop 	= document.body.scrollTop;
		scrollLeft 	= document.body.scrollLeft;
	}



	var left 	= ((innerWidth - images[0].width) / 2) 		+ scrollLeft;
	var top 	= ((innerHeight - images[0].height) / 2) 	+ scrollTop;

//	alert(innerWidth + ' ' + innerHeight);
//	alert(images[0].src + ' ' + images[0].width + ' ' + images[0].height);
	
	elt.style.top 	= top + 'px';
	elt.style.left 	= left + 'px';	
	elt.style.visibility = 'visible';	
}
function setPopupImageLocation(evt)
{
  if (evt) {
    g_mouseX = evt.pageX;
    g_mouseY = evt.pageY;
  }
  else
  {
  	if(document.documentElement)
  	{
			var scrollTop 	= document.documentElement.scrollTop;
			var scrollLeft 	= document.documentElement.scrollLeft;
		}
		else
		{
			var scrollTop 	= document.body.scrollTop;
			var scrollLeft 	= document.body.scrollLeft;
		}
  	
    g_mouseX = event.clientX + scrollLeft;
    g_mouseY = event.clientY + scrollTop;   

  }

	if(g_currentImage)
	{
		var images = g_currentImage.getElementsByTagName('img');

	  var innerWidth 	= 0;
	  var innerHeight = 0;
	  
	  if( typeof( window.innerWidth ) == 'number' ) 
	  {
			//Non-IE
		  innerWidth 	= window.innerWidth;
		  innerHeight 	= window.innerHeight;
		} 
		else 
		{
			if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
			{
				//IE 6+ in 'standards compliant mode'
			 	innerWidth 	= document.documentElement.clientWidth;
			  innerHeight = document.documentElement.clientHeight;
			} 
			else 
			{
				if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
				{
			  	//IE 4 compatible
			 		innerWidth 	= document.body.clientWidth;
			   	innerHeight = document.body.clientHeight;
			 	}
			}
		}
		
		if(g_mouseX > (innerWidth - g_mouseX))
		{
			var left = g_mouseX - images[0].width - 25;
		}		
		else
		{
			var left = g_mouseX + 5;
		}
		
		if(g_mouseY > (innerHeight - g_mouseY))
		{
			var top = g_mouseY - images[0].height - 25;
		}		
		else
		{
			var top = g_mouseY + 5;
		}
		
		
		g_currentImage.style.top	= top + 'px';
		g_currentImage.style.left = left + 'px';
	}
}
var g_oldCursor;
function setCloseCursor()
{
	g_oldCursor = document.body.style.cursor;
	document.body.style.cursor = 'default';
}
function resetCloseCursor()
{
	document.body.style.cursor = g_oldCursor;
}
function printLargeImage(key)
{
	var name = 'largeimage_' + key;
	var elt = document.getElementById(name);
	var img = elt.getElementsByTagName('img');
//	alert(img[0].src + ' ' + img[0].width + ' ' + img[0].height);
	var height = img[0].height + 64;
	
	window.open('helpers/print_image.php?k=' + key,'imageprinter','width=' + img[0].width + ',height=' + height);
	
	
}












document.onmousemove = setPopupImageLocation;
