/*
 * XenForo lightbox.min.js
 * Copyright 2010-2013 XenForo Ltd.
 * Released under the XenForo License Agreement: http://xenforo.com/license-agreement
 */
(function(a,p,q){XenForo.LightBox=function(r,u){var o=a("#LightBox").prop("unselectable",!0),m=o.find(".imageNav"),g=a("#LbImg"),j=o.find(".imageContainer"),n=[],e=a("#LbThumbs"),i=e.data("thumbheight"),k=0,l=0,s="";a("#LbPrev, #LbNext, #LightBox .imageContainer").click(a.context(function(b){b.preventDefault();this.shift(a(b.target).closest(".imageNav").attr("id")=="LbPrev"?-1:1);return!1},this));this.bindNav=function(){a(q).bind({"keydown.lightbox":a.context(function(a){switch(a.keyCode){case 37:case 38:return a.preventDefault(),
this.shift(-1);case 39:case 40:return a.preventDefault(),this.shift(1)}},this),"wheel.lightbox":a.context(function(a,d){d&&(a.preventDefault(),this.shift(d<0?1:-1))},this)})};this.unbindNav=function(){a(q).unbind(".lightbox")};this.shift=function(b){var d=e.find("li:not(#LbThumbTemplate) a");d.each(a.context(function(c,e){if(a(e).data("src")==g.attr("src"))return c+=b,c<0?c=d.length-1:c>=d.length&&(c=0),d.eq(c).triggerHandler("click",[!0]),!1},this))};this.setThumbStrip=function(b){console.info("setThumbStrip(%o)",
b);var d=a("#LbThumbTemplate"),c=this;n=[];e.find("li").not(d).remove();l=0;b.find("img.LbImage").each(a.context(function(b,f){var h=a(f),g=h.parent(".LbTrigger").attr("href")||h.attr("src");if(h.parents(".ignored").length)return this;a.inArray(g,n)==-1&&(n.push(g),setTimeout(function(){preLoader=new Image;preLoader.src=g},1),d.clone().removeAttr("id").appendTo(e).find("a").data("src",g).data("el",h).click(a.context(function(a,b){a.preventDefault();this.setImage(h,b?0:XenForo.speed.fast)},this)).find("img").load(function(){var b=
this;setTimeout(function(){var c=a(b),d=c.width();c.height()>d?(c.css("width",i),c.css("top",(c.height()-i)/2*-1)):(c.css("height",i),c.css(XenForo.switchStringRTL("left"),(c.width()-i)/2*-1));c.css("visibility","visible")},0)}).error(function(){c.removeFailedThumb(this)}).attr("src",h.attr("src")))},this));switch(n.length){case 0:return!1;case 1:m.hide();break;default:m.show()}return this};this.removeFailedThumb=function(b){a(b).closest("li").remove();switch(e.find("li:not(#LbThumbTemplate)").length){case 0:return r.close(),
!1;case 1:m.hide();break;default:m.show()}this.setDimensions(!0);this.selectThumb(s,0);return!0};this.setImage=function(b,d){if(b===void 0)return j.find("img.LbImg").not(g).remove(),this;var c,t=b.closest(u),f=b.parent(".LbTrigger").attr("href")||b.attr("src"),h=this;c=g.clone(!0);var i=a.context(function(){j.find("img.LbImg").not(g).remove();c.css({maxWidth:j.width(),maxHeight:j.height()});c.prependTo(g.parent()).css({position:"static","margin-top":(j.height()-c.height())/2,visibility:"visible"});
g.attr("src",f)},this);c.one("load",function(){setTimeout(i,0)}).error(function(){e.find("li:not(#LbThumbTemplate) a").each(function(b,c){a(c).data("src")==f&&h.removeFailedThumb(c)&&(console.log(a(e.find("li:not(#LbThumbTemplate) a").get(Math.max(0,b-1))).data("el")),h.setImage(a(e.find("li:not(#LbThumbTemplate) a").get(Math.max(0,b-1))).data("el"),0))})});c.attr("src",f);this.selectThumb(f,d);this.setImageInfo(t,f);this.setContentLink(t);return this};this.selectThumb=function(b,d){var c=e.find("li:not(#LbThumbTemplate) a");
c.find("img").fadeTo(0,0.5);b===void 0&&(b=g.attr("src"));c.each(function(g,f){if(a(f).data("src")==b){s=b;l=g*(i+3);e.stop();if(d){var h={};h[XenForo.switchStringRTL("left")]=k-l;e.animate(h,d,function(){a(f).find("img").fadeTo(d/6,1)})}else e.css(XenForo.switchStringRTL("left"),k-l),a(f).find("img").fadeTo(0,1);a("#LbSelectedImage").text(g+1);a("#LbTotalImages").text(c.length);return!1}});return this};this.setDimensions=function(b){var d=a(p).height()-r.getConf().top*2-a("#LbUpper").outerHeight()-
a("#LbLower").outerHeight();j.css({height:d,lineHeight:0});o.find("img.LbImg").css({maxWidth:j.width(),maxHeight:d});k=Math.max(0,(e.parent().width()-(i+2))/2);b&&console.log("thumbOffset = "+k+", thumbShift = "+l);e.css(XenForo.switchStringRTL("left"),k-l);a("#LbReveal").css(XenForo.switchStringRTL("left"),k).show();return this};this.setImageInfo=function(b,d){var c=b.find("a.avatar"),e=c.find("img"),f=!1;if(e.length)f=e.attr("src");else if(f=c.find("span.img").css("background-image"))f=f.replace(/^url\(("|'|)([^\1]+)\1\)$/i,
"$2");f?a("#LbAvatar img").attr("src",f):a("#LbAvatar img").attr("src","rgba.php?r=0&g=0&b=0");a("#LbUsername").text(b.data("author"));a("#LbDateTime").text(b.find(".DateTime:first").text());a("#LbNewWindow").attr("href",d);return this};this.setContentLink=function(b){(b=b.attr("id"))?a("#LbContentLink, #LbDateTime").attr("href",p.location.href).attr("hash","#"+b):a("#LbContentLink").text("").removeAttr("href");return this}}})(jQuery,this,document);
