/**
* jQuery fancyzoom plugin.
* This is an adaptation of the fancyzoom effect as a jQuery plugin
*
* Author: Mathieu Vilaplana <mvilaplana@df-e.com>
* Date: March 2008
* rev 1.0
* rev: 1.1
* Add title if alt in the img
*/
(function($){var s='ressources/';var t=$('<div>');var u=$('<img>').css({position:'absolute',top:0,left:0,cursor:'pointer',zIndex:102});$.fn.fancyzoom=function(q){var r=$('<div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,cursor:"wait"});function openZoomBox(a,o){if(o.showoverlay){r.appendTo('body').click(function(){closeZoomBox(o)})}pos=a.offset();o=$.extend(o,{dimOri:{width:a.outerWidth(),height:a.outerHeight(),left:pos.left,top:pos.top,'opacity':0}});var b=$('img',t);t.css({'opacity':0,'text-align':'center','border':'0px solid red'}).appendTo('body');var c=t.outerWidth();var d=t.outerHeight();dimBoxTarget=$.extend({},{width:c,height:d,'opacity':1},__posCenter((c+15),(d+30)));u.css({left:(dimBoxTarget.left+dimBoxTarget.width-22-(dimBoxTarget.width-b.width())/2),top:dimBoxTarget.top});var e=function(){if($.fn.shadow&&!$.browser.msie){$('img:first',t).shadow(o.shadowOpts)}if(o.Speed>0&&!$.browser.msie){u.fadeIn('slow');$('div',t).fadeIn('slow')}else{u.show();$('div',t).show()}};$('div',t).hide();if(o.Speed>0){t.css(o.dimOri).animate(dimBoxTarget,o.Speed,e)}else{t.css(dimBoxTarget);e()}}function closeZoomBox(o){u.remove();if(o.Speed>0){t.animate(o.dimOri,o.Speed,function(){$(this).empty().remove()});if(o.showoverlay){r.animate({'opacity':0},o.Speed,function(){$(this).empty().remove()})}}else{t.empty().remove();if(o.showoverlay){r.empty().remove()}}}return this.each(function(){var l=$(this);var m=l.is('img')?l:$('img:first',l);var n=null;if(l.attr('href')){n=l.attr('href')}if(l.is('img')){n=l.attr('src');l.css('cursor','pointer')}var p=$.extend({},$.fn.fancyzoom.defaultsOptions,q||{},{dimOri:{},oImgZoomBoxProp:{position:'absolute',left:0,top:0}});r.css({opacity:p.overlay,background:p.overlayColor});if(!/\.jpg|\.png|\.gif/i.test(n)||($('img',l).size()===0&&!l.is('img'))){return}l.click(function(){if(v&&v.is(':visible')||x){if(t&&$('img:first',t).attr('src')!=n){__cancelLoading()}else{return false}}var o=$.extend({},p,q);if(t&&t.parent().size()>0){var b=$('img:first',t);if(n==b.attr('src')){pos=m.offset();o=$.extend(o,{dimOri:{width:m.outerWidth(),height:m.outerHeight(),left:pos.left,top:pos.top,'opacity':0}});closeZoomBox(o);return false}else{u.remove();t.empty().remove()}}if(o.showoverlay&&r){r.empty().remove().css({'opacity':o.overlay})}u.attr('src',o.imgDir+'../images/gallery/closebox.png').appendTo('body').hide();if($.fn.ifixpng){$.ifixpng(o.imgDir+'../images/gallery/blank.gif');u.ifixpng(o.imgDir+'../images/gallery/blank.gif')}u.unbind('click').click(function(){closeZoomBox(o)});t=$('<div>').empty().css(o.oImgZoomBoxProp);var c=m.attr('alt');if(c){var d=$('<div><center><table height=0 border="0" cellspacing=0 cellpadding=0><tr><td></td><td class="fancyTitle">'+c+'</td><td></td></table></center></div>').css({marginTop:10,marginRight:15});var e=d.find('td:first').css({'background':'url('+o.imgDir+'../images/gallery/zoom-caption-l.png)',width:'13px',height:'26px'});var f=d.find('td:last').css({'background':'url('+o.imgDir+'../images/gallery/zoom-caption-r.png)',width:'13px',height:'26px'});var g=$('.fancyTitle',d).css({'background':'url('+o.imgDir+'../images/gallery/zoom-caption-fill.png)','padding':'0px 20px',color:'#FFF','font-size':'14px'});if($.fn.ifixpng){e.ifixpng(o.imgDir+'../images/gallery/blank.gif');f.ifixpng(o.imgDir+'../images/gallery/blank.gif');g.ifixpng(o.imgDir+'../images/gallery/blank.gif')}d.appendTo(t)}var h=$('<img />').attr('src',n).css({zIndex:100,marginTop:15,marginRight:15}).click(function(){closeZoomBox(o)}).prependTo(t);var i=new Image();i.src=n;var j=function(){if(w){w=false}else{if(__getFileName(i.src)==__getFileName($('img:first',t).attr('src'))){k();openZoomBox(m,o);__stoploading()}}};var k=function(){var a=$('<div></div>').css({position:'absolute','top':0,'left':0,opacity:0,'border':'0px solid red'});h.appendTo(a);a.appendTo('body');imWidth=h.width();imHeight=h.height();maxWidth=$(window).width()*0.9;maxHeight=$(window).height()*0.8;if(maxHeight<imHeight){h.css('height',maxHeight)}else if(maxWidth<imWidth){h.css('width',maxWidth)}a.remove();h.prependTo(t)};if(i.complete){k();openZoomBox(m,o)}else{__displayLoading();i.onload=function(){j()}}return false})})};$.fn.fancyzoom.defaultsOptions={overlayColor:'#000',overlay:0.6,showoverlay:false,Speed:400,shadowOpts:{color:"#000",offset:4,opacity:0.2},imgDir:s};function __posCenter(a,b){var c=($(window).width()-a)/2+$(window).scrollLeft();var d=($(window).height()-b)/2+$(window).scrollTop();c=(c<0)?0:c;d=(d<0)?0:d;return{left:c,top:d}}var v=null;var w=false;var x=null;function __displayLoading(){if(!v){v=$('<div></div>').css({width:50,height:50,position:'absolute','background':'transparent',opacity:8/10,color:'#FFF',padding:'5px','font-size':'10px'})}v.css(__posCenter(50,50)).html('<img src="../jquery2/'+$.fn.fancyzoom.defaultsOptions.imgDir+'../images/gallery/blank.gif" />').click(function(){__cancelLoading()}).appendTo('body').show();x=setTimeout(__changeimageLoading,400)}function __cancelLoading(){w=true;__stoploading()}function __stoploading(){v.hide().remove();if(x){clearTimeout(x);x=null}}function __changeimageLoading(){if(!v.is(':visible')){x=null;return}var a=$('img',v);if(!a.attr('src')||/blank\.gif/.test(a.attr('src'))){strImgSrc=$.fn.fancyzoom.defaultsOptions.imgDir+"../images/gallery/zoom-spin-1.png"}else{tab=a.attr('src').split(/[- .]+/);iImg=parseInt(tab[2]);iImg=(iImg<12)?(iImg+1):1;strImgSrc=tab[0]+"-"+tab[1]+"-"+iImg+"."+tab[3]}var b=new Image();b.src=strImgSrc;var c=function(){v.css(__posCenter(50,50));a.attr('src',strImgSrc);x=setTimeout(__changeimageLoading,100)};if(b.complete){c()}else{b.onload=c}}function __getFileName(a){if(!a){return false}var b=a.split('/');return((b.length<1)?a:b[(b.length-1)])}})(jQuery);
