/*
* Zoomy 1.3.3.min - jQuery plugin
* http://redeyeops.com/plugins/zoomy
*
* Copyright (c) 2010 Jacob Lowe (http://redeyeoperations.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Built for jQuery library
* http://jquery.com
*
* Addition fixes and modifications done by Larry Battle ( blarry@bateru.com )
* Code has been refactored and the logic has been corrected.
*
*/

(function(e){var h={count:[]};e.fn.zoomy=function(g,f){var k={move:function(a,b,c){var d=b.attr("rel"),e=a.offset(),l=h[d].zoom.x,j=h[d].zoom.y,a=h[d].css.width,i=h[d].css.height,m=f.zoomSize,n=m/2,g=a/l,k=i/j,d=Math.round(n-n*g),a=a-m+d,i=i-m+d,q=j-m,m=l-m,l=c.pageX-e.left-n,j=c.pageY-e.top-n,g=Math.round((c.pageX-e.left)/g)-n,c=Math.round((c.pageY-e.top)/k)-n,c={0:[g,c,l,j],1:[0,c,-d,j],2:[0,0,-d,-d],3:[0,q,-d,i],4:[g,0,l,-d],5:[m,0,a,-d],6:[m,c,a,j],7:[m,q,a,i],8:[g,q,l,i]},e=-d<=j,n=-d>j,k=i>
j,i=i<=j,j=a>l,d=-d<=l&&e&&j&&k?0:-d>l?e&&k?1:n?2:i?3:null:n?j?4:5:a<=l?k?6:7:i?8:null;b.css({backgroundPosition:"-"+c[d][0]+"px -"+c[d][1]+"px",left:c[d][2],top:c[d][3]})},classes:function(a){var b=a.find(".zoomy").attr("rel");h[b].state===0||h[b].state===null?a.removeClass("inactive"):a.addClass("inactive")},enter:function(a,b){var c=b.attr("rel");h[c].state=1;b.css("visibility","visible");k.classes(a)},leave:function(a,b,c){var d=b.attr("rel");h[d].state=c!==null?null:0;b.css("visibility","hidden");
k.classes(a)},callback:function(a,b){var c=b.attr("rel");a!==null&&typeof a==="function"&&a(h[c])}},o={round:function(a){return!f.round?0:a===void 0?f.zoomSize/2+"px":f.zoomSize/2+"px "+f.zoomSize/2+"px 0px 0px"},glare:function(a){a.children("span").css({height:f.zoomSize/2,width:f.zoomSize-10,margin:e.browser.msie&&parseInt(e.browser.version,10)===9?0:"5px auto","border-radius":o.round(0)})},params:function(a,b){var c=a.children("img"),d={marginTop:c.css("margin-top"),marginRight:c.css("margin-right"),
marginBottom:c.css("margin-bottom"),marginLeft:c.css("margin-left")},g={"float":c.css("float")},l={display:"block",height:c.height(),width:c.width(),position:"relative"},j=b.attr("rel"),i={};if(g["float"]==="none"&&a.parent("*:first").css("text-align")==="center")d.marginRight="auto",d.marginLeft="auto";e.extend(i,d,g,l);h[j].css=i;f.glare||b.children("span").css({height:f.zoomSize-10,width:f.zoomSize-10});b.css({height:f.zoomSize,width:f.zoomSize,"border-radius":o.round()});c.css("margin","0px");
c.one("load",function(){a.css(h[j].css)}).each(function(){(this.complete||e.browser.msie&&parseInt(e.browser.version,10)===6)&&e(this).trigger("load")})}},r={image:function(a,b){var c=b.attr("rel");b.show().css({top:"-999999px",left:"-999999px"});b.find("img").attr("src")!==a&&b.find("img").attr("src",a).load(function(){var d=f.glare?"<span/>":"";h[c].zoom={x:b.find("img").width(),y:b.find("img").height()};b.append(d).css({"background-image":"url("+a+")"}).find("img").remove();o.glare(b)}).each(function(){(this.complete||
e.browser.msie&&parseInt(e.browser.version,10)===6)&&e(this).trigger("load")})},zoom:function(a,b){h[b]={state:null,index:b};h.count.push(0);var c=typeof a.attr(f.attr)==="string"&&f.attr!=="href"?a.attr(f.attr):a.attr("href"),d=null,p=f.zoomInit;(function(){var c=[],e=function(b){k.move(a,d,b)},i=function(){k.enter(a,d);a.bind("mousemove",e);k.callback(f.zoomStart,d)},m=function(b){k.leave(a,d,b);a.unbind("mousemove",e);k.callback(f.zoomStop,d)},n=function(c){f.clickable||c.preventDefault();h[b].state===
0||h[b].state===null?(i(),k.move(a,d,c)):h[b].state===1&&g!=="mouseover"&&g!=="mouseenter"&&m(0)},o=function(){h[b].state===0&&i()},p=function(){return!1};g==="mouseover"?c[g]=n:(c[g]=n,c.mouseover=o);if(!f.clickable&&g!=="click")c.click=p;c.mouseleave=function(){h[b].state===1&&m(null)};a.bind(c)})();a.addClass("parent-zoom").append('<div class="zoomy zoom-obj-'+b+'" rel="'+b+'"><img id="tmp"/></div>');d=e(".zoom-obj-"+b);p!==null&&typeof p==="function"&&p(a);o.params(a,d);r.image(c,d)},init:function(a,
b){b.one("load",function(){r.zoom(a,h.count.length)}).each(function(){(this.complete||e.browser.msie&&parseInt(e.browser.version,10)===6)&&e(this).trigger("load")})}};typeof g==="object"&&f===void 0?(f=g,g="click"):g===void 0&&(g="click");f=e.extend({zoomSize:200,round:!0,glare:!0,clickable:!1,attr:"href",zoomInit:null,zoomStart:null,zoomStop:null},f);e(this).each(function(){var a=e(this),b=a.find("img");r.init(a,b)})}})(jQuery);
