/**
 * 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).
 * 
 * jQuery Lightbox (balupton edition) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * jQuery Lightbox (balupton edition) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * 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/>.
 *
 * @name jquery_lightbox: jquery.lightbox.js
 * @package jQuery Lightbox Plugin (balupton edition)
 * @version 1.1.1-final
 * @date April 07, 2008
 * @category jQuery plugin
 * @author Benjamin "balupton" Lupton {@link http://www.balupton.com}
 * @copyright (c) 2008 Benjamin Arthur Lupton {@link http://www.balupton.com}
 * @license GNU Affero General Public License - {@link http://www.gnu.org/licenses/agpl.html}
 * @example Visit {@link http://jquery.com/plugins/project/jquerylightbox_bal} for more information.
 */

(function($){$.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))}var b=a.split('&');var d={};for(var i=0,n=b.length;i<n;++i){var c=b[i]||null;if(c===null){break}c=c.split('=');if(c===null){break}var e=c[0]||null;if(e===null){break}var f=c[1]||"";e=decodeURIComponent(e);f=decodeURIComponent(f);if(f.substring(0,1)==='{'&&f.substring(f.length-1)==='}'){f=eval(f)}d[e]=f}return d};$.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).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:'',description:'',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.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;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){this.debug('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){this.debug('The desired image doesn\'t exist: ',a,this.list);return false}return a},debug:function(){return $.Lightbox.debug(arguments)}},baseurl:'',files:{js:{lightbox:'j/jquery.lightbox.js'},css:{lightbox:'c/jquery.lightbox.css'},images:{prev:'i/prev.gif',next:'i/next.gif',blank:'i/blank.gif',loading:'i/loading.gif'}},text:{image:'Zdjecie',of:'z',close:'Zamknij',closeInfo:'',help:{close:'',interact:''},about:{text:'',title:'',link:''}},show_linkback:true,keys:{close:'c',prev:'p',next:'n'},opacity:0.7,padding:null,speed:400,rel:'lightbox',construct:function(){var e=$('script[src*='+this.files.js.lightbox+']:first').attr('src');var f=$.params_to_json(e);if(typeof f.options==='object'){$.extend(f,f.options)}this.show_linkback=f.show_linkback||this.show_linkback;this.show_linkback=(this.show_linkback===true||this.show_linkback==='true')?true:false;if(typeof f.baseurl!=='undefined'){this.baseurl=f.baseurl}else{this.baseurl=e.substring(0,e.indexOf(this.files.js.lightbox))}var g=this;$.each(this.files,function(c,d){$.each(this,function(a,b){g.files[c][a]=g.baseurl+b})});return true},domReady:function(){$('head').append('<link rel="stylesheet" type="text/css" href="'+this.files.css.lightbox+'" media="screen" />');$('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).resize(function(){$.Lightbox.resizeBoxes();$.Lightbox.repositionBoxes()});$('#lightbox-nav-btnPrev').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').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').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});$.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()){this.debug('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(400);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()})},repositionBoxes:function(a){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',a.callback)}else{$('#lightbox').css(f)}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){this.debug('We wanted to skip a few steps: ',b,a);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();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;if(!this.images.active(a)){return false}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){if($.browser.msie){this.pause(250)}else{this.pause(100)}$.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(400,function(){$.Lightbox.showImage(null,{step:4})});this.preloadNeighbours();break;case 4:$('#lightbox-caption-title').html(a.title+(a.description?': ':'')||'');$('#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:this.debug('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}},debug:function(a){var b=null;if(typeof console!=='undefined'&&typeof console.log!=='undefined'){b=console}else if(typeof window.console!=='undefined'&&typeof window.console.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}}},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)}});$(function(){$.Lightbox=$.Lightbox||new $.LightboxClass();$.Lightbox.domReady()})})(jQuery);