(function(a){a.fn.fancyZoom=function(b){function l(c){if(d)return!1;d=!0;var e=a(a(this).attr("href")),f=b.width,g=b.height,h=window.innerWidth||window.document.documentElement.clientWidth||window.document.body.clientWidth,k=window.innerHeight||window.document.documentElement.clientHeight||window.document.body.clientHeight,l=window.pageXOffset||window.document.documentElement.scrollLeft||window.document.body.scrollLeft,n=window.pageYOffset||window.document.documentElement.scrollTop||window.document.body.scrollTop,q={width:h,height:k,x:l,y:n},h=(f||e.width())+60,k=(g||e.height())+60,r=q,s=Math.max(r.height/2-k/2+n,0),t=r.width/2-h/2,u=c.pageY,v=c.pageX;return i.attr("curTop",u),i.attr("curLeft",v),i.attr("scaleImg",b.scaleImg?"true":"false"),a("#zoom").hide().css({position:"absolute",top:u+"px",left:v+"px",width:"1px",height:"1px"}),o(),i.hide(),b.closeOnClick&&a("#zoom").click(m),b.scaleImg?(j.html(e.html()),a("#zoom_content img").css("width","100%")):j.html(""),a("#zoom").animate({top:s+"px",left:t+"px",opacity:"show",width:h,height:k},500,null,function(){b.scaleImg!=1&&j.html(e.html()),p(),i.show(),d=!1}),!1}function m(){return d?!1:(d=!0,a("#zoom").unbind("click"),o(),i.attr("scaleImg")!="true"&&j.html(""),i.hide(),a("#zoom").animate({top:i.attr("curTop")+"px",left:i.attr("curLeft")+"px",opacity:"hide",width:"1px",height:"1px"},500,null,function(){i.attr("scaleImg")=="true"&&j.html(""),p(),d=!1}),!1)}function n(b){a("#zoom_table td").each(function(c){var d=a(this).css("background-image").replace(/\.(png|gif|none)\"\)$/,"."+b+'")');a(this).css("background-image",d)});var c=i.children("img"),d=c.attr("src").replace(/\.(png|gif|none)$/,"."+b);c.attr("src",d)}function o(){a.browser.msie&&parseFloat(a.browser.version)>=7&&n("gif")}function p(){a.browser.msie&&a.browser.version>=7&&n("png")}var b=b||{},c=b&&b.directory?b.directory:"images",d=!1;if(a("#zoom").length==0){var e=a.browser.msie?"gif":"png",f='<div id="zoom" style="display:none;">                   <table id="zoom_table" style="border-collapse:collapse; width:100%; height:100%;">                     <tbody>                       <tr>                         <td class="tl" style="background:url('+c+"/tl."+e+') 0 0 no-repeat; width:20px; height:20px; overflow:hidden;" />                         <td class="tm" style="background:url('+c+"/tm."+e+') 0 0 repeat-x; height:20px; overflow:hidden;" />                         <td class="tr" style="background:url('+c+"/tr."+e+') 100% 0 no-repeat; width:20px; height:20px; overflow:hidden;" />                       </tr>                       <tr>                         <td class="ml" style="background:url('+c+"/ml."+e+') 0 0 repeat-y; width:20px; overflow:hidden;" />                         <td class="mm" style="background:#fff; vertical-align:top; padding:10px;">                           <div id="zoom_content">                           </div>                         </td>                         <td class="mr" style="background:url('+c+"/mr."+e+') 100% 0 repeat-y;  width:20px; overflow:hidden;" />                       </tr>                       <tr>                         <td class="bl" style="background:url('+c+"/bl."+e+') 0 100% no-repeat; width:20px; height:20px; overflow:hidden;" />                         <td class="bm" style="background:url('+c+"/bm."+e+') 0 100% repeat-x; height:20px; overflow:hidden;" />                         <td class="br" style="background:url('+c+"/br."+e+') 100% 100% no-repeat; width:20px; height:20px; overflow:hidden;" />                       </tr>                     </tbody>                   </table>                   <a href="#" title="Close" id="zoom_close" style="position:absolute; top:0; left:0;">                     <img src="'+c+"/closebox."+e+'" alt="Close" style="border:none; margin:0; padding:0;" />                   </a>                 </div>';a("body").append(f),a("html").click(function(b){a(b.target).parents("#zoom:visible").length==0&&m()}),a(document).keyup(function(b){b.keyCode==27&&a("#zoom:visible").length>0&&m()}),a("#zoom_close").click(m)}var g=a("#zoom"),h=a("#zoom_table"),i=a("#zoom_close"),j=a("#zoom_content"),k=a("td.ml,td.mm,td.mr");return this.each(function(b){a(a(this).attr("href")).hide(),a(this).click(l)}),this}})(jQuery)
