/*
 * 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
 *
 */
 
this.imagePreview = function(tag_bl, tag_link, xOffset, yOffset){	
	/* 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
	//e.pageX e.pageY
	/* END CONFIG */
	$("a."+tag_link).hover(
		function(e){
			this.t = this.title;
			this.title = "";	
			var c = (this.t != "") ? "<br/>" + this.t : "";
			$("body").append("<p id='"+tag_bl+"'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");
			
			var x = 0, y = 0;
			if ($(this).position().left - $("#"+tag_bl).width() + xOffset <= 0) {
				x = Math.abs(xOffset);
			}/* else if () {
				x = ;
			}*/ else {
				x = $(this).position().left - $("#"+tag_bl).width() + xOffset;
			}
			if ($(this).position().top - $("#"+tag_bl).height() - yOffset <= 0) {
				y = Math.abs(yOffset);
			}/* else if () {
				y = ;
			}*/ else {
				y = $(this).position().top - $("#"+tag_bl).height() + yOffset;
			}
			
			$("#"+tag_bl)
				.css("left",/*($(this).position().left - $("#"+tag_bl).width() + xOffset)*/x + "px")
				.css("top",/*($(this).position().top - $("#"+tag_bl).height() + yOffset)*/y + "px")
				.fadeIn("fast");
			delete x, y;
	    },
		function(){
			this.title = this.t;	
			$("#"+tag_bl).remove();
	    }
	);
	/*$("a."+tag_link).mousemove(function(e){
		$("#"+tag_bl)
			.css("left",($(this).position().left - $("#"+tag_bl).width() + xOffset) + "px")
			.css("top",($(this).position().top - $("#"+tag_bl).height() + yOffset) + "px");
	});*/
	$("a."+tag_link).click(function(e){
		e.preventDefault();
	});
};

