/***
 * 
 * jbgallery 2.0 BETA - RC3
 * 
 * $Date: 2011-05-16 20:53:56 +0200 (lun, 16 mag 2011) $
 * $Revision: 54 $
 * $Author: massimiliano.balestrieri $
 * $HeadURL: https://jbgallery.googlecode.com/svn/trunk/jbgallery-3.0.min.js $
 * $Id: jbgallery-3.0.min.js 54 2011-05-16 18:53:56Z massimiliano.balestrieri $
 * @requires jQuery v1.3.2
 * 
 * Copyright (c) 2010 Massimiliano Balestrieri
 * Examples and docs at: http://maxb.net/blog/
 * Licensed GPL licenses:
 * http://www.gnu.org/licenses/gpl.html
 *
 * Thanks to Carlo Denaro, Simone Parato, Aaron Hutten, Alain Bourgeoa, Steffen Wenzel
 * Inspired by http://www.ringvemedia.com/introduction
 */
//jQuery.noConflict();
;(function(c){jBGallery={Settings:function(){return{style:"centered",menu:"slider",shortcuts:[37,39],slideshow:!1,fade:!0,popup:!1,randomize:0,caption:!0,autohide:!1,clickable:!1,current:1,webkit:navigator.userAgent.toLowerCase().search(/webkit/)!=-1,ie6:/MSIE 6/i.test(navigator.userAgent),ie7:/MSIE 7/i.test(navigator.userAgent),labels:{play:"play",next:"next",prev:"prev",stop:"stop",close:"close",info:"info"},timers:{fade:400,interval:7E3,autohide:7E3},delays:{mousemove:200,resize:500,mouseover:800},
close:function(){},before:function(){},after:function(){},load:function(){},ready:function(){},fullscreen:!0,push:function(){},unshift:function(){},shift:function(){},pop:function(){},empty:function(){}}}};jBGallery.Init=function(e,d){function a(a){if(!c(a).data("jbgallery")){var b=new jBGallery.Options(e,a),d=new jBGallery.Data(a,e);c(a).data("jbgallery",new jBGallery.Core(a,d,b));return c(a).data("jbgallery")}}if(typeof e=="string"){if(c(this).data("jbgallery"))return c(this).eq(0).data("jbgallery")[e](d)}else return typeof d==
"boolean"?a(c(this).get(0)):this.each(function(){a(this)})};jBGallery.Data=function(e){function d(b,d){c.isArray(b)?c.each(b,function(c,e){b[c]=a(e);f[d](b[c])}):(b=a(b),f[d](b));return b}function a(b){b=typeof b=="string"?a({href:b}):c.extend({href:"",title:"",caption:"",caption_css:"",thumb:"",rel:""},b);if(b.thumb.length==0||!b.thumb)b.thumb=b.href;return b}var f=[];(function(){f=c.map(c(e).find("ul > li"),function(a){var e=c("a",a).get(0);return d({href:e.href,title:e.title,rel:e.rel,caption:c("div.caption",
a).html(),caption_css:c("div.caption",a).clone().removeClass("caption").attr("class"),thumb:c("img",a).attr("src")},"push")})})();return{get:function(c){return f[c]?f[c]:a("")},items:function(){return f},push:function(a){return d(a,"push")},unshift:function(a){return d(a,"unshift")},shift:function(){f.shift()},pop:function(){f.pop()},empty:function(){f=[]},length:function(){return f.length}}};jBGallery.Core=function(e,d,a){function f(){c("html, body").removeClass("jbg").removeClass("ie6");g.target.unbind();
g.target.remove();c(b).removeData("jbgallery");c(b).unbind();c(".jbg-wrap",b).remove();c(".jbgs-thumb, .jbgs, .jbgs-opacity, .jbgs-top, .jbgs-top-opacity, .jbg-loading, .jbg-caption, .jbg-menu-opacity, .jbg-menu",e).unbind().find("a").unbind();c(".jbgs-thumb, .jbgs, .jbgs-opacity, .jbgs-top, .jbgs-top-opacity, .jbg-loading, .jbg-caption, .jbg-menu-opacity, .jbg-menu",e).remove();c(document).unbind("keydown.jbgallery").unbind("mousemove.jbgallery").unbind("click.jbgallery");c(window).unbind("resize.jbgallery")}
var b=e;new jBGallery.Interface(b,d,a);var g=new jBGallery.Engine(b,d,a),h=new jBGallery.Keys(g,a.shortcuts);g.register(h);new jBGallery.OnLoadImage(e,g,a);h=a.caption?new jBGallery.Caption(b,d,g,a):{};a.menu&&(h=a.menu=="slider"?new jBGallery.MenuSlider(b,d,g,h,a):new jBGallery.MenuSimple(b,d,g,h,a),g.register(h));c(b).bind("destroy",f);c(window).bind("unload",f);c(b).fadeIn(a.timers.fade,function(){a.ready(b)});return{current:g.current,play:g.play,stop:g.stop,go:g.go,right:g.right,left:g.left,destroy:f,
length:d.length,push:g.push,shift:g.shift,pop:g.pop,unshift:g.unshift,empty:g.empty}};jBGallery.Loading=function(){document.getElementsByTagName("html")[0].className="loading"};jBGallery.Options=function(e,d){var a={};c.metadata&&(a=c(d).metadata());var f=new jBGallery.Settings,a=c.extend(!0,f,a,e);if(a.current!==1)a.randomize=0;if(a.popup&&a.current===1&&(f=parseInt(location.hash.replace("#",""),10)))a.current=f;a.current--;if(a.current<0)a.current=0;if(!a.fade)a.timers.fade=0;if(a.popup&&a.style==
"centered")a.style="centered modal";return a};jBGallery.EventTimer=function(e,d,a,f,b){c.each(d,function(d,h){var i=null;c(e).bind(h,function(c){i&&clearTimeout(i);i=setTimeout(function(){f(c)},a)});b&&c(e).bind(b,function(){i&&clearTimeout(i)})})};jBGallery.AutoToggle=function(e,d,a){function f(){h();g(a[0])}function b(){g(a[1])}function g(a){c(e).each(function(){if(c(this).css("visibility")!=="hidden")c(this)[a](d.timers.fade)})}function h(){i&&(clearInterval(i),i=!1);i=setInterval(b,d.timers.autohide)}
var i=!1,l=!1;a||(a=["slideDown","slideUp"]);c(document).bind("click.jbgallery",f).bind("mousemove.jbgallery",function(){l&&(clearTimeout(l),l=!1);l=setTimeout(f,d.delays.mousemove)});h()};jBGallery.Randomizer=function(c,d){c=Math.ceil((d-1)*Math.random());c>=d&&(c=0);return c};jBGallery.Interface=function(e,d,a){if(a.randomize>0)a.current=jBGallery.Randomizer(a.current,d.length());var f=a.style;a.webkit&&(f="");f='<img style="visibility:hidden" class="'+f+' jbgallery-target" alt="'+d.get(a.current).title+
'" src="'+d.get(a.current).href+'" />';f='<div class="jbg-wrap '+a.style+'"><table cellpadding="0" cellspacing="0"><tr><td>'+f+"</td></tr></table></div>";c(e).hide().find("ul").hide();a.fullscreen?c("html, body").addClass("jbg-body"):c(e).addClass("jbox");a.ie6&&c("html").addClass("ie6");c(e).prepend(f).prepend('<div class="jbg-caption" style="display:none"></div>').prepend('<div class="jbg-loading"><span class="jbg-loading"></span></div>');f=new Image;f.onload=function(){c(".jbgallery-target",e).hide().css("visibility",
"").fadeIn(a.timers.fade)};f.src=d.get(a.current).href};jBGallery.Engine=function(e,d,a){function f(b){a.before();r.css("opacity",0.5).show();j=b;var e=d.get(j-1),b=new Image;b.onload=function(){m.fadeOut(a.timers.fade,function(){this.src==e.href&&(e.href+="#"+(new Date).getTime());c(this).hide().attr({src:e.href,alt:e.title})})};b.src=e.href}function b(a){a>d.length()||a===j&&!k||(f(a),k=!1)}function g(c){a.randomize==2&&(j=jBGallery.Randomizer(j,d.length()));var e=j<d.length()?j+1:1;b(e,c)}function h(c,
j){var e=d[c](j);d.length()==1&&b(1);l(c,e);a[c](e)}function i(){k=!0;d.empty();l("empty");a.empty()}function l(a,b){c.each(p,function(c){p[c].notify(a,b)})}var j=a.current?a.current+1:1,n=a.slideshow,q=a.timers.interval,s=!1,p=[],k=!1,m=c(".jbgallery-target",e),r=c(".jbg-loading",e);return{current:function(){return j},slideshow:function(){return n},length:function(){return d.length()},play:function(){n||(n=!0,g(q))},stop:function(){n=!1;clearTimeout(s)},go:b,right:g,left:function(){a.randomize==
2&&(j=jBGallery.Randomizer(j,d.length()));var c=j>1?j-1:d.length();b(c)},target:m,loading:r,timeout:function(a){clearTimeout(s);s=setTimeout(function(){g(a)},q)},register:function(a){p.push(a)},push:function(a){h("push",a)},shift:function(){d.shift();j==1&&d.length()>0?(k=!0,b(1)):j--;l("shift");a.shift();d.length()==0&&i()},pop:function(){d.pop();j>d.length()&&d.length()>0&&(k=!0,b(d.length()));l("pop");a.pop();d.length()==0&&i()},unshift:function(a){d.length()>1&&j++;h("unshift",a)},empty:i}};jBGallery.OnLoadImage=
function(e,d,a){(a.ie6||a.webkit||a.style!=="zoom")&&new jBGallery.Fix(e,d.target,a);a.clickable&&d.target.click(function(){d.right();return!1}).css({cursor:"pointer"});d.target.one("load",function(){c("html").removeClass("loading")}).bind("load",function(c){d.loading.hide();d.target.hide().css("visibility","").fadeIn(a.timers.fade);a.load(c);a.after(c);d.slideshow()&&d.timeout(c)})};jBGallery.Fix=function(e,d,a){function f(b){var d=a.fullscreen?"body":e,f=c(d).width(),d=c(d).height(),b={bw:f,bh:d,
pm:f/d,p:b.width/b.height,h:b.height,w:b.width};_img=null;return b}function b(){var c=d.get(0),b=a.style=="zoom"?h:g;a.ie6||a.ie7?setTimeout(function(){b(c)},10):b(c)}function g(b){c(b).width("auto").height("auto");var b=f(b),d;if(a.style=="original"&&b.bw>=b.w&&b.bh>=b.h)return!1;if(b.bw<b.bh){var e=b.h*b.bw/b.w;(d=e>b.bh)?(e=b.w*b.bh/b.h,l(e,b,d)):l(b.bw,b)}else e=b.w*b.bh/b.h,(d=e>b.bw)?(e=b.h*b.bw/b.w,i(e,b,d)):i(b.bh,b)}function h(a){c(a).width("auto").height("auto");a=f(a);if(a.bh>a.bw){var b=
a.w*a.bh/a.h;b<a.bw?(b=a.h*a.bw/a.w,i(b,a,!0)):i(a.bh,a,!0)}else b=a.h*a.bw/a.w,b<a.bh?(b=a.w*a.bh/a.h,l(b,a,!0)):l(a.bw,a,!0)}function i(c,b,e){(e||a.style=="centered"||b.bh<b.h)&&d.height(c)}function l(c,b,e){(e||a.style=="centered"||b.bw<b.w)&&d.width(c)}a.fullscreen&&jBGallery.EventTimer(window,["resize.jbgallery"],a.delays.resize,b);d.bind("load",function(){b()})};jBGallery.Keys=function(e,d){function a(a){switch(a.which||a.keyCode){case d[0]:return e.left(),!1;case d[1]:return e.right(),!1;
case 37:case 38:case 39:case 40:return!1}}function f(){!b&&e.length()>1&&(c(document).bind("keydown.jbgallery",a),b=!0)}var b=!1;f();return{notify:function(){f()}}};jBGallery.Caption=function(e,d,a,f){function b(){var c,b=a.current(),e=c="",b=d.get(b-1),e=b.title;b.rel.length>0&&(e='<a href="'+b.rel+'" target="_self">'+b.title+"</a>");b.title.length>0&&(c+="<h3>"+e+"</h3>");b.caption&&(c+="<div>"+b.caption+"</div>");h.removeAttr("class").addClass(b.caption_css).addClass("jbg-caption");c+="";g=c.length;
h.html(c);g==0&&h.hide()}var g=0,h=c(".jbg-caption",e);b();g>0&&h.fadeIn(f.timers.fade);f.autohide&&jBGallery.AutoToggle(h,f);a.target.bind("load",function(){b()});return{toggle:function(){g>0&&h.toggle()}}};jBGallery.MenuSimple=function(e,d,a,f,b){function g(){var b=a.current();k.find("a.selected").removeClass("selected");k.find("a:eq("+b+")").addClass("visited").addClass("selected")}function h(a,b,d){a=c('<a href="#" class="'+a+'">'+b+"</a>").click(function(){d();return!1});return c("<li></li>").append(a)}
function i(){for(var b="",c=1;c<=a.length();c++)b+='<li class="jbg-n"><a href="#">'+c+"</a></li>";return b}function l(b){b=b.target||b.srcElement;b.tagName.toString().toLowerCase()==="a"&&(b=parseInt(c(b).text()),a.go(b));return!1}function j(){!p&&a.length()>0&&(c('<div class="jbg-menu-opacity" /><ul class="jbg-menu" />').hide().appendTo(e),k=c(".jbg-menu",e),m=c(".jbg-menu-opacity , .jbg-menu",e),b.menu=="numbers"&&k.append(i()).click(l).find("a:eq("+(a.current()-1)+")").addClass("selected").addClass("visited"),
k.append(h("jbg-next",b.labels.next,a.right)).prepend(h("jbg-prev",b.labels.prev,a.left)),k.append(r).append(t),b.caption&&k.append(h("jbg-info",b.labels.info,function(){f.toggle();return!1})),b.popup&&k.append(h("jbg-close",b.labels.close,function(){c(s).trigger("destroy");b.close();return!1})),b.menu=="numbers"&&a.target.bind("load",g),b.autohide&&jBGallery.AutoToggle(c(m),b),c(m).fadeIn(b.timers.fade),p=!0)}function n(a){c(".jbg-next",k).parent().before(a)}function q(b){p||j();if(c.isArray(b)){var d=
"",e=a.length()-b.length;c.each(b,function(a){d+='<li class="jbg-n"><a href="#">'+(e+a+1)+"</a></li>"});n(d)}else n('<li class="jbg-n"><a href="#">'+a.length()+"</a></li>");g();a.length()}var s=e,p=!1,k,m,r=h("jbg-play",b.labels.play,function(){a.play();r.hide();t.show()}).toggle(!b.slideshow),t=h("jbg-stop",b.labels.stop,function(){a.stop();r.show();t.hide()}).toggle(b.slideshow);a.length();j();return{notify:function(e,f){d.length()>0&&!c(m).eq(0).is(":visible")&&c(m).fadeIn(b.timers.fade);if(b.menu==
"numbers")switch(e){case "push":case "unshift":q(f);break;case "pop":case "shift":c("li.jbg-n:last",k).remove()}e=="empty"&&(b.menu=="numbers"&&c(".jbg-n",k).remove(),c(m).fadeOut(b.timers.fade),a.length())}}};jBGallery.MenuSlider=function(e,d,a,f,b){function g(a,b){c(a).click(function(){var a=this;if(!c(a).is(".lock"))return c(a).addClass("lock"),b(function(){c(a).removeClass("lock")}),!1})}function h(a){return a.height>=a.width?"jbgs-thumb-portrait":"jbgs-thumb-landscape"}function i(a,b){o.animate({left:a},
function(){b&&b()})}function l(a){var b=n(),c=q();i(b+60*c>0?0:b+60*c,a)}function j(b){var c=n(),d=a.length(),e=Math.abs(c)/60,f=q(),g=(d-f)*60;if(d<f||f+e>=d)return b();i(e+f+f>d?-g:c-60*f,b)}function n(){return parseInt(o.css("left"),10)}function q(){var a=c(u).width()-130;return(a-a%60)/60}function s(){c("a",o).css("margin-top","");c(".jbgs-thumb").fadeOut(b.timers.fade,function(){c(this).remove()})}function p(a){a=a.target||a.srcElement;if(a.tagName.toString().toLowerCase()==="img"){c(a).parent().parent().css("margin-top",
"3px");var d=c(F).index(c(a).parent().parent()),a=c(a).get(0),f=new Image;f.src=a.src;var d="jbgs-thumb-"+d,g=c(a).parents("li:eq(0)").offset().left-c(e).offset().left,i=h(f);f=f.height>=f.width?25:(f.width*100/f.height-60)/2;f=g-f;c("#"+d).length==0&&c('<div style="left:'+f+'px" class="jbgs-thumb" id="'+d+'"><img src="'+a.src+'" alt="" class="'+i+'" />'+(b.ie6||b.ie7?"":'<div class="jbgs-thumb-btn"><div class="jbgs-thumb-tip" /></div>')+"</div>").hide().appendTo(u).fadeIn(b.timers.fade)}}function k(){var a=
c(u).width()-130;B.width(a-a%60)}function m(a){c(a).addClass(h(a)).css(a.height>=a.width?{top:-(a.height*51/a.width-51)/2}:{left:-(a.width*51/a.height-51)/2})}function r(a){c(a).wrap("<div />");if(a.complete)m(a);else c(a).one("load",function(){m(a)})}function t(a,b){var d=c('<li><a title="'+a.title+'" href="'+a.href+'"><img src="'+a.thumb+'" alt="" /></a></li>')[b](w),d=c("img",d).css("opacity",0.7).get(0);r(d)}function A(d,e,f){!f&&!C&&E();c.isArray(d)?c.each(d,function(a,b){t(b,e)}):t(d,e);D==
0&&!f&&x.fadeIn(b.timers.fade);D=a.length()}function E(){!C&&a.length()>0&&(c(u).append(I+J).addClass("jbgs-cnt"),v=c(".jbgs-top-right",e),B=c(".jbgs-viewer",e),w=c('<div class="jbgs-inner"></div>').appendTo(B),o=c(".jbgs-inner",e),y=c(".jbgs-h-play",e),z=c(".jbgs-h-pause",e),F=c("a",o),x=c(".jbgs-opacity, .jbgs, .jbgs-top",e),A(d.items(),"appendTo",!0),c(".jbgs-opacity, .jbgs-h").css("opacity",0.8),a.slideshow()?y.hide():z.hide(),b.caption&&c(K).click(function(){f.toggle();return!1}).appendTo(v),
b.popup&&(c("a",v).length>0&&c(L).appendTo(v),c(M).click(function(){c(H).trigger("destroy");b.close();return!1}).appendTo(v)),g(".jbgs-h-left",l),g(".jbgs-h-right",j),y.click(function(){c(this).hide();z.show();a.play();return!1}),z.click(function(){c(this).hide();y.show();a.stop();return!1}),c(".jbgs-h-prev",e).click(function(){a.left();return!1}),c(".jbgs-h-next",e).click(function(){a.right();return!1}),c("a",o).live("click",function(){var b=c("a",o).index(this)+1;a.go(b);return!1}),jBGallery.EventTimer(o,
["mouseover"],b.delays.mouseover,p,"mouseout"),o.bind("mouseout",s),a.target.bind("load",function(){var b=a.current(),d=n(),d=Math.abs(d)/60,e=q();if(!(b>=d+1&&b<=d+e)){d=b;d-=1;var e=a.length,f=q(),d=e-f<d?e-f:d;i(-(d*60)<=0?-(d*60):0)}c("a",o).find(".focus").removeClass("focus").css("opacity","0.7").end().eq(b-1).find("img").addClass("focus").css("opacity","1").parent().addClass("focus").css("opacity","1")}),jBGallery.EventTimer(window,["resize.jbgallery"],b.delays.resize,k),b.autohide&&(jBGallery.AutoToggle(x,
b),jBGallery.AutoToggle(".jbgs-thumb",b,["fadeIn","fadeOut"])),C=!0)}var H=e,u=e,G=b.fullscreen?c("body").width()-130:c(u).width()-130,L="<span>&nbsp;|&nbsp;</span>",M='<a href="#" class="jbgs-h-close">'+b.labels.close+"</a>",K='<a href="#" class="jbgs-h-info">'+b.labels.info+"</a>",I='<div class="jbgs-top"><div class="jbgs-top-center"><a href="#" class="jbgs-h jbgs-h-prev">&nbsp;</a><a href="#" class="jbgs-h jbgs-h-next">&nbsp;</a></div><div class="jbgs-top-right"></div></div>',J='<div class="jbgs-opacity"></div><div class="jbgs"><div class="jbgs-wrapper"><div class="jbgs-left"><a href="#" class="jbgs-h-play jbgs-h">&nbsp;</a><a href="#" class="jbgs-h-pause jbgs-h">&nbsp;</a><a href="#" class="jbgs-h-left jbgs-h">&nbsp;</a></div><div class="jbgs-viewer" style="width:'+
(G-G%60)+'px"></div><div class="jbgs-right"><a href="#" class="jbgs-h-right jbgs-h">&nbsp;</a></div></div></div>',w,v,B,o,y,z,F,x,C=!1,D=a.length();E();return{notify:function(d,e){switch(d){case "empty":o.empty();x.hide(b.timers.fade);D=a.length();break;case "push":A(e,"appendTo");break;case "unshift":A(e,"prependTo");break;case "shift":c("li:first",w).remove();break;case "pop":c("li:last",w).remove()}}}};jBGallery.Adapters={};c.fn.jbgallery=jBGallery.Init})(jQuery);
