/*!
 * jQzoom Evolution Library v2.3  - Javascript Image magnifier
 * http://www.mind-projects.it
 *
 * Copyright 2011, Engineer Marco Renzi
 * Licensed under the BSD license.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the organization nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * Date: 03 May 2011 22:16:00
 */
(function($){var e=true,a="standard",d="jqzoom",c=false,isIE6=$.browser.msie&&$.browser.version<7,body=$(document.body),window=$(window),jqzoompluging_disabled=c;$.fn.jqzoom=function(a){return this.each(function(){var b=this.nodeName.toLowerCase();b=="a"&&new jqzoom(this,a)})};jqzoom=function(el,options){var q=".zoomWrapperImage",p="block",o="px",n="absolute",m=".zoomWrapper",l=".zoomWindow",k=".zoomPup",j="<div/>",h=".zoomPad",i="reverse",g="innerzoom",f="drag",b="title",e="none";el.picswap=options.picswap||c;var settings2=options.picswap,api=null;api=$(el).data(d);if(api)return api;var obj=this,settings=$.extend({},$.jqzoom.defaults,options||{});obj.el=el;el.rel=$(el).attr("rel");el.zoom_active=c;el.zoom_disabled=c;el.largeimageloading=c;el.largeimageloaded=c;el.scale={};el.timer=null;el.mousepos={};el.mouseDown=c;$(el).css({"outline-style":e,"text-decoration":e});var img=$("img:eq(0)",el);el.title=$(el).attr(b);el.imagetitle=img.attr(b);var zoomtitle=$.trim(el.title).length>0?el.title:el.imagetitle,smallimage=new Smallimage(img),lens=new Lens,stage=new Stage,largeimage=new Largeimage,loader=new Loader;$(el).bind("click",function(a){a.preventDefault();return c});var zoomtypes=[a,f,g,i];if($.inArray($.trim(settings.zoomType),zoomtypes)<0)settings.zoomType=a;$.extend(obj,{create:function(){if($(h,el).length==0){el.zoomPad=$(j).addClass("zoomPad");img.wrap(el.zoomPad)}if(settings.zoomType==g){settings.zoomWidth=smallimage.w;settings.zoomHeight=smallimage.h}$(k,el).length==0&&lens.append();$(l,el).length==0&&stage.append();$(".zoomPreload",el).length==0&&loader.append();(settings.preloadImages||settings.zoomType==f||settings.alwaysOn)&&obj.load();obj.init()},init:function(){if(settings.zoomType==f){$(h,el).mousedown(function(){el.mouseDown=e});$(h,el).mouseup(function(){el.mouseDown=c});document.body.ondragstart=function(){return c};$(h,el).css({cursor:"default"});$(k,el).css({cursor:"move"})}settings.zoomType==g&&$(m,el).css({cursor:"crosshair"});$(h,el).bind("mouseenter mouseover",function(a){img.attr(b,"");$(el).attr(b,"");el.zoom_active=e;smallimage.fetchdata();if(el.picswap){el.picswap=c;el.largeimageloaded=c}if(el.largeimageloaded)obj.activate(a);else obj.load()});$(h,el).bind("mouseleave",function(){obj.deactivate()});$(h,el).bind("mousemove",function(a){if(a.pageX>smallimage.pos.r||a.pageX<smallimage.pos.l||a.pageY<smallimage.pos.t||a.pageY>smallimage.pos.b){lens.setcenter();return c}el.zoom_active=e;el.largeimageloaded&&!$(l,el).is(":visible")&&obj.activate(a);el.largeimageloaded&&(settings.zoomType!=f||settings.zoomType==f&&el.mouseDown)&&lens.setposition(a)});var thumb_preload=[],i=0,thumblist=[];thumblist=$("a").filter(function(){var a=new RegExp("gallery[\\s]*:[\\s]*'"+$.trim(el.rel)+"'","i"),b=$(this).attr("rel");if(a.test(b))return this});if(thumblist.length>0){var first=thumblist.splice(0,1);thumblist.push(first)}thumblist.each(function(){if(settings.preloadImages){var thumb_options=$.extend({},eval("("+$.trim($(this).attr("rel"))+")"));thumb_preload[i]=new Image;thumb_preload[i].src=thumb_options.largeimage;i++}$(this).click(function(b){var a="zoomThumbActive";if($(this).hasClass(a))return c;thumblist.each(function(){$(this).removeClass(a)});b.preventDefault();obj.swapimage(this);return c})})},load:function(){if(el.largeimageloaded==c&&el.largeimageloading==c){var a=$(el).attr("href");el.largeimageloading=e;largeimage.loadimage(a)}},activate:function(){clearTimeout(el.timer);lens.show();stage.show()},deactivate:function(){switch(settings.zoomType){case f:break;default:img.attr(b,el.imagetitle);$(el).attr(b,el.title);if(settings.alwaysOn)lens.setcenter();else{stage.hide();lens.hide()}}el.zoom_active=c},swapimage:function(link){el.largeimageloading=c;el.largeimageloaded=c;var options={};options=$.extend({},eval("("+$.trim($(link).attr("rel"))+")"));if(options.smallimage&&options.largeimage){var smallimage=options.smallimage,largeimage=options.largeimage;$(link).addClass("zoomThumbActive");$(el).attr("href",largeimage);img.attr("src",smallimage);lens.hide();stage.hide();obj.load()}else{alert("ERROR :: Missing parameter for largeimage or smallimage.");throw"ERROR :: Missing parameter for largeimage or smallimage.";}return false}});if(img[0].complete){smallimage.fetchdata();$(h,el).length==0&&obj.create()}function Smallimage(image){var a=this,$obj=a;a.node=image[0];a.findborder=function(){var bordertop=0;bordertop=image.css("border-top-width");btop="";var borderleft=0;borderleft=image.css("border-left-width");bleft="";if(bordertop)for(i=0;i<3;i++){var x=[];x=bordertop.substr(i,1);if(isNaN(x)==c)btop=btop+""+bordertop.substr(i,1);else break}if(borderleft)for(i=0;i<3;i++)if(!isNaN(borderleft.substr(i,1)))bleft=bleft+borderleft.substr(i,1);else break;$obj.btop=btop.length>0?eval(btop):0;$obj.bleft=bleft.length>0?eval(bleft):0};a.fetchdata=function(){$obj.findborder();$obj.w=image.width();$obj.h=image.height();$obj.ow=image.outerWidth();$obj.oh=image.outerHeight();$obj.pos=image.offset();$obj.pos.l=image.offset().left+$obj.bleft;$obj.pos.t=image.offset().top+$obj.btop;$obj.pos.r=$obj.w+$obj.pos.l;$obj.pos.b=$obj.h+$obj.pos.t;$obj.rightlimit=image.offset().left+$obj.ow;$obj.bottomlimit=image.offset().top+$obj.oh};a.node.onerror=function(){var a="Problems while loading image.";alert(a);throw a;};a.node.onload=function(){$obj.fetchdata();$(h,el).length==0&&obj.create()};return $obj}function Loader(){var b="visibility",a=this,c=a;a.append=function(){this.node=$(j).addClass("zoomPreload").css(b,"hidden").html(settings.preloadText);$(h,el).append(this.node)};a.show=function(){var a=this;a.node.top=(smallimage.oh-a.node.height())/2;a.node.left=(smallimage.ow-a.node.width())/2;a.node.css({top:a.node.top,left:a.node.left,position:n,visibility:"visible"})};a.hide=function(){this.node.css(b,"hidden")};return a}function Lens(){var a=this,b=a;a.node=$(j).addClass("zoomPup");a.append=function(){var a=this;$(h,el).append($(a.node).hide());if(settings.zoomType==i){a.image=new Image;a.image.src=smallimage.node.src;$(a.node).empty().append(a.image)}};a.setdimensions=function(){var a=this;a.node.w=parseInt(settings.zoomWidth/el.scale.x)>smallimage.w?smallimage.w:parseInt(settings.zoomWidth/el.scale.x);a.node.h=parseInt(settings.zoomHeight/el.scale.y)>smallimage.h?smallimage.h:parseInt(settings.zoomHeight/el.scale.y);a.node.top=(smallimage.oh-a.node.h-2)/2;a.node.left=(smallimage.ow-a.node.w-2)/2;a.node.css({top:0,left:0,width:a.node.w+o,height:a.node.h+o,position:n,display:e,borderWidth:1+o});if(settings.zoomType==i){a.image.src=smallimage.node.src;$(a.node).css({opacity:1});$(a.image).css({position:n,display:p,left:-(a.node.left+1-smallimage.bleft)+o,top:-(a.node.top+1-smallimage.btop)+o})}};a.setcenter=function(){var a=this;a.node.top=(smallimage.oh-a.node.h-2)/2;a.node.left=(smallimage.ow-a.node.w-2)/2;a.node.css({top:a.node.top,left:a.node.left});settings.zoomType==i&&$(a.image).css({position:n,display:p,left:-(a.node.left+1-smallimage.bleft)+o,top:-(a.node.top+1-smallimage.btop)+o});largeimage.setposition()};a.setposition=function(d){var a=this;el.mousepos.x=d.pageX;el.mousepos.y=d.pageY;var b=0,c=0;function g(a){return el.mousepos.x-a.w/2<smallimage.pos.l}function f(a){return el.mousepos.x+a.w/2>smallimage.pos.r}function h(a){return el.mousepos.y-a.h/2<smallimage.pos.t}function e(a){return el.mousepos.y+a.h/2>smallimage.pos.b}b=el.mousepos.x+smallimage.bleft-smallimage.pos.l-(a.node.w+2)/2;c=el.mousepos.y+smallimage.btop-smallimage.pos.t-(a.node.h+2)/2;if(g(a.node))b=smallimage.bleft-1;else if(f(a.node))b=smallimage.w+smallimage.bleft-a.node.w-1;if(h(a.node))c=smallimage.btop-1;else if(e(a.node))c=smallimage.h+smallimage.btop-a.node.h-1;a.node.left=b;a.node.top=c;a.node.css({left:b+o,top:c+o});if(settings.zoomType==i){$.browser.msie&&$.browser.version>7&&$(a.node).empty().append(a.image);$(a.image).css({position:n,display:p,left:-(a.node.left+1-smallimage.bleft)+o,top:-(a.node.top+1-smallimage.btop)+o})}largeimage.setposition()};a.hide=function(){img.css({opacity:1});this.node.hide()};a.show=function(){settings.zoomType!=g&&(settings.lens||settings.zoomType==f)&&this.node.show();settings.zoomType==i&&img.css({opacity:settings.imageOpacity})};a.getoffset=function(){var a={};a.left=b.node.left;a.top=b.node.top;return a};return a}function Stage(){var a=this,b=a;a.node=$("<div class='zoomWindow'><div class='zoomWrapper'><div class='zoomWrapperTitle'></div><div class='zoomWrapperImage'></div></div></div>");a.ieframe=$('<iframe class="zoomIframe" src="javascript:\'\';" marginwidth="0" marginheight="0" align="bottom" scrolling="no" frameborder="0" ></iframe>');a.setposition=function(){var a=this;a.node.leftpos=0;a.node.toppos=0;if(settings.zoomType!=g)switch(settings.position){case"left":a.node.leftpos=smallimage.pos.l-smallimage.bleft-Math.abs(settings.xOffset)-settings.zoomWidth>0?0-settings.zoomWidth-Math.abs(settings.xOffset):smallimage.ow+Math.abs(settings.xOffset);a.node.toppos=Math.abs(settings.yOffset);break;case"top":a.node.leftpos=Math.abs(settings.xOffset);a.node.toppos=smallimage.pos.t-smallimage.btop-Math.abs(settings.yOffset)-settings.zoomHeight>0?0-settings.zoomHeight-Math.abs(settings.yOffset):smallimage.oh+Math.abs(settings.yOffset);break;case"bottom":a.node.leftpos=Math.abs(settings.xOffset);a.node.toppos=smallimage.pos.t-smallimage.btop+smallimage.oh+Math.abs(settings.yOffset)+settings.zoomHeight<screen.height?smallimage.oh+Math.abs(settings.yOffset):0-settings.zoomHeight-Math.abs(settings.yOffset);break;default:a.node.leftpos=smallimage.rightlimit+Math.abs(settings.xOffset)+settings.zoomWidth<screen.width?smallimage.ow+Math.abs(settings.xOffset):0-settings.zoomWidth-Math.abs(settings.xOffset);a.node.toppos=Math.abs(settings.yOffset)}a.node.css({left:a.node.leftpos+o,top:a.node.toppos+o});return a};a.append=function(){var c=".zoomWrapperTitle",a=this;$(h,el).append(a.node);a.node.css({position:n,display:e,zIndex:5001});if(settings.zoomType==g){a.node.css({cursor:"default"});var d=smallimage.bleft==0?1:smallimage.bleft;$(m,a.node).css({borderWidth:d+o})}$(m,a.node).css({width:Math.round(settings.zoomWidth)+o,borderWidth:d+o});$(q,a.node).css({width:"100%",height:Math.round(settings.zoomHeight)+o});$(c,a.node).css({width:"100%",position:n});$(c,a.node).hide();settings.title&&zoomtitle.length>0&&$(c,a.node).html(zoomtitle).show();b.setposition()};a.hide=function(){switch(settings.hideEffect){case"fadeout":this.node.fadeOut(settings.fadeoutSpeed,function(){});break;default:this.node.hide()}this.ieframe.hide()};a.show=function(){var a=this;switch(settings.showEffect){case"fadein":a.node.fadeIn();a.node.fadeIn(settings.fadeinSpeed,function(){});break;default:a.node.show()}if(isIE6&&settings.zoomType!=g){a.ieframe.width=a.node.width();a.ieframe.height=a.node.height();a.ieframe.left=a.node.leftpos;a.ieframe.top=a.node.toppos;a.ieframe.css({display:p,position:n,left:a.ieframe.left,top:a.ieframe.top,zIndex:99,width:a.ieframe.width+o,height:a.ieframe.height+o});$(h,el).append(a.ieframe);a.ieframe.show()}}}function Largeimage(){var b=this,a=b;b.node=new Image;b.loadimage=function(b){var a=this;loader.show();a.url=b;a.node.style.position=n;a.node.style.border="0px";a.node.style.display=e;a.node.style.left="-5000px";a.node.style.top="0px";document.body.appendChild(a.node);a.node.src=b};b.fetchdata=function(){var c=this,b=$(c.node),d={};c.node.style.display=p;a.w=b.width();a.h=b.height();a.pos=b.offset();a.pos.l=b.offset().left;a.pos.t=b.offset().top;a.pos.r=a.w+a.pos.l;a.pos.b=a.h+a.pos.t;d.x=a.w/smallimage.w;d.y=a.h/smallimage.h;el.scale=d;document.body.removeChild(c.node);$(q,el).empty().append(c.node);lens.setdimensions()};b.node.onerror=function(){var a="Problems while loading the big image.";alert(a);throw a;};b.node.onload=function(){a.fetchdata();loader.hide();el.largeimageloading=c;el.largeimageloaded=e;if(settings.zoomType==f||settings.alwaysOn){lens.show();stage.show();lens.setcenter()}};b.setposition=function(){var a=-el.scale.x*(lens.getoffset().left-smallimage.bleft+1),b=-el.scale.y*(lens.getoffset().top-smallimage.btop+1);$(this.node).css({left:a+o,top:b+o})};return b}$(el).data(d,obj)};$.jqzoom={defaults:{zoomType:a,zoomWidth:300,zoomHeight:300,xOffset:10,yOffset:0,position:"right",preloadImages:e,preloadText:"Loading zoom",title:e,lens:e,imageOpacity:.4,alwaysOn:c,showEffect:"show",hideEffect:"hide",fadeinSpeed:"slow",fadeoutSpeed:"2000",picswap:c},disable:function(b){var a=$(b).data(d);a.disable();return c},enable:function(b){var a=$(b).data(d);a.enable();return c},disableAll:function(){jqzoompluging_disabled=e},enableAll:function(){jqzoompluging_disabled=c}}})(jQuery);
