(function($){
$.fn.fancyZoom = function(options){

	var options   = options || {};
	
	
	var $th_o;
	
	var $box = $('<img id="box" />').hide();
//	var $closebtn = $('<a id="box_close">Close</a>').appendTo($box).click(function(){});
	$('body').append($box);
	this.each(function(i) {
		$(this).click(function(){
			
			var width       = window.innerWidth  || (window.document.documentElement.clientWidth  || window.document.body.clientWidth);
			var height      = window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight);
			var x           = window.pageXOffset || (window.document.documentElement.scrollLeft   || window.document.body.scrollLeft);
			var y           = window.pageYOffset || (window.document.documentElement.scrollTop    || window.document.body.scrollTop);
			
			x += width/2;
			y += height/2;
			
			$th_o = $('img',this);
			var imgPreload = new Image();
			$box.stop().attr('src',this.href).css({
				opacity		: "0",
				top			: $th_o.offset().top + 'px',
				left		: $th_o.offset().left + 'px',
				width		: $th_o.width() + 'px',
				height		: $th_o.height() + 'px'
			});
			imgPreload.onload=function(){
				    $box.animate({
						top     : y-imgPreload.height/2 + 'px',
						left    : x-imgPreload.width/2-8 + 'px',
						opacity : "1",
						width   : imgPreload.width,
						height  : imgPreload.height
					}, 1000, null, function() {
					});
			};
			imgPreload.src = this.href;
			$(document).bind('click.zoom scroll.zoom keypress.zoom',function(){
				$(document).unbind('.zoom');
				$box.animate({
					opacity	: "0",
					top			: $th_o.offset().top + 'px',
					left		: $th_o.offset().left + 'px',
					width		: $th_o.width() + 'px',
					height		: $th_o.height() + 'px'
				}, 500,function(){
					$(this).hide();
				});
				return false;
			});
			return false;
		});
	});

	return this;
}
})(jQuery);
