this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		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 = "";
		var c = (this.t != "") ? "<br/><span style='width:300px;float:left;'>" + this.t + "</span>" : "";
		$("body").append("<p id='preview'><img style='float:left;' width='300' height='' src='"+ this.name +"' alt='Fara imagine' />"+ c +"</p>");
		$("#preview")
			.fadeIn("fast",function(){
			//if(e.pageY - $(window).scrollTop() + $('#preview').height() <= $(window).height()){
			if($('#preview').height() < $(window).height() - e.pageY + $(window).scrollTop()){
				//posY = $(window).height() + $(window).scrollTop() - $('#tooltip').height() - 15 ;
				$("#preview")
				.css("left",(e.pageX + xOffset) + "px")
				.css("top",(e.pageY - $("#preview").height()/2) + "px");
				//alert("CAZ 1 ePageY "+ e.pageY + " , scrolltop "+$(window).scrollTop()+" , prev height "+$("#preview").height()+" window height "+$(window).height());
			} else {
				$("#preview")
				.css("left",(e.pageX + xOffset) + "px")
				.css("top",(e.pageY - $("#preview").height()) + "px");
				//alert("CAZ 3 ePageY "+ e.pageY + " , scrolltop "+$(window).scrollTop()+" , prev height "+$("#preview").height()+" window height "+$(window).height());
			}
			//yOffset = $("#preview").height();
			});
    },
	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");
	});	*/
};

/*
modif
$("#preview")
.fadeIn("fast",function(){
$("#preview")
.css("left",(e.pageX + xOffset) + "px")
.css("top",(e.pageY - $("#preview").height()) + "px");
yOffset = $("#preview").height();
});

orig
$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
});
 */


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