;(function(){var zimage={libs:{},types:/\.jpg|\.jpeg|\.png|\.gif|\.bmp/g,current:null,moved:false,pointer:{x:0,y:0},diff:{x:0,y:0},trackKey:false,defaults:{opacity:0.3,border:0,shadow:6,duration:400,prevent:14,controls:true,caption:true,hideSource:true,centered:true,className:false,onLoad:function(){return false},beforeZoomIn:function(){return false},onZoomIn:function(){return false},beforeZoomOut:function(){return false},onZoomOut:function(){return false},onFocus:function(){return false},controlsTrigger:'focus',easing:'linear',preload:'click'},template:['<div class="zoomimage">','<div class="zoomimage_s">','<div class="zoomimage_st">','<div class="zoomimage_stl"></div>','<div class="zoomimage_stc"></div>','<div class="zoomimage_str"></div>','</div>','<div class="zoomimage_sc">','<div class="zoomimage_scl"></div>','<div class="zoomimage_scc"></div>','<div class="zoomimage_scr"></div>','</div>','<div class="zoomimage_sb">','<div class="zoomimage_sbl"></div>','<div class="zoomimage_sbc"></div>','<div class="zoomimage_sbr"></div>','</div>','</div>','<img />','<div class="zoomimage_controls">','<a href="#" class="zoomimage_prev"></a>','<a href="#" class="zoomimage_next"></a>','</div>','<div class="zoomimage_caption"></div>','<div class="zoomimage_loading"></div>','</div>'],zoomIn:function(el){if(el.zoomimageCfg.loaded===false){if(el.zoomimageCfg.loading!=true){el.zoomimageCfg.loading=true;zimage.preload(el)}return}if(el.zoomimageCfg.zoomed==true){zimage.focus(el);return}el.zoomimageCfg.beforeZoomIn.apply(el,[el.zoomimageCfg.box]);var elPos=jQuery(el).offset();elPos.innerWidth=jQuery(el).width();elPos.innerHeight=jQuery(el).height();var bodyOffset={scrollTop:jQuery('body').scrollTop(),scrollLeft:jQuery('body').scrollLeft()};var windowOffset={innerWidth:jQuery(window).width(),innerHeight:jQuery(window).height()};var borderAndShadow=el.zoomimageCfg.border+el.zoomimageCfg.shadow;var width=el.zoomimageCfg.width+borderAndShadow*2;var height=el.zoomimageCfg.height+borderAndShadow*2;var screenRatio=windowOffset.innerWidth/windowOffset.innerHeight;var imageRatio=el.zoomimageCfg.width/el.zoomimageCfg.height;if(screenRatio>imageRatio){if(height>windowOffset.innerHeight){height=windowOffset.innerHeight;width=parseInt(height*imageRatio,10)}}else if(width>windowOffset.innerWidth){width=windowOffset.innerWidth;height=parseInt(width/imageRatio,10)}var top=el.zoomimageCfg.centered?bodyOffset.scrollTop+parseInt((windowOffset.innerHeight-height)/2,10):Math.min(Math.max(bodyOffset.scrollTop,elPos.top+(elPos.innerHeight-height)/2-borderAndShadow),bodyOffset.scrollTop+windowOffset.innerHeight-height);var left=el.zoomimageCfg.centered?bodyOffset.scrollLeft+parseInt((windowOffset.innerWidth-width)/2,10):Math.min(Math.max(bodyOffset.scrollLeft,elPos.left+(elPos.innerWidth-width)/2-borderAndShadow),bodyOffset.scrollLeft+windowOffset.innerWidth-width);var imgWidth=width-borderAndShadow*2;var imgHeight=height-borderAndShadow*2;if(el.zoomimageCfg.hideSource===true){el.style.visibility='hidden'}jQuery('#'+el.zoomimageCfg.box).css({top:elPos.top+'px',left:elPos.left+'px',width:elPos.innerWidth+'px',height:elPos.innerHeight+'px'}).find('>div').hide().end().find('img').attr('src',el.zoomimageCfg.src).css({top:0,left:0,width:'100%',height:'100%',display:'block',borderWidth:'0px'}).end().animate({width:imgWidth,height:imgHeight,top:top+borderAndShadow,left:left+borderAndShadow},el.zoomimageCfg.duration,el.zoomimageCfg.easing,function(){jQuery(this).css({top:top+'px',left:left+'px',width:width+'px',height:height+'px'}).find('img').css({top:el.zoomimageCfg.shadow+'px',left:el.zoomimageCfg.shadow+'px',width:imgWidth+'px',height:imgHeight+'px',borderWidth:el.zoomimageCfg.border+'px'}).end().find('>div:first').find('div.zoomimage_sc').css('height',height-el.zoomimageCfg.shadow*2+'px').end().show();el.zoomimageCfg.zoomed=true;zimage.focus(el);el.zoomimageCfg.onZoomIn.apply(el,[el.zoomimageCfg.box])})},showControls:function(el){if(el==undefined)return;if(el.zoomimageCfg==undefined){el=jQuery('#'+jQuery(el).attr('zoomimage')).get(0)}var height,imgWidth,borderAndShadow=el.zoomimageCfg.border+el.zoomimageCfg.shadow;jQuery('#'+el.zoomimageCfg.box).find('img').each(function(){imgWidth=parseInt($.curCSS(this,'width'),10)}).end().get(0).zoomimageControls=true;if(el.zoomimageCfg.caption){jQuery('#'+el.zoomimageCfg.box).find('>div:eq(2)').stop().css({bottom:borderAndShadow+'px',left:borderAndShadow+'px',width:imgWidth+'px'}).show().each(function(){this.style.height='auto';height=this.offsetHeight;this.style.height='0'}).animate({height:height},el.zoomimageCfg.duration)}if(el.zoomimageCfg.controls){if(zimage.libs[el.zoomimageCfg.lib]>1){jQuery('#'+el.zoomimageCfg.box).find('>div:eq(1)').show().each(function(){if(!el.zoomimageCfg.controlsHeight){el.zoomimageCfg.controlsHeight=this.offsetHeight}this.style.height='0'}).css({top:borderAndShadow+'px',left:borderAndShadow+'px',width:imgWidth+'px'}).animate({height:el.zoomimageCfg.controlsHeight},el.zoomimageCfg.duration)}}},zoomOut:function(el,goToNext){var boxEl,elPos,borderAndShadow,elSize;if(el.zoomimageCfg){if(el.zoomimageCfg.zoomed===false){return}el.zoomimageCfg.beforeZoomOut.apply(el,[el.zoomimageCfg.box]);boxEl=document.getElementById(el.zoomimageCfg.box)}else{boxEl=el;el=jQuery('a[href='+jQuery('img',boxEl).attr('src')+']').get(0)}if(el){elPos=jQuery(el).offset();el.zoomimageCfg.zoomed=false;borderAndShadow=el.zoomimageCfg.border+el.zoomimageCfg.shadow;elSize={width:el.offsetWidth,height:el.offsetHeight}}else{borderAndShadow=zimage.defaults.border+zimage.defaults.shadow;elSize={width:0,height:0};elPos=jQuery(boxEl).offset();elPos.top+=parseInt(boxEl.offsetHeight/2,10);elPos.left+=parseInt(boxEl.offsetWidth/2,10)}jQuery(boxEl).css({top:boxEl.offsetTop+borderAndShadow+'px',left:boxEl.offsetLeft+borderAndShadow+'px',width:boxEl.offsetWidth-borderAndShadow*2+'px',height:boxEl.offsetHeight-borderAndShadow*2+'px'}).find('>div').stop().hide().end().find('img').css({top:0,left:0,width:'100%',height:'100%',borderWidth:'0px'}).end().animate({top:elPos.top+'px',left:elPos.left+'px',width:elSize.width+'px',height:elSize.height+'px'},el?el.zoomimageCfg.duration:zimage.defaults.duration,el.zoomimageCfg.easing,function(){zimage.blur();jQuery(this).hide();if(el){if(el.zoomimageCfg.hideSource===true){el.style.visibility='visible'}el.zoomimageCfg.onZoomOut.apply(el,[el.zoomimageCfg.box]);if(!goToNext){zimage.focus(jQuery('div.zoomimage:visible:last').not(':animated').get(0))}}else{jQuery(boxEl).stop().remove()}})},mouseOver:function(e){var triggerEl=document.getElementById(jQuery(this).attr('zoomimage'));if(triggerEl.zoomimageCfg.zoomed===true&&this.zoomimageControls==false){zimage.showControls(triggerEl)}return false},mouseOut:function(e){return false},mouseDown:function(e){var triggerEl=document.getElementById(jQuery(this).attr('zoomimage'));if(triggerEl){$.extend(zimage,{current:this,prevent:triggerEl.zoomimageCfg.prevent,moved:false,diff:{x:e.pageX-this.offsetLeft,y:e.pageY-this.offsetTop},pointer:{x:e.pageX,y:e.pageY}});jQuery(document).bind('mousemove',zimage.mouseMove).bind('mouseup',zimage.mouseUp)}else{jQuery(this).zoomimageClear()}return false},mouseMove:function(e){var diffX=Math.abs(zimage.pointer.x-e.pageX);var diffY=Math.abs(zimage.pointer.y-e.pageY);if(zimage.moved===false){if(diffX>zimage.prevent||diffY>zimage.prevent){zimage.moved=true;jQuery(zimage.current).addClass('zoomimage_move');if(!jQuery(zimage.current).is('.zoomimage_focused')){zimage.focus(zimage.current)}}}else{zimage.current.style.top=e.pageY-zimage.diff.y+'px';zimage.current.style.left=e.pageX-zimage.diff.x+'px'}return false},mouseUp:function(e){jQuery(zimage.current).removeClass('zoomimage_move');zimage.current=null;jQuery(document).unbind('mousemove',zimage.mouseMove).unbind('mouseup',zimage.mouseUp);return false},imageClick:function(e){jQuery(document).unbind('mousemove',zimage.mouseMove).unbind('mouseup',zimage.mouseUp);var el=document.getElementById(jQuery(this).attr('zoomimage'));if(el){if(zimage.moved===false&&jQuery(this).is('.zoomimage_focused')){if(jQuery(e.target).is('a')){zimage.zoomNext(el,e.target.className=='zoomimage_next'?1:-1);var goToNext=true}else{zimage.zoomOut(el,goToNext||false)}}else if(!jQuery(this).is('.zoomimage_focused')){zimage.focus(this)}}else{jQuery(this).zoomimageClear()}return false},clear:function(){var subject=this;if(subject.size()==0){subject=jQuery('div.zoomimage')}return subject.each(function(){var triggerEl=document.getElementById(jQuery(this).attr('zoomimage'));if(triggerEl){zimage.zoomOut(triggerEl,false)}else{zimage.zoomOut(this,false)}})},zoomNext:function(el,dir){if(el.zoomimageCfg.zoomed===false){return}zimage.zoomOut(el,true);var nextImg=el.zoomimageCfg.iteration+dir;var lib=jQuery(el).attr('zoomimage');var maxImg=zimage.libs[lib];if(nextImg<0){nextImg=maxImg-1}else if(nextImg>=maxImg){nextImg=0}zimage.zoomIn(jQuery('a[zoomimage="'+lib+'"]').get(nextImg))},keyPressed:function(e){var el=jQuery('div.zoomimage_focused');if(el.size()==1){var pressedKey=e.charCode||e.keyCode||-1;el=jQuery('#'+jQuery(el).attr('zoomimage')).get(0);var lib=jQuery(el).attr('zoomimage');switch(pressedKey){case 35:if(zimage.libs[lib]>1&&zimage.libs[lib]-1!=el.zoomimageCfg.iteration){zimage.zoomNext(el,zimage.libs[lib]-el.zoomimageCfg.iteration-1);return false}break;case 36:if(zimage.libs[lib]>1&&el.zoomimageCfg.iteration!=0){zimage.zoomNext(el,-el.zoomimageCfg.iteration);return false}break;case 40:case 37:case 8:case 33:case 80:case 112:if(zimage.libs[lib]>1){zimage.zoomNext(el,-1);return false}break;case 38:case 39:case 34:case 32:case 110:case 78:if(zimage.libs[lib]>1){zimage.zoomNext(el,1);return false}break;case 27:zimage.zoomOut(el,false);return false;break}}},focus:function(el){if(el==undefined)return;if(el.zoomimageCfg==undefined){el=jQuery('#'+jQuery(el).attr('zoomimage')).get(0)}else{var showControls=true}zimage.blur(el);jQuery('#'+el.zoomimageCfg.box).not('.zoomimage_focused').addClass('zoomimage_focused');el.zoomimageCfg.onFocus.apply(el,[el.zoomimageCfg.box]);if(el.zoomimageCfg.controlsTrigger=='focus'||showControls){zimage.showControls(el)}},blur:function(el){jQuery('div.zoomimage_focused').not('#'+(el==undefined?'fakezoomimage':el.zoomimageCfg.box)).removeClass('zoomimage_focused').each(function(){this.zoomimageControls=false}).find('>div:not(:first)').stop().hide()},preload:function(el){var boxEl=jQuery('#'+el.zoomimageCfg.box).show();boxEl.find('>div, img').hide();var elPos=jQuery(el).offset();boxEl.find('>div:last').show().end().css({top:elPos.top+'px',left:elPos.left+'px',width:el.offsetWidth+'px',height:el.offsetHeight+'px'});var preld=new Image();preld.src=el.href;if(preld.complete){zimage.markPreloaded(preld,el)}else{preld.onload=function(){zimage.markPreloaded(preld,el)}}},markPreloaded:function(preld,el){$.extend(el.zoomimageCfg,{loaded:true,width:preld.width,height:preld.height,src:preld.src});jQuery('#'+el.zoomimageCfg.box).find('div.zoomimage_loading').hide();if(el.zoomimageCfg.loading){el.zoomimageCfg.loading=false;zimage.zoomIn(el)}el.zoomimageCfg.onLoad.apply(el,[el.zoomimageCfg.box])}};jQuery.fn.zoomimage=function(opt){var libKey=parseInt(Math.random()*2000,10);zimage.libs[libKey]=0;opt=$.extend({lib:libKey},zimage.defaults,opt||{});return this.each(function(){var jQEl=jQuery(this);var el=this;if(el.href&&el.href.toLowerCase().match(zimage.types)!=null){el.zoomimageCfg=$.extend({},opt,{zoomed:false,loading:false,loaded:false,animated:false,src:el.href,iteration:zimage.libs[libKey],box:'zoomimage_'+parseInt(Math.random()*2000,10)+''});zimage.libs[libKey]++;jQEl.click(function(){el.blur();if(el.zoomimageCfg.loading===true)return false;if(el.zoomimageCfg.zoomed==false)zimage.zoomIn(el);else zimage.zoomOut(el,false);return false}).attr('zoomimage',libKey).attr('zoomimageBox',el.zoomimageCfg.box);var currId=jQEl.attr('id');if(!currId){currId=el.zoomimageCfg.box+'_trigger';jQEl.attr('id',currId)}var titleAttr=jQuery(el).attr('title');if(titleAttr==''||titleAttr==false)el.zoomimageCfg.caption=false;jQuery(zimage.template.join('')).attr('id',el.zoomimageCfg.box).attr('zoomimage',currId).addClass(el.zoomimageCfg.className).appendTo(document.body).bind('mousedown',zimage.mouseDown).bind('click',zimage.imageClick).each(function(){this.zoomimageControls=false;if(el.zoomimageCfg.controlsTrigger!='focus'){jQuery(this).bind('mouseover',zimage.mouseOver).bind('mouseout',zimage.mouseOut)}}).find('>div').not(':first').css('opacity',el.zoomimageCfg.opacity).end().filter('div:eq(2)').html('<p>'+titleAttr+'</p>');if(el.zoomimageCfg.preload=='load')zimage.preload(el);if(zimage.trackKey===false){zimage.trackKey=true;jQuery(document).bind('keydown',zimage.keyPressed)}}})}})(jQuery);
