(function($)
{
	// Private

	var opts = {};

	function imagepreview_click()
	{
		return false;
	};

	function imagepreview_mouseover(e)
	{
		$("body").append('<div id="preview"><img src="'+ $(this).attr('href') +'" alt="Image preview"/></div>');				var newSize = get_new_size(e);		
		$("#preview")
			.css(opts.xOffsetLocation, newSize[0] + "px")			.css(opts.yOffsetLocation, newSize[1] + "px")
			.fadeIn("fast");
	};
	
	function imagepreview_mouseout()
	{
		$("#preview").remove();
	};
	
	function imagepreview_mousemove(e)
	{		var newSize = get_new_size(e);	
		$("#preview")
			.css(opts.xOffsetLocation, newSize[0] + "px")			.css(opts.yOffsetLocation, newSize[1] + "px");
	};		function get_new_size(e)	{		if (opts.xOffsetLocation == 'left') {			var newX = e.pageX + opts.xOffset;		}		else {			var newX = $(window).width() - e.pageX - opts.xOffset;		}				if (opts.yOffsetLocation == 'top') {			var newY = e.pageY + opts.yOffset;		}		else {			var newY = $(window).height() - e.pageY - opts.yOffset;		}				return [newX, newY];	}
	
	// Public

	$.fn.imagepreview = function(options)
	{
		opts = $.extend({}, $.fn.imagepreview.defaults, options);
		
		$(this).unbind('click', imagepreview_click);
		$(this).bind('click', imagepreview_click);
		
		$(this).unbind('mouseover', imagepreview_mouseover);
		$(this).bind('mouseover', imagepreview_mouseover);
		
		$(this).unbind('mouseout', imagepreview_mouseout);
		$(this).bind('mouseout', imagepreview_mouseout);
		
		$(this).unbind('mousemove', imagepreview_mousemove);
		$(this).bind('mousemove', imagepreview_mousemove);
		
		return this;
	};
	
	$.fn.imagepreview.defaults =
	{
		xOffset: 30,
		yOffset: -100,		xOffsetLocation: 'left',		yOffsetLocation: 'top'
	};

})(jQuery);