	xOffset = 50;
	yOffset = 100;
	displayRequired = true;

	function positionPopup(e)
	{

		var windowWidth;
		var windowHeight;
		var leftPos;
		var rightPos;
		var topPos;
		var bottomPos;
		var offset;
		var scrollTop;
		var screenY;

		windowWidth = jQuery(window).width();
		windowHeight = jQuery(window).height();

		scrollTop = jQuery(window).scrollTop();
		screenY = e.pageY - scrollTop;
		leftPos = 'auto';
		rightPos = 'auto';
		topPos = 'auto';
		bottomPos = 'auto';
		if (e.pageX > (windowWidth/2))
		{
			rightPos = ((windowWidth - e.pageX) + xOffset ) + "px";
		}
		else
		{
			leftPos = (e.pageX + xOffset) + "px";
		}

		if (screenY > (windowHeight/2))
		{
			if (screenY > windowHeight - yOffset)
			{
				bottomPos = ((windowHeight - e.pageY) ) + "px";
			} 
			else
			{
				bottomPos = ((windowHeight - e.pageY) - yOffset ) + "px";
			}
		}
		else
		{

			if (screenY < yOffset)
			{
				topPos = (e.pageY) + "px";
			}
			else
			{
				topPos = (e.pageY - yOffset) + "px";
			}
		}

		jQuery("#paintingpopup")
			.css("bottom", bottomPos)
			.css("top", topPos)
			.css("right", rightPos)
			.css("left", leftPos);
	}


	function setupPopups()
	{

		jQuery('.paintthumb').live('mouseover', function()  
		{  
			if (!jQuery(this).data('init'))  
			{  
				jQuery(this).data('init', true);  
				jQuery(this).hoverIntent(function(e) {  
					paintingHoverEnter(jQuery(this), e)
				}, function() {
					paintingHoverExit();
				});
				jQuery(this).trigger('mouseover');  
			}  
		});  

/*	
		jQuery(".paintthumb").hoverIntent(function(e) {
				paintingHoverEnter(jQuery(this), e)
			}, function() {
				paintingHoverExit();
			});
*/
		//jQuery(".paintthumb").mousemove(function(e){
		//	positionPopup(e);
			//jQuery("#paintingpopup").css("top",(e.pageY - yOffset) + "px").css("left",(e.pageX + xOffset) + "px");
		//});
	}


	function paintingHoverEnter(thumb, e){

		var detailImg;
		var infoTableStr;
		displayRequired = true;
		jQuery("#paintingpopup").load("paintingpopup.php?catalogue="
			+ thumb.attr("id"), function(){displayPopup(e)});
	}


	function displayPopup(e) {
		if (displayRequired == true)
		{
			positionPopup(e);
			jQuery("#paintingpopup").fadeIn("slow");
		}
	}

	function paintingHoverExit(){
		displayRequired = false;
		jQuery("#paintingpopup").hide();
		jQuery("#paintingpopup").empty();
	}


