this.imagePreview = function() {

    xOffset = 40;
    yOffset = 0;

    imgHeight = 0;
    imgWidth = 0;

    leftPos = 0;
    topPos = 0;

    t = "";
    imgalt = "";
    pageOffsetX = "";
    pageOffsetY = "";

    windowWidth = 0;
    windowHeight = 0;
	
	imgLinks = $("#main1 DIV.prod .largeimg");
	previewWindow = $("#preview");
	img = null;
	thisImg = null;

    imgLinks.hover(function(e) {
        t = this.title;
        this.title = "";
		thisImg = $(this).find("input[type='image']");
		if (thisImg.length == 0) thisImg = $(this).find("img");
		if (thisImg.length > 0) {
			var imgsrc = thisImg.attr("src").replace("thumb/", "med/");
		
			img = new Image();
	
			imgalt = thisImg.attr("alt");
			thisImg.attr("alt", "");
			thisImg.attr("title", "");
	
			if (jQuery.browser.msie) {
				pageOffsetX = $(window).scrollLeft();
				pageOffsetY = $(window).scrollTop();
			} else {
				pageOffsetX = window.pageXOffset;
				pageOffsetY = window.pageYOffset;
			}
	
			windowWidth = $(window).width();
			windowHeight = $(window).height();
	
			img.src = imgsrc;
	
			$(img).load(function() {
				if (img != null) {
					imgWidth = img.width + 14;
					imgHeight = img.height + 10;
					yOffset = -(imgHeight / 2);
	
					getPosition(e);
					previewWindow
						.css("top", (topPos + "px"))
						.css("left", (leftPos + "px"))
						.html("<img src=\"" + imgsrc + "\" />")
						.fadeIn(150);
				}
			}).attr('src', imgsrc);
		}
    },
	function() {
        this.title = t;
		if (thisImg != null) thisImg.attr("alt", imgalt);
        previewWindow.hide();
        img = null;
    });
    imgLinks.mousemove(function(e) {
        getPosition(e);
        previewWindow
            .css("top", (topPos + "px"))
            .css("left", (leftPos + "px"));
    });
    function getPosition(e) {
        var thisY = e.pageY;
        var thisX = e.pageX;

        if (imgWidth + xOffset + thisX - pageOffsetX > windowWidth) leftPos = thisX - (xOffset + imgWidth);
        else leftPos = thisX + xOffset;

        if (thisY - yOffset - pageOffsetY > windowHeight) topPos = thisY - imgHeight;
        else if (thisY + yOffset - pageOffsetY < 0) topPos = thisY;
        else topPos = thisY + yOffset;
    }
};

$(document).ready(function() {
	if ($("#main1 DIV.prod .largeimg").length > 0) {
		$('body').append('<div id=\"preview\"></div>');
		$("#preview").hide();
    	imagePreview();
	}
});