(function(d){var a={allowZoom:true,allowPan:true,viewportWidth:450,viewportHeight:600,maxWidth:1200,topX:-1,topY:-1,bottomX:-1,bottomY:-1,callback:function(i,g,j,h){}};function f(m){m.preventDefault();var h=d(this);var l=h.data("dim");var k=l.origoX-m.clientX;var j=l.origoY-m.clientY;l.origoX=m.clientX;l.origoY=m.clientY;var o=l.x-k;var n=l.y-j;var i=-l.width+l.viewportWidth;var g=-l.height+l.viewportHeight;l.x=o;l.y=n;h.move()}function b(j){j.preventDefault();var i=d(this);var h=i.data("dim");var g=(h.origoY-j.clientY);h.oldWidth=h.width;h.oldHeight=h.height;h.width=((g/100)*h.width)+h.width;h.height=((g/100)*h.height)+h.height;if(i.resize()){h.origoY=j.clientY}}function c(g){g.preventDefault();var j=d(this);var i=j.data("dim");i.origoX=g.clientX;i.origoY=g.clientY;var k=(g.pageX-d(this).offset({scroll:false}).left);var h=(g.pageY-d(this).offset({scroll:false}).top);if(i.allowZoom&&(g.shiftKey||g.ctrlKey)){j.mousemove(b)}else{if(i.allowPan){j.mousemove(f)}}return false}function e(){d(this).unbind("mousemove").store()}d.fn.extend({store:function(){var h=d(this);var g=h.data("dim");var i=g.width/g.actualWidth;g.topX=(-g.x)/i;g.topY=(-g.y)/i;g.bottomX=g.topX+(g.viewportWidth/i);g.bottomY=g.topY+(g.viewportHeight/i);if(typeof g.callback=="function"){g.callback(parseInt(g.topX),parseInt(g.topY),parseInt(g.bottomX),parseInt(g.bottomY))}return h},move:function(){var i=d(this);var h=i.data("dim");var g=-h.width+h.viewportWidth;var j=-h.height+h.viewportHeight;if(h.x>0){h.x=0}else{if(h.x<g){h.x=g}}if(h.y>0){h.y=0}else{if(h.y<j){h.y=j}}d(this).css({left:h.x+"px",top:h.y+"px"});return i},resize:function(){var i=d(this);var h=i.data("dim");var k=true;if(h.width<h.viewportWidth){h.height=parseInt(h.actualHeight*(h.viewportWidth/h.actualWidth));h.width=h.viewportWidth;k=false}if(h.height<h.viewportHeight){h.width=parseInt(h.actualWidth*(h.viewportHeight/h.actualHeight));h.height=h.viewportHeight;k=false}if(h.width>h.maxWidth){h.height=parseInt(h.height*(h.maxWidth/h.width));h.width=h.maxWidth;k=false}d(this).css({width:h.width+"px",height:h.height+"px"});var g=h.width/(-h.x+(h.viewportWidth/2));var j=h.height/(-h.y+(h.viewportHeight/2));h.x=h.x-((h.width-h.oldWidth)/g);h.y=h.y-((h.height-h.oldHeight)/j);d(this).move();return k},zoomin:function(){var i=d(this);var h=i.data("dim");var g=10;h.oldWidth=h.width;h.oldHeight=h.height;h.width=((g/100)*h.width)+h.width;h.height=((g/100)*h.height)+h.height;if(i.resize()){}i.store()},zoomout:function(){var i=d(this);var h=i.data("dim");var g=-10;h.oldWidth=h.width;h.oldHeight=h.height;h.width=((g/100)*h.width)+h.width;h.height=((g/100)*h.height)+h.height;if(i.resize()){}i.store()},setup:function(){var j=d(this);var i=j.data("dim");i.actualWidth=j.width();i.actualHeight=j.height();i.width=i.actualWidth;i.height=i.actualHeight;if(i.topX<0){i.topX=0;i.topY=0;if((i.actualWidth/i.viewportWidth)>(i.actualHeight/i.viewportHeight)){i.bottomY=i.actualHeight;i.bottomX=i.viewportWidth*(i.actualHeight/i.viewportHeight)}else{i.bottomX=i.actualWidth;i.bottomY=i.viewportHeight*(i.actualWidth/i.viewportWidth)}}var h=i.viewportWidth/(i.bottomX-i.topX);var g=i.viewportHeight/(i.bottomY-i.topY);i.width=i.width*h;i.height=i.height*g;i.oldWidth=i.width;i.oldHeight=i.height;i.x=-(i.topX*h);i.y=-(i.topY*g);j.resize();j.store();j.css({position:"relative",cursor:"move",display:"block"});j.mousedown(c);j.mouseup(e);j.mouseout(e)},imagetool:function(g){return this.each(function(){var l=d(this).css({display:"none"});var k=d.extend({},a,g);l.data("dim",k);var j={backgroundColor:"#fff",position:"relative",overflow:"hidden",width:k.viewportWidth+"px",height:k.viewportHeight+"px"};var i=d('<div class="viewport"></div>');i.css(j);l.wrap(i);if(k.loading){var h={"margin-top":(k.viewportHeight/2)-8,"margin-left":(k.viewportWidth/2)-8};d('<img class="loading" src="'+k.loading+'" />').css(h).insertAfter(l)}l.load(function(){d(this).next("img").remove();d(this).setup()});if(d.browser.msie){l.attr("src",l.attr("src")+"?"+(Math.round(2048*Math.random())))}})}})})(jQuery);
