/*
 * 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
 *
 */

// starting the script on page load
$(document).ready(function(){
	
	xOffset = 10;
	yOffset = -5;
	
	$("a.preview").hover(function (e) {
		
		var imageURL = this.href;
		
		var metadata = $(this).metadata();
		
		if (typeof metadata != 'undefined' && metadata.hasOwnProperty('image')) {
			imageURL = metadata.image;
		}
		
		if (imageURL.length === 0) {
			return;
		}
		
		this.t = this.title;
		this.title = "";
		var c = (this.t !== "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><span></span><img src='"+ imageURL +"' alt='Image Preview' />"+ c +"</p>");								 
		$("#preview").css({
			top: (e.pageY + yOffset) + "px",
			left: (e.pageX + xOffset) + "px"
		})
		.fadeIn(150);					
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });
	
	$("a.preview").mousemove(function (e) {
		$("#preview").css({
			top: (e.pageY + yOffset) + "px",
			left: (e.pageX + xOffset) + "px"
		});
	});
	
});
