/*
 * 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
 *
 */
 
// Allows you to set the X value dynamically.  Use when a thumbnail is low on the page
// which puts part of the preview outside the browser window and therefore invisible.
// Uses the "id" property of the anchor tag for the preview image to set X value 
//xOffset = 0;
//yOffset = 30; 
 
function IsNumeric(val) {

    if (isNaN(parseFloat(val))) {
          return false;
     }

     return true

} 
 
this.imagePreview = function(){	
	/* CONFIG */

	var xOffset = 150;
  var yOffset = 30;

	// Original
	//		xOffset = 150;
	//	yOffset = 30;
				// 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){
		this.t = this.title;
		this.title = "";	
		// Use value of id parameter to set X offset
		this.i = this.id;
		if (IsNumeric(this.i)) {
			if (this.i > 0) {
				xOffset = this.i;
			}
		}
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' style='margin-bottom:15px' />"+ c +"</p>");			
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
