(function($){
	$.fn.zoomi = function() {
		$(this).filter("img").each(
			function(){
				if(!this.z) {
					$(this).zoom1().mouseover(
						function(){
							$('.big').hide();
							$(this).zoom2().show();
							$('#signed').html($(this).attr('title'));
						}
					);
				
					$(this.z).mouseout(
						function(){
							$(this).hide();
							$('#signed').html('');
						}
					);
				}
			return $(this);
			}
		);
	};

	$.fn.zoom1 = function() {
		$(this).each(
			function(){
				var e = this;
				if($(e).parent('a').length > 0){
					$(e).parent('a').after('<a href="#" class="big"><img class="zoom2"/></a>');
					e.z = e.parentNode.nextSibling;
					$(e.z).attr('href',$(e.parentNode).attr('href'));
					$(e.z.firstChild).attr("src",e.alt || e.src);
				}else{
					$(e).after('<a href="#" class="big none"><img class="zoom2"/></a>');
					e.z = e.nextSibling;
					$(e.z).click(function(){return false;});
					$(e.z.firstChild).attr("src",e.alt || e.src);
				}				
				$(e.z).hide();
			}	
		);
		return this;
	};

$.fn.zoom2 = function() {
	var s = [];
	this.each(
		function(){
			var e = this;
			if(!e.z) {e = $(e).zoom1()[0];}
			s.push(e.z);
			if(!e.z.firstChild.complete) {return;}
			if(!e.z.width) { 
				$(e.z).show(); 
				e.z.width=e.z.width; 
				$(e.z).hide(); 
			}
			if($(e).parent('a').length > 0){
				$(e.z).css({left:$(e).parent('a').position().left-17+'px',top:$(e).parent('a').position().top+'px'});
			}else{
				$(e.z).css({left:$(e).position().left-17+'px',top:$(e).position().top+'px'});
			}
			
		}	
	);
	return this.pushStack(s);
};
})(jQuery);
$(window).load(function(){ $('img.zoomi').zoomi(); });