/*
 * Url 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
 *
 * Modify by L.Ken (http://fall-leaf.net)
 *
 * for txtcube zenphoto plugin
 */
 
this.ZenPhotoPreview = function(){	
	/* CONFIG */
		
		xOffset = 20;
		yOffset = 20;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.photoBox_preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='photoBox_preview'><img src='"+ this.rel +"' alt='Images preview' />"+ c +"</p>");
		var left = e.pageX + xOffset;
		var top = e.pageY + yOffset;

		if (e.pageX>$(window).width()-$("#photoBox_preview").width() - xOffset) {
			left = e.pageX - $("#photoBox_preview").width() - xOffset;
		}
		if (e.pageY>$(window).height()-$("#photoBox_preview").height() - yOffset) {
			top = e.pageY - $("#photoBox_preview").height() - yOffset;
		}

		$("#photoBox_preview")
			.css("top",(top) + "px")
			.css("left",(left) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;	
		$("#photoBox_preview").remove();
    });	
	$("a.photoBox_preview").mousemove(function(e){
		var left = e.pageX + xOffset;
		var top = e.pageY + yOffset;

		if (e.pageX>$(window).width()-$("#photoBox_preview").width() - xOffset) {
			left = e.pageX - $("#photoBox_preview").width() - xOffset;
		}
		if (e.pageY>$(window).height()-$("#photoBox_preview").height() - yOffset) {
			top = e.pageY - $("#photoBox_preview").height() - yOffset;
		}

		$("#photoBox_preview")
			.css("top",(top) + "px")
			.css("left",(left) + "px");
	});
};


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