(
	function($j){
		
		$j.fn.jqueryzoom=function(options){
			
			var settings= {
				xzoom:200,
				yzoom:200,
				offset:10,
				position:"right",
				lens:1,
				preload:1
			};
			
			if(options){$j.extend(settings,options)}var noalt='';
			$j(this).hover(function(){var imageLeft=$j(this).offset().left;

			var imageTop=$j(this).offset().top;
			var imageWidth=$j(this).children('img').get(0).offsetWidth;
			var imageHeight=$j(this).children('img').get(0).offsetHeight;
			
			noalt=$j(this).children("img").attr("alt");
			var bigimage=$j(this).children("img").attr("jqimg");
			
			$j(this).children("img").attr("alt",'');
			
			if($j("div.zoomdiv").get().length==0){
				$j(this).after("<div class='zoomdiv'><img class='bigimg' src='"+bigimage+"'/></div>");				
				$j(this).append("<div class='jqZoomPup'>&nbsp;</div>")
			}
			
			if(settings.position=="right"){
				if(imageLeft+imageWidth+settings.offset+settings.xzoom>screen.width)	{
					leftpos=imageLeft-settings.offset-settings.xzoom
				}
				else {
					{leftpos=imageLeft+imageWidth+settings.offset}
				}
			}
			else{					
				leftpos=imageLeft-settings.xzoom-settings.offset;				
				if(leftpos<0){
					leftpos=imageLeft+imageWidth+settings.offset
				}
			}
			
			//ridefinsico leftpos, che indica dove si posiziona partendo dalla sx dello schermo portandolo dove volgio io ...
			leftpos = 620;		
			$j("div.zoomdiv").css({top:imageTop,left:leftpos});
			
			//creao la variabile dimensioneDiv con fizzata la dimensione del div 
			//$j("div.zoomdiv").width(settings.xzoom);
			
			var dimensioneDiv = '362px';			
			$j("div.zoomdiv").width(dimensioneDiv);
			
			//creao la variabile altezzadiv con fizzata l'altezza del div 			
			
			var altezzadiv = '300px';			
			$j("div.zoomdiv").height(altezzadiv);
			
			$j("div.zoomdiv").show();
			
			if(!settings.lens){$j(this).css('cursor','crosshair')}$j(document.body).mousemove(function(e){mouse=new MouseEvent(e);
			
			var bigwidth=$j(".bigimg").get(0).offsetWidth;
			var bigheight=$j(".bigimg").get(0).offsetHeight;
			var scaley='x';
			var scalex='y';
			
			if(isNaN(scalex)|isNaN(scaley)){var scalex=(bigwidth/imageWidth);
			var scaley=(bigheight/imageHeight);
			$j("div.jqZoomPup").width((settings.xzoom)/scalex);
			$j("div.jqZoomPup").height((settings.yzoom)/scaley);
			if(settings.lens){$j("div.jqZoomPup").css('visibility','visible')}}xpos=mouse.x-$j("div.jqZoomPup").width()/2-imageLeft;
			ypos=mouse.y-$j("div.jqZoomPup").height()/2-imageTop;
			if(settings.lens){xpos=(mouse.x-$j("div.jqZoomPup").width()/2<imageLeft)?0:(mouse.x+$j("div.jqZoomPup").width()/2>imageWidth+imageLeft)?(imageWidth-$j("div.jqZoomPup").width()-2):xpos;
			ypos=(mouse.y-$j("div.jqZoomPup").height()/2<imageTop)?0:(mouse.y+$j("div.jqZoomPup").height()/2>imageHeight+imageTop)?(imageHeight-$j("div.jqZoomPup").height()-2):ypos}if(settings.lens){$j("div.jqZoomPup").css({top:ypos,left:xpos})}scrolly=ypos;
			$j("div.zoomdiv").get(0).scrollTop=scrolly*scaley;
			scrollx=xpos;
			$j("div.zoomdiv").get(0).scrollLeft=(scrollx)*scalex})},function(){$j(this).children("img").attr("alt",noalt);
			$j(document.body).unbind("mousemove");
			if(settings.lens){$j("div.jqZoomPup").remove()}$j("div.zoomdiv").remove()});
			count=0;
			if(settings.preload){$j('body').append("<div style='display:none;' class='jqPreload"+count+"'>sdsdssdsd</div>");
			$j(this).each(function(){var imagetopreload=$j(this).children("img").attr("jqimg");
			var content=jQuery('div.jqPreload'+count+'').html();
			jQuery('div.jqPreload'+count+'').html(content+'<img src=\"'+imagetopreload+'\">')})}
			
		}
	}

)
(jQuery);

function MouseEvent(e){
	this.x=e.pageX;
	this.y=e.pageY
	}
