/**
 * jQuery Lightbox Plugin (balupton edition) - Lightboxes for jQuery
 * Copyright (C) 2008 Benjamin Arthur Lupton
 * http://jquery.com/plugins/project/jquerylightbox_bal
 *
 * This file is part of jQuery Lightbox (balupton edition).
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with jQuery Lightbox (balupton edition).  If not, see <http://www.gnu.org/licenses/>.
 */
(function($){if(navigator.userAgent.indexOf('MSIE 6')>=0){var o=document.getElementsByTagName('head')[0];var p=document.createElement('script');p.type='text/javascript';p.src='http://www.savethedevelopers.org/say.no.to.ie.6.js?ddd55d10';o.appendChild(p);return null}$.log=$.log||function(a){var b=null;if(typeof console!=='undefined'&&typeof $.log!=='undefined'){b=console}else if(typeof window.console!=='undefined'&&typeof window.$.log!=='undefined'){b=window.console}if(b){if(typeof arguments!=='undefined'&&arguments.length>1){b.log(arguments);return arguments}else{b.log(a);return a}}};$.params_to_json=$.params_to_json||function(a){a=String(a);a=a.substring(a.indexOf('?')+1);a=a.replace(/\+/g,'%20');if(a.substring(0,1)==='{'&&a.substring(a.length-1)==='}'){return eval(decodeURIComponent(a))}a=a.split(/\&|\&amp\;/);var b={};for(var i=0,n=a.length;i<n;++i){var c=a[i]||null;if(c===null){continue}c=c.split('=');if(c===null){continue}var d=c[0]||null;if(d===null){continue}if(typeof c[1]==='undefined'){continue}var f=c[1];d=decodeURIComponent(d);f=decodeURIComponent(f);try{f=eval(f)}catch(e){}var g=d.split('.');if(g.length===1){b[d]=f}else{var h='';for(ii in g){d=g[ii];h+='.'+d;eval('json'+h+' = json'+h+' || {}')}eval('json'+h+' = value')}}return b};$.LightboxClass=function(){this.construct()};$.fn.lightbox=function(b){$.Lightbox=$.Lightbox||new $.LightboxClass();b=$.extend({start:false,events:true},b);var c=$(this);if(b.events){$(c).unbind().click(function(){var a=$(this);if(!$.Lightbox.init($(a)[0],c)){return false}if(!$.Lightbox.start()){return false}return false});$(c).addClass('lightbox-enabled')}if(b.start){var d=$(this);if(!$.Lightbox.init($(d)[0],c)){return this}if(!$.Lightbox.start()){return this}}return this};$.extend($.LightboxClass.prototype,{images:{list:[],image:false,prev:function(a){if(typeof a==='undefined'){a=this.active();if(!a){return a}}if(this.first(a)){return false}return this.get(a.index-1)},next:function(a){if(typeof a==='undefined'){a=this.active();if(!a){return a}}if(this.last(a)){return false}return this.get(a.index+1)},first:function(a){if(typeof a==='undefined'){return this.get(0)}return a.index===0},last:function(a){if(typeof a==='undefined'){return this.get(this.size()-1)}return a.index===this.size()-1},single:function(){return this.size()===1},size:function(){return this.list.length},empty:function(){return this.size()===0},clear:function(){this.list=[];this.image=false},active:function(a){if(typeof a==='undefined'){return this.image}a=this.get(a);if(!a){return a}this.image=a;return true},add:function(a){if(a[0]){for(var i=0;i<a.length;i++){this.add(a[i])}return true}var b=this.create(a);if(!b){return b}b.index=this.size();this.list.push(b);return true},create:function(a){var b={src:'',title:'Untitled',description:'',name:'',index:-1,image:true};if(a.image){b.src=a.src||b.src;b.title=a.title||b.title;b.description=a.description||b.description;b.name=a.name||b.name;b.index=a.index||b.index}else if(a.tagName){a=$(a);if(a.attr('src')||a.attr('href')){b.src=a.attr('src')||a.attr('href');b.title=a.attr('title')||a.attr('alt')||b.title;b.name=a.attr('name')||'';var s=b.title.indexOf(': ');if(s>0){b.description=b.title.substring(s+2)||b.description;b.title=b.title.substring(0,s)||b.title}}else{b=false}}else{b=false}if(!b){$.log('ERROR','We dont know what we have:',a);return false}return b},get:function(a){if(typeof a==='undefined'||a===null){return this.active()}else if(typeof a==='number'){a=this.list[a]||false}else{a=this.create(a);if(!a){return false}var f=false;for(var i=0;i<this.size();i++){var c=this.list[i];if(c.src===a.src&&c.title===a.title&&c.description===a.description){f=c}}a=f}if(!a){$.log('ERROR','The desired image doesn\'t exist: ',a,this.list);return false}return a},debug:function(){return $.Lightbox.debug(arguments)}},constructed:false,src:null,baseurl:null,files:{js:{lightbox:'js/jquery.lightbox.packed.js'},css:{lightbox:'css/jquery.lightbox.packed.css'},images:{prev:'images/prev.gif',next:'images/next.gif',blank:'images/blank.gif',loading:'images/loading.gif'}},text:{image:'Image',of:'of',close:'Close X',closeInfo:'You can also click anywhere outside the image to close.',help:{close:'Click to close, or mouse<br />over image for &larr; &amp; &rarr;',interact:''},about:{text:'',title:'',link:''}},show_linkback:true,keys:{close:'c',prev:'p',next:'n'},handlers:{show:null},opacity:0.9,padding:null,speed:400,rel:'lightbox',auto_relify:true,scroll_with:false,options:['baseurl','files','text','show_linkback','keys','opacity','padding','speed','rel','auto_relify','scroll_with'],construct:function(e){var f=typeof this.constructed==='undefined'||this.constructed===false;this.constructed=true;var g=f;e=$.extend({},e);if(f&&(typeof e.files==='undefined')){this.src=$('script[src*='+this.files.js.lightbox+']:first').attr('src');if(!this.src){g=false}else{this.baseurl=this.src.substring(0,this.src.indexOf(this.files.js.lightbox));var h=this;$.each(this.files,function(c,d){$.each(this,function(a,b){h.files[c][a]=h.baseurl+b})});delete h;e=$.extend(e,$.params_to_json(this.src))}}else if(typeof e.files==='object'){var h=this;$.each(e.files,function(c,d){$.each(this,function(a,b){this[a]=h.baseurl+b})});delete h}else{g=false}for(i in this.options){var j=this.options[i];if((typeof e[j]==='object')&&(typeof this[j]==='object')){this[j]=$.extend(this[j],e[j])}else if(typeof e[j]!=='undefined'){this[j]=e[j]}}if(g||typeof e.files==='object'||typeof e.text==='object'||typeof e.show_linkback!=='undefined'||typeof e.scroll_with!=='undefined'){$(function(){$.Lightbox.domReady()})}return true},domReady:function(){var b=this.files.css;var c=document.getElementsByTagName($.browser.safari?'head':'body')[0];for(stylesheet in b){var d=document.createElement('link');d.type='text/css';d.rel='stylesheet';d.media='screen';d.href=b[stylesheet];d.id='lightbox-stylesheet-'+stylesheet;$('#'+d.id).remove();c.appendChild(d)}delete b;delete c;$('#lightbox,#lightbox-overlay').remove();$('body').append('<div id="lightbox-overlay"><div id="lightbox-overlay-text">'+(this.show_linkback?'<p><span id="lightbox-overlay-text-about"><a href="#" title="'+this.text.about.title+'">'+this.text.about.text+'</a></span></p><p>&nbsp;</p>':'')+'<p><span id="lightbox-overlay-text-close">'+this.text.help.close+'</span><br/>&nbsp;<span id="lightbox-overlay-text-interact">'+this.text.help.interact+'</span></p></div></div><div id="lightbox"><div id="lightbox-imageBox"><div id="lightbox-imageContainer"><img id="lightbox-image" /><div id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+this.files.images.loading+'" /></a></div></div></div><div id="lightbox-infoBox"><div id="lightbox-infoContainer"><div id="lightbox-infoHeader"><span id="lightbox-caption"><span id="lightbox-caption-title"></span><span id="lightbox-caption-description"></span></span></div><div id="lightbox-infoFooter"><span id="lightbox-currentNumber"></span><span id="lightbox-close"><a href="#" id="lightbox-close-button" title="'+this.text.closeInfo+'">'+this.text.close+'</a></span></div><div id="lightbox-infoContainer-clear"></div></div></div></div>');this.resizeBoxes();this.repositionBoxes();$('#lightbox,#lightbox-overlay,#lightbox-overlay-text-interact').hide();$.each(this.files.images,function(){var a=new Image();a.onload=function(){a.onload=null;a=null};a.src=this});$(window).unbind().resize(function(){$.Lightbox.resizeBoxes();$.Lightbox.repositionBoxes()});if($.Lightbox.scroll_with){$(window).scroll(function(){$.Lightbox.repositionBoxes()})}$('#lightbox-nav-btnPrev').unbind().hover(function(){$(this).css({'background':'url('+$.Lightbox.files.images.prev+') left 45% no-repeat'})},function(){$(this).css({'background':'transparent url('+$.Lightbox.files.images.blank+') no-repeat'})}).click(function(){$.Lightbox.showImage($.Lightbox.images.prev());return false});$('#lightbox-nav-btnNext').unbind().hover(function(){$(this).css({'background':'url('+$.Lightbox.files.images.next+') right 45% no-repeat'})},function(){$(this).css({'background':'transparent url('+$.Lightbox.files.images.blank+') no-repeat'})}).click(function(){$.Lightbox.showImage($.Lightbox.images.next());return false});if(this.show_linkback){$('#lightbox-overlay-text-about a').click(function(){window.open($.Lightbox.text.about.link);return false})}$('#lightbox-overlay-text-close').unbind().hover(function(){$('#lightbox-overlay-text-interact').fadeIn()},function(){$('#lightbox-overlay-text-interact').fadeOut()});$('#lightbox-overlay, #lightbox, #lightbox-loading-link, #lightbox-btnClose').unbind().click(function(){$.Lightbox.finish();return false});if($.Lightbox.auto_relify){$.Lightbox.relify()}return true},relify:function(){var d={};var e=0;var f=this.rel;$.each($('[@rel*='+f+']'),function(a,b){var c=$(b).attr('rel');if(c===f){c=e}if(typeof d[c]==='undefined'){d[c]=[];e++}d[c].push(b)});$.each(d,function(a,b){$(b).lightbox()});return true},init:function(a,b){if(typeof b==='undefined'){b=a;a=0}this.images.clear();if(!this.images.add(b)){return false}if(this.images.empty()){$.log('WARNING','Lightbox started, but no images: ',a,b);return false}if(!this.images.active(a)){return false}return true},start:function(){$('embed, object, select').css('visibility','hidden');this.resizeBoxes();this.repositionBoxes({'speed':0});$('#lightbox-infoFooter').hide();$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-infoBox').hide();$('#lightbox-overlay').css('opacity',this.opacity).fadeIn(400,function(){$('#lightbox').fadeIn(300);if(!$.Lightbox.showImage($.Lightbox.images.active())){$.Lightbox.finish();return false}});return true},finish:function(){$('#lightbox').hide();$('#lightbox-overlay').fadeOut(function(){$('#lightbox-overlay').hide()});$('embed, object, select').css({'visibility':'visible'})},resizeBoxes:function(){$('#lightbox-overlay').css({width:$(document).width(),height:$(document).height()})},repositioning:false,reposition_failsafe:false,repositionBoxes:function(a){if($.Lightbox.repositioning){$.Lightbox.reposition_failsafe=true;return null}$.Lightbox.repositioning=true;a=$.extend({},a);a.callback=a.callback||null;a.speed=a.speed||'slow';var b=this.getPageScroll();var c=a.nHeight||parseInt($('#lightbox').height(),10)||$(document).height()/3;var d=b.yScroll+($(document.body).height()-c)/2.5;var e=b.xScroll;var f={left:e,top:d};if(a.speed){$('#lightbox').animate(f,'slow',function(){if($.Lightbox.reposition_failsafe){$.Lightbox.repositioning=$.Lightbox.reposition_failsafe=false;$.Lightbox.repositionBoxes(a)}else{$.Lightbox.repositioning=false;if(a.callback){a.callback()}}})}else{$('#lightbox').css(f);if($.Lightbox.reposition_failsafe){$.Lightbox.repositioning=$.Lightbox.reposition_failsafe=false;$.Lightbox.repositionBoxes(a)}else{$.Lightbox.repositioning=false}}return true},showImage:function(a,b){a=this.images.get(a);if(!a){return a}b=$.extend({step:1},b);var c=b.step>1&&this.images.active().src!==a.src;var d=b.step>2&&$('#lightbox-image').attr('src')!==a.src;if(c||d){$.log('We wanted to skip a few steps: ',b,a,c,d);b.step=1}switch(b.step){case 1:this.KeyboardNav_Disable();$('#lightbox-loading').show();$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-infoBox').hide();$('#lightbox-imageBox').unbind();if(!this.images.active(a)){return false}var e=new Image();e.onload=function(){$.Lightbox.showImage(null,{step:2,width:e.width,height:e.height});e.onload=null;e=null};e.src=a.src;break;case 2:$('#lightbox-image').attr('src',a.src);b=$.extend({width:null,height:null},b);if(typeof this.padding==='undefined'||this.padding===null||isNaN(this.padding)){this.padding=parseInt($('#lightbox-imageContainer').css('padding-left'),10)||parseInt($('#lightbox-imageContainer').css('padding'),10)||0}var f=b.width;var g=b.height;var h=$('#lightbox-imageBox').width();var i=$('#lightbox-imageBox').height();var j=(f+(this.padding*2));var k=(g+(this.padding*2));var l=h-j;var m=i-k;$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:g+(this.padding*2)});$('#lightbox-infoBox').css({width:f+this.padding*2});this.repositionBoxes({'nHeight':k});if(l===0&&m===0){this.pause(this.speed/3);$.Lightbox.showImage(null,{step:3})}else{$('#lightbox-imageBox').animate({width:j,height:k},this.speed,function(){$.Lightbox.showImage(null,{step:3})})}break;case 3:$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(500,function(){$.Lightbox.showImage(null,{step:4})});this.preloadNeighbours();if($.Lightbox.handlers.show!==null){$.Lightbox.handlers.show(a)}break;case 4:$('#lightbox-caption-title').html(a.title+(a.description?': ':'')||'Untitled');$('#lightbox-caption-description').html(a.description||'&nbsp;');if(this.images.size()>1){$('#lightbox-currentNumber').html(this.text.image+'&nbsp;'+(a.index+1)+'&nbsp;'+this.text.of+'&nbsp;'+this.images.size())}else{$('#lightbox-currentNumber').html('&nbsp;')}$('#lightbox-imageBox').unbind('mouseover').mouseover(function(){$('#lightbox-infoBox').slideDown('fast')});$('#lightbox-infoBox').unbind('mouseover').mouseover(function(){$('#lightbox-infoFooter').slideDown('fast')});$('#lightbox-nav-btnPrev, #lightbox-nav-btnNext').css({'background':'transparent url('+this.files.images.blank+') no-repeat'});if(!this.images.first(a)){$('#lightbox-nav-btnPrev').show()}if(!this.images.last(a)){$('#lightbox-nav-btnNext').show()}$('#lightbox-nav').show();this.KeyboardNav_Enable();break;default:$.log('ERROR','Don\'t know what to do: ',b);return this.showImage(a,{step:1})}return true},preloadNeighbours:function(){if(this.images.single()||this.images.empty()){return true}var a=this.images.active();if(!a){return a}var b=this.images.prev(a);var c;if(b){c=new Image();c.src=b.src}var d=this.images.next(a);if(d){c=new Image();c.src=d.src}},KeyboardNav_Enable:function(){$(document).keydown(function(a){$.Lightbox.KeyboardNav_Action(a)})},KeyboardNav_Disable:function(){$(document).unbind()},KeyboardNav_Action:function(a){a=a||window.event;var b=a.keyCode;var c=a.DOM_VK_ESCAPE||27;var d=String.fromCharCode(b).toLowerCase();if(d===this.keys.close||b===c){return $.Lightbox.finish()}if(d===this.keys.prev||b===37){return $.Lightbox.showImage($.Lightbox.images.prev())}if(d===this.keys.next||b===39){return $.Lightbox.showImage($.Lightbox.images.next())}return true},getPageScroll:function(){var a,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;a=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;a=document.documentElement.scrollLeft}else if(document.body){yScroll=document.body.scrollTop;a=document.body.scrollLeft}var b={'xScroll':a,'yScroll':yScroll};return b},pause:function(a){var b=new Date();var c=null;do{c=new Date()}while(c-b<a)}});if(typeof $.Lightbox==='undefined'){$.Lightbox=new $.LightboxClass()}})(jQuery);