/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 var photolink;
 this.imagePreview = function() {
     /* CONFIG */




     // these 2 variable determine popup's distance from the cursor
     // you might want to adjust to get the right result

     /* END CONFIG */
     $("a.preview").hover(function(e) {
         yOffset = parseInt(this.attributes["dim"].value.substr(0, this.attributes["dim"].value.indexOf(";")));
         xOffset = parseInt(this.attributes["dim"].value.substr(this.attributes["dim"].value.indexOf(";") + 1));

         //alert(yOffset);
         //alert(xOffset);

         this.t = this.title;
         this.title = "";
         var c = (this.t != "") ? "<br/>" + this.t : "";
         $("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");
         var top = 0;
         var left = 0;
         if (document.all) {
             var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
             top = e.pageY;
             left = e.pageX;
             if ((e.clientY + yOffset) > (iebody.clientHeight)) {
                 top = e.pageY - (yOffset - (iebody.clientHeight - e.clientY));
             }
             if ((e.clientX + xOffset + 40) > (iebody.clientWidth)) {
                 left = e.pageX - xOffset - 40;
             }
         }
         else {
             top = e.pageY;
             left = e.pageX;
             if ((e.clientY + yOffset) > (window.innerHeight)) {
                 top = e.pageY - (yOffset - (window.innerHeight - e.clientY));
             }
             if ((e.clientX + xOffset + 40) > (window.innerWidth)) {
                 left = e.pageX - xOffset - 40;
             }
         }
         $("#preview")
			.css("top", (top) + "px")
			.css("left", (left + 20) + "px")

			.fadeIn("fast");
     },
	function() {
	    this.title = this.t;
	    $("#preview").remove();
	});
     $("a.preview").mousemove(function(e) {
         yOffset = parseInt(this.attributes["dim"].value.substr(0, this.attributes["dim"].value.indexOf(";")));
         xOffset = parseInt(this.attributes["dim"].value.substr(this.attributes["dim"].value.indexOf(";") + 1));
         var top = 0;
         var left = 0;
         if (document.all) {
             var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
             top = e.pageY;
             left = e.pageX;
             if ((e.clientY + yOffset) > (iebody.clientHeight)) {
                 top = e.pageY - (yOffset - (iebody.clientHeight - e.clientY));
             }
             if ((e.clientX + xOffset + 40) > (iebody.clientWidth)) {
                 left = e.pageX - xOffset - 40;
             }
         }
         else {
             top = e.pageY;
             left = e.pageX;
             if ((e.clientY + yOffset) > (window.innerHeight)) {
                 top = e.pageY - (yOffset - (window.innerHeight - e.clientY));
             }
             if ((e.clientX + xOffset + 40) > (window.innerWidth)) {
                 left = e.pageX - xOffset - 40;
             }
         }
         $("#preview")
			.css("top", (top) + "px")
			.css("left", (left + 20) + "px");
     });
 };


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
