this.imagePreview = function(){

	// these 2 variable determine popup's distance from the cursor
	// you might want to adjust to get the right result		
	xOffset = 10;
	yOffset = 30;
	
	//load all images in the indexpage
	$("a[rel]").each(function() {
		var rel = $(this).attr("rel");
		var prevImage = new Image() ;
		prevImage.src = rel; 
	});

		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		
		var prevImage = new Image();
		prevImage.src = this.rel;
		
		//320 is width of the preview image
		var myHeight = prevImage.height * 320 / prevImage.width;
		imgHeight = Math.round(myHeight);
		
		$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset - imgHeight) + "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 - imgHeight) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	imagePreview();
});
