/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.js
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @version 0.5.1
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CCAttribution-ShareAlike 2.5 Brazil - http://creativecommons.org/licenses/by-sa/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 *
 * @updates by Ivaylo Stamatov aka avioli @ FULLER http://fuller.com.au/
 * @date 2011-08-04
 */
var lightbox_path=lightbox_path||"";
(function(b){b.fn.lightBox=function(a){function p(c,d){b("embed, object, select").css({visibility:"hidden"});q();a.imageArray.length=0;a.activeImage=0;var e=false,h;if(a.grouping)if(h=c.getAttribute("rel")){e=d;d=[];e.each(function(j,n){h==n.getAttribute("rel")&&d.push(n)})}if(d.length==1){var g=a.captionPosition=="gallery"?jQuery(c).parent().next().html():c.getAttribute("title");a.imageArray.push([c.getAttribute("href"),g])}else for(var f=0;f<d.length;f++)if(a.captionPosition!="gallery"){g=d[f].getAttribute("title");
a.imageArray.push([d[f].getAttribute("href"),g])}else if(f>1){if(!(d[f-1].getAttribute("href")!=d[f].getAttribute("href")&&jQuery(d[f-1]).parent().parent().children().children().attr("href")==jQuery(d[f]).parent().parent().children().children().attr("href"))){g=jQuery(d[f]).parent().next().html();a.imageArray.push([jQuery(d[f]).parent().parent().children().children().attr("href"),g])}}else{g=jQuery(d[f]).parent().next().html();a.imageArray.push([jQuery(d[f]).parent().parent().children().children().attr("href"),
g])}for(;a.imageArray[a.activeImage][0]!=c.getAttribute("href");)a.activeImage++;if(a.grouping&&e){d=e;e=false}i()}function q(){b("body").append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" 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="'+
a.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+a.imageBtnClose+'"></a></div></div></div></div>');var c=k();b("#jquery-overlay").css({backgroundColor:a.overlayBgColor,opacity:a.overlayOpacity,width:c[0],
height:c[1]}).fadeIn();var d=l();b("#jquery-lightbox").css({top:d[1]+c[3]/10,left:d[0]}).show();b("#jquery-overlay,#jquery-lightbox").click(function(){m()});b("#lightbox-loading-link,#lightbox-secNav-btnClose").click(function(){m();return false});b(window).resize(function(){var e=k();b("#jquery-overlay").css({width:e[0],height:e[1]});var h=l();b("#jquery-lightbox").css({top:h[1]+e[3]/10,left:h[0]})})}function i(){b("#lightbox-loading").show();a.fixedNavigation?b("#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber").hide():
b("#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber").hide();var c=new Image;c.onload=function(){b("#lightbox-image").attr("src",a.imageArray[a.activeImage][0]);r(c.width,c.height);c.onload=function(){}};c.src=a.imageArray[a.activeImage][0]}function r(c,d){var e=b("#lightbox-container-image-box").width(),h=b("#lightbox-container-image-box").height();if(a.shrinkToFit){var g=k(),f=l()[1]+g[3]/10,j=c/d;
if(d>g[1]-f*2-a.shrinkPadding){d=g[1]-f*2-a.shrinkPadding;c=d*j}if(c>g[0]-a.shrinkPadding){c=g[0]-a.shrinkPadding;d=c/j}}g=c+a.containerBorderSize*2;f=d+a.containerBorderSize*2;e-=g;h-=f;b("#lightbox-container-image-box").animate({width:g,height:f},a.containerResizeSpeed,function(){s()});if(e==0&&h==0)b.browser.msie?o(250):o(100);b("#lightbox-container-image-data-box").css({width:c});b("#lightbox-nav-btnPrev,#lightbox-nav-btnNext").css({height:d+a.containerBorderSize*2})}function s(){b("#lightbox-loading").hide();
b("#lightbox-image").fadeIn(function(){b("#lightbox-container-image-data-box").slideDown("fast");b("#lightbox-image-details-caption").hide();a.imageArray[a.activeImage][1]&&b("#lightbox-image-details-caption").html(a.imageArray[a.activeImage][1]).show();a.imageArray.length>1&&b("#lightbox-image-details-currentNumber").html(a.txtImage+" "+(a.activeImage+1)+" "+a.txtOf+" "+a.imageArray.length).show();t()});if(a.imageArray.length-1>a.activeImage){objNext=new Image;objNext.src=a.imageArray[a.activeImage+
1][0]}if(a.activeImage>0){objPrev=new Image;objPrev.src=a.imageArray[a.activeImage-1][0]}}function t(){b("#lightbox-nav").show();b("#lightbox-nav-btnPrev,#lightbox-nav-btnNext").css({background:"transparent url("+a.imageBlank+") no-repeat"});if(a.activeImage!=0)a.fixedNavigation?b("#lightbox-nav-btnPrev").css({background:"url("+a.imageBtnPrev+") left 15% no-repeat"}).unbind().bind("click",function(){a.activeImage-=1;i();return false}):b("#lightbox-nav-btnPrev").unbind().hover(function(){b(this).css({background:"url("+
a.imageBtnPrev+") left 15% no-repeat"})},function(){b(this).css({background:"transparent url("+a.imageBlank+") no-repeat"})}).show().bind("click",function(){a.activeImage-=1;i();return false});if(a.activeImage!=a.imageArray.length-1)a.fixedNavigation?b("#lightbox-nav-btnNext").css({background:"url("+a.imageBtnNext+") right 15% no-repeat"}).unbind().bind("click",function(){a.activeImage+=1;i();return false}):b("#lightbox-nav-btnNext").unbind().hover(function(){b(this).css({background:"url("+a.imageBtnNext+
") right 15% no-repeat"})},function(){b(this).css({background:"transparent url("+a.imageBlank+") no-repeat"})}).show().bind("click",function(){a.activeImage+=1;i();return false});u()}function u(){b(document).keydown(function(c){if(c==null){keycode=event.keyCode;escapeKey=27}else{keycode=c.keyCode;escapeKey=c.DOM_VK_ESCAPE}key=String.fromCharCode(keycode).toLowerCase();if(key==a.keyToClose||key=="x"||keycode==escapeKey)m();if(key==a.keyToPrev||keycode==37)if(a.activeImage!=0){a.activeImage-=1;i();
b(document).unbind()}if(key==a.keyToNext||keycode==39)if(a.activeImage!=a.imageArray.length-1){a.activeImage+=1;i();b(document).unbind()}})}function m(){b("#jquery-lightbox").remove();b("#jquery-overlay").fadeOut(function(){b("#jquery-overlay").remove()});b("embed, object, select").css({visibility:"visible"})}function k(){var c,d;if(window.innerHeight&&window.scrollMaxY){c=window.innerWidth+window.scrollMaxX;d=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){c=
document.body.scrollWidth;d=document.body.scrollHeight}else{c=document.body.offsetWidth;d=document.body.offsetHeight}var e,h;if(self.innerHeight){e=document.documentElement.clientWidth?document.documentElement.clientWidth:self.innerWidth;h=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){e=document.documentElement.clientWidth;h=document.documentElement.clientHeight}else if(document.body){e=document.body.clientWidth;h=document.body.clientHeight}pageHeight=d<
h?h:d;pageWidth=c<e?c:e;return arrayPageSize=[pageWidth,pageHeight,e,h]}function l(){var c,d;if(self.pageYOffset){d=self.pageYOffset;c=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){d=document.documentElement.scrollTop;c=document.documentElement.scrollLeft}else if(document.body){d=document.body.scrollTop;c=document.body.scrollLeft}return arrayPageScroll=[c,d]}function o(c){var d=new Date;do var e=new Date;while(e-d<c)}a=jQuery.extend({overlayBgColor:"#000",
overlayOpacity:0.8,fixedNavigation:false,imageLoading:lightbox_path+"images/lightbox-ico-loading.gif",imageBtnPrev:lightbox_path+"images/lightbox-btn-prev.gif",imageBtnNext:lightbox_path+"images/lightbox-btn-next.gif",imageBtnClose:lightbox_path+"images/lightbox-btn-close.gif",imageBlank:lightbox_path+"images/lightbox-blank.gif",containerBorderSize:10,containerResizeSpeed:400,txtImage:"Image",txtOf:"of",keyToClose:"c",keyToPrev:"p",keyToNext:"n",imageArray:[],activeImage:0,captionPosition:"",shrinkToFit:true,
shrinkPadding:50,grouping:true},a);var v=this;return this.unbind("click").click(function(){p(this,v);return false})}})(jQuery);
