$(document).ready(
    function(){
		if(document.getElementById("imagegross")){
		   if($("#imagegross").attr("alt").indexOf("noPic")==-1){
			   $("img.imagezoom").jqueryzoom({xzoom:250,yzoom:250,offset:10,position:"right"});
			}
		}
	}
);
 
(function($){
		  $.fn.jqueryzoom=function(options){
			  var settings={xzoom:250,yzoom:250,offset:10,position:"right"};
			  if(options){$.extend(settings,options);}
				$(this).hover(function(){
									   var imageLeft=$(this).get(0).offsetLeft;
									   var imageRight=$(this).get(0).offsetRight;
									   var imageTop=$(this).get(0).offsetTop;
									   var imageWidth=$(this).get(0).offsetWidth;
									   var imageHeight=$(this).get(0).offsetHeight;
									  
									   var imageZWidth=$(this).attr("Zwidth");
									   var imageZHeight=$(this).attr("Zheight");
									   
									   var bigimage=$(this).attr("alt");
									   if($("div.zoomdiv").length==0){
										   $(this).after("<div class='zoomdiv' style='background:url("+bigimage+") no-repeat;'><!-- --></div>");
									   }
									   var zoomdiv=$("div.zoomdiv");
									   if(settings.position=="right"){
										   leftpos=imageLeft+imageWidth+settings.offset;
									   }else{
										   leftpos=imageLeft-settings.xzoom-settings.offset;
									   }
									   zoomdiv.css({top:imageTop,left:leftpos});
									   zoomdiv.width(settings.xzoom);
									   zoomdiv.height(settings.yzoom);
									   
									   zoomdiv.xwidth = imageZWidth;
									   zoomdiv.zheight= imageZHeight;
									   zoomdiv.show();
									   $(this).mousemove(function(e){
																  var evt=e.originalEvent||event;
																  var mx=evt.layerX||evt.offsetX;
																  var my=evt.layerY||evt.offsetY;
																 
																  //alert('x:' + zoomdiv.zheight + '\ny:' + zoomdiv.xwidth);
																  fx = Math.round((zoomdiv.xwidth / 120) * 100) / 100;
																  fy = Math.round((zoomdiv.zheight / 120) * 100) / 100;
																  
																 // alert('fx :' + fx + 'fy:' + fy);
																  
																  x=(fx*mx);
																  y=(fy*my);
																 
																  if(x>zoomdiv.xwidth)x=zoomdiv.xwidth;
																  if(y>zoomdiv.zheight)y=zoomdiv.zheight;
																  
																  if(y<0)y=0;
																  if(x<0)x=0;
																  zoomdiv.css("background-position","-"+x+"px "+"-"+y+"px");
														});
						},function(){
							$("div.zoomdiv").hide();
							$(this).unbind("mousemove");
							$(".lenszoom").remove();
							$("div.zoomdiv").remove();
						});
				}
			}
		)(jQuery);
