(function($){$.fn.fancyzoom=function(useroptions){var ooverlay=$('
').css({height:'100%',width:'100%',position:'fixed',zindex:100,left:0,top:0,cursor:"wait"});function openzoombox(imgsrc,o){if(o.showoverlay){ooverlay.appendto('body').click(function(){closezoombox(o)});if($.browser.msie&&$.browser.version<7){ooverlay.css({position:'absolute',height:$(document).height(),width:$(document).width()})}}var oimgzoombox=o.oimgzoombox;pos=imgsrc.offset();o=$.extend(o,{imgsrc:imgsrc,dimori:{width:imgsrc.outerwidth(),height:imgsrc.outerheight(),left:pos.left,top:pos.top,'opacity':1}});if(!imgsrc.is('img')){o.dimori=$.extend(o.dimori,{width:0,height:0})}oimgzoombox.css({'text-align':'center','border':'0px solid red'}).appendto('body');var iwidth=oimgzoombox.outerwidth();var iheight=oimgzoombox.outerheight();dimboxtarget=$.extend({},{width:iwidth,height:iheight,'opacity':1},__poscenter((iwidth),(iheight+30)));o.oimgclose.css({left:(dimboxtarget.left+dimboxtarget.width-15),top:(dimboxtarget.top-15)});var $fctend=function(){if($.fn.shadow&&o.shadow&&!$.browser.msie){$('img:first',oimgzoombox).shadow(o.shadowopts)}if(o.speed>0&&!$.browser.msie){o.oimgclose.fadein('slow');$('div',oimgzoombox).fadein('slow')}else{o.oimgclose.show();$('div',oimgzoombox).show()}};$('div',oimgzoombox).hide();if(o.imgsrc.is('img')){o.imgsrc.css({'opacity':0})}var oimgdisplay=$('img:first',oimgzoombox).css({'width':'100%','height':'auto'});if(o.speed>0){oimgzoombox.css(o.dimori).animate(dimboxtarget,o.speed,$fctend)}else{oimgzoombox.css(dimboxtarget);$fctend()}}function closezoombox(o){var oimgzoombox=o.oimgzoombox;o.oimgclose.remove();$('div',oimgzoombox).remove();var endclose=function(){oimgzoombox.empty().remove();o.imgsrc.css('opacity',1)};if(o.speed>0){var pos=oimgzoombox.offset();var ipercent=0.15;var odimplus={width:(oimgzoombox.width()*(1+ipercent)),height:(oimgzoombox.height()*(1+ipercent)),left:(pos.left-(oimgzoombox.width()*(ipercent/2))),top:(pos.top-(oimgzoombox.height()*(ipercent/2)))};oimgzoombox.animate(odimplus,o.speed*0.2,function(){oimgzoombox.animate(o.dimori,o.speed,function(){endclose()});if(o.showoverlay){ooverlay.animate({'opacity':0},o.speed,function(){$(this).remove()})}})}else{endclose();if(o.showoverlay){ooverlay.remove()}}}return this.each(function(){var $this=$(this);var imgtarget=$this.is('img')?$this:($('img:first',$this).length==0)?$this:$('img:first',$this);var imgtargetsrc=null;if($this.attr('href')){imgtargetsrc=$this.attr('href')}var oimgclose=$('').css({position:'absolute',top:0,left:0,cursor:'pointer'});var opts=$.extend({},$.fn.fancyzoom.defaultsoptions,useroptions||{},{dimori:{},oimgzoomboxprop:{position:'absolute',left:0,top:0},oimgclose:oimgclose});if(imgtarget.is('img')){var oimghover=$("").css({position:'absolute',top:0,left:0});imgtarget.hover(function(){if(imgtarget.css('opacity')!=0){oimghover.appendto(imgtarget.parent()).hide();var pos=imgtarget.position();var marginleft=parseint(imgtarget.css('margin-left').replace(/px/,''));var margintop=parseint(imgtarget.css('margin-top').replace(/px/,''));margintop=(margintop)?margintop:0;marginleft=(marginleft)?marginleft:0;oimghover.css({left:(pos.left+marginleft-12),top:(pos.top+margintop-12)}).show();if($.fn.ifixpng){oimghover.ifixpng(opts.imgdir+'blank.gif')}}},function(){oimghover.remove()})}if($this.is('img')){imgtargetsrc=$this.css('cursor','pointer').attr('src');if(opts.imgresizescript){if(imgtargetsrc.match(new regexp("^"+opts.imgresizescript,"g"))){imgtargetsrc=imgtargetsrc.replace(/.*img=([^&]*).*/gi,'$1')}}}ooverlay.css({opacity:opts.overlay,background:opts.overlaycolor});if(!/\.jpg|\.jpeg|\.png|\.gif/i.test(imgtargetsrc)){return true}$this.click(function(){var zoomopened=$('div.jqfancyzoombox');if(zoomopened.length>0){if($('img:first',zoomopened).attr('src')!=imgtargetsrc){if(oloading&&oloading.is(':visible')){__cancelloading()}}else{return false}}var o=$.extend({},opts,useroptions);var closebtn=$("img.jqfancyzoomclosebox");if(closebtn.length>0){var imcurrent=$('img:first',zoomopened);if(imgtargetsrc==imcurrent.attr('src')){pos=imgtarget.offset();o=$.extend(o,{dimori:{width:(imgtarget.outerwidth()),height:(imgtarget.outerheight()),left:pos.left,top:(pos.top),'opacity':0}});closezoombox(o);return false}else{closebtn.trigger('click')}}if(o.showoverlay&&ooverlay){ooverlay.empty().remove().css({'opacity':o.overlay})}oimgclose.attr('src','images/'+o.imgdir+'closebox.png').appendto('body').hide();if($.fn.ifixpng){$.ifixpng(o.imgdir+'blank.gif');oimgclose.ifixpng(o.imgdir+'blank.gif')}oimgclose.unbind('click').click(function(){closezoombox(o)});var oimgzoombox=$('
').css(o.oimgzoomboxprop);o=$.extend(o,{oimgzoombox:oimgzoombox});var strtitle=imgtarget.attr('alt');if(strtitle){var otitle=$('
'+strtitle+'
').css({margintop:10,marginright:15});var tdl=otitle.find('td:first').css({'background':'url('+o.imgdir+'zoom-caption-l.png)',width:'13px',height:'26px'});var tdr=otitle.find('td:last').css({'background':'url('+o.imgdir+'zoom-caption-r.png)',width:'13px',height:'26px'});var tdc=$('.fancytitle',otitle).css({'background':'url('+o.imgdir+'zoom-caption-fill.png)','padding':'0px 20px',color:'#fff','font-size':'14px'});if($.fn.ifixpng){tdl.ifixpng(o.imgdir+'blank.gif');tdr.ifixpng(o.imgdir+'blank.gif');tdc.ifixpng(o.imgdir+'blank.gif')}otitle.appendto(oimgzoombox)}var oimgzoom=$('').attr('src',imgtargetsrc).click(function(){closezoombox(o)}).prependto(oimgzoombox);var imagezindex=opts.imagezindex;ooverlay.css('zindex',imagezindex-1);oimgzoombox.css('zindex',imagezindex);oimgclose.css('zindex',(imagezindex+10));var imgpreload=new image();imgpreload.src=imgtargetsrc;var $fctendloading=function(){if(bcancelloading){bcancelloading=false}else{if(__getfilename(imgpreload.src)==__getfilename($('img:first',oimgzoombox).attr('src'))){fctcalculateimagesize(o.autoresize);openzoombox(imgtarget,o);__stoploading()}}};var fctcalculateimagesize=function(autoresize){if(autoresize){var divcalculate=$('
').css({position:'absolute','top':0,'left':0,opacity:0,'border':'0px solid red'});var bresize=false;oimgzoom.appendto(divcalculate);divcalculate.appendto('body');imwidth=oimgzoom.width();imheight=oimgzoom.height();maxwidth=$(window).width()*0.9;maxheight=$(window).height()-100;if(maxheighttabsizes[i]){finalwidth=tabsizes[i];break}}oimgzoom.width(finalwidth);oimgzoom.height(parseint(theight*finalwidth/twidth));var args="img="+encodeuri(oimgzoom.attr('src'));args+="&width="+oimgzoom.width();args+="&height="+oimgzoom.height();oimgzoom.attr('src',o.imgresizescript+"?"+args)}divcalculate.remove()}oimgzoom.prependto(oimgzoombox)};if(imgpreload.complete){fctcalculateimagesize(o.autoresize);openzoombox(imgtarget,o)}else{__displayloading(o);imgpreload.onload=function(){$fctendloading()}}return false})})};$.fn.fancyzoom.defaultsoptions={overlaycolor:'#000',overlay:0.6,imagezindex:100,showoverlay:true,speed:400,shadow:true,shadowopts:{color:"#000",offset:4,opacity:0.2},imgdir:'ressources/',imgresizescript:null,autoresize:true};function __poscenter(iwidth,iheight){var ileft=($(window).width()-iwidth)/2+$(window).scrollleft();var itop=($(window).height()-iheight)/2+$(window).scrolltop();ileft=(ileft<0)?0:ileft;itop=(itop<0)?0:itop;return{left:ileft,top:itop}}var oloading=null;var bcancelloading=false;var timerloadingimg=null;function __displayloading(o){if(!oloading){oloading=$('
').css({width:50,height:50,position:'absolute','background':'transparent',opacity:8/10,color:'#fff',padding:'5px','font-size':'10px'})}oloading.css(__poscenter(50,50)).html('').click(function(){__cancelloading()}).appendto('body').show();timerloadingimg=settimeout(function(){__changeimageloading(o)},400)}function __cancelloading(){bcancelloading=true;__stoploading()}function __stoploading(){oloading.hide().remove();if(timerloadingimg){cleartimeout(timerloadingimg);timerloadingimg=null}}function __changeimageloading(o){if(oloading&&!oloading.is(':visible')){timerloadingimg=null;return}var $im=$('img',oloading);if(!$im.attr('src')||/blank\.gif/.test($im.attr('src'))){strimgsrc=o.imgdir+"zoom-spin-1.png"}else{tab=$im.attr('src').split(/[- .]+/);iimg=parseint(tab[2]);iimg=(iimg<12)?(iimg+1):1;strimgsrc=tab[0]+"-"+tab[1]+"-"+iimg+"."+tab[3]}var pload=new image();pload.src=strimgsrc;var $fct=function(){oloading&&oloading.css(__poscenter(50,50));$im.attr('src',strimgsrc);timerloadingimg=settimeout(__changeimageloading,100)};if(pload.complete){$fct()}else{pload.onload=$fct}}function __getfilename(strpath){if(!strpath){return false}var tabpath=strpath.split('/');return((tabpath.length<1)?strpath:tabpath[(tabpath.length-1)])}})(jquery);