(function($) {
	/*
		Image preview script 
		powered by jQuery (http://www.jquery.com)
		
		written by Alen Grakalic (http://cssglobe.com)
		modified by Damien du Toit (http://coda.co.za)

		for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
	*/

	$.fn.imagePreview = function(options) {

		$.fn.imagePreview.defaults = {
			xOffset: 30,
			yOffset: 10,
			relocate: true
		};

		var o = $.extend({}, $.fn.imagePreview.defaults, options);

		$("a.preview").hover(function(e) {
			this.t = this.title;
			this.title = "";	
			var c = (this.t != "") ? "<br />" + this.t : "";
			$("body").append("<p id='preview'><img src='" + this.href + "' alt='Image preview' />" + c + "</p>");								 
			$("#preview")
				.css("top", (e.pageY - o.yOffset) + "px")
				.css("left", (e.pageX + o.xOffset) + "px")
				.fadeIn("normal");						
		},	
		function() {
			this.title = this.t;	
			$("#preview").remove();
		});
	
		if (o.relocate) {
			$("a.preview").mousemove(function(e) {
				$("#preview")
					.css("top", (e.pageY - o.yOffset) + "px")
					.css("left", (e.pageX + o.xOffset) + "px")
			});
		}

		$("a.preview").click(function() {
			return false;
		});
	};
})(jQuery);
