// JavaScript Document

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = -10;
		yOffset = 0;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		var dir=$('body').css('direction');
		var xPos;
		var imageWidth=400;
		
	/* END CONFIG */
	$("a.preview img").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		
	$("body").append("<p id='preview'><img id='pre-img' src='"+ this.src +"' alt='Image preview'/>"+ c +"</p>");
	
		xPos=((dir=='rtl')?(e.pageX-imageWidth-yOffset):(e.pageX + xOffset));
		
		//subtract image width in arabic version to appear on the left side of the cursor
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(xPos) + "px")
			.fadeIn('slow');						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
			
		xPos=((dir=='rtl')?(e.pageX-imageWidth-yOffset):(e.pageX + yOffset));
		//subtract image width in arabic version to appear on the left side of the cursor
		
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(xPos) + "px");
			
	});			
};


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