
$(document).ready(function(){$.lightbox={shadow:$('<div class="lb-shadow"></div>').appendTo(document.body),loading:$('<div class="lb-loading"></div>').appendTo(document.body),container:$('<div class="lb-1"></div>').appendTo(document.body),content:$('<div class="lb-3"></div>'),show:function(){$(document.body).addClass('lb-visible');$(document).keyup($.lightbox.keyup);$(document).keyup($.gallery.keyup);},hide:function(){$(document.body).removeClass('lb-visible');$(document).unbind('keyup',$.lightbox.keyup);$(document).unbind('keyup',$.gallery.keyup);},keyup:function(evt){if((evt.DOM_VK_ESCAPE||27)==evt.keyCode){$.lightbox.hide();}}};$.lightbox.container.append($('<div class="lb-2"></div>').append($.lightbox.content));$.lightbox.container.click($.lightbox.hide);$.gallery={temp:new Image(),close:$('<a class="close" href="javascript:void(0)">zavřít &times;</a>'),img:$('<img>'),label:$('<div class="label"></div>'),view:$('<div class="view"></div>'),prev:$('<a class="prev" href="javascript:void(0)">&laquo;&nbsp;předchozí</a>'),next:$('<a class="next" href="javascript:void(0)">následující&nbsp;&raquo;</a>'),ls:[],lsPos:0,handleClick:function(evt){$.gallery.prev.hide();$.gallery.next.hide();var galleryEid=$(this).parents('.gallery').attr('id');var galleryId=false;var motiveId=false;if(galleryEid){var m=galleryEid.match(/^gallery-([0-9]+)$/);if(m&&m[1]){galleryId=m[1];var motiveEid=this.id;m=motiveEid.match(/^motive-([0-9]+)$/);if(m&&m[1]){motiveId=m[1];}}}
$.lightbox.content.hide();$.lightbox.show();$.gallery.label.html(this.title||'&nbsp;');$.gallery.temp.onload=function(){$.lightbox.content.width($.gallery.temp.width+8);$.gallery.img.attr('src',$.gallery.temp.src);$.lightbox.content.show();if(galleryId){$.ajax({url:galleryAjaxUrl,data:{galleryId:galleryId},dataType:"json",success:function(data){$.gallery.ls=data;if(motiveId){for(var i=0,l=data.length;i<l;i++){if(motiveId==data[i].id){$.gallery.lsPos=i;break;}}}
if($.gallery.lsPos>0){$.gallery.prev.show();}
if($.gallery.lsPos+1<$.gallery.ls.length){$.gallery.next.show();}}});}}
$.gallery.temp.src=this.href;evt.preventDefault();},gtPrev:function(evt){if(!$.gallery.ls.length||$.gallery.lsPos+1>=$.gallery.ls.length){evt.stopPropagation();return;}
$.lightbox.content.hide();$.gallery.temp.onload=function(){$.lightbox.content.width($.gallery.temp.width+8);$.gallery.img.attr('src',$.gallery.temp.src);$.lightbox.content.show();}
$.gallery.lsPos++;$.gallery.temp.src=$.gallery.ls[$.gallery.lsPos].fullscreen;$.gallery.label.html($.gallery.ls[$.gallery.lsPos].title||'&nbsp;');if($.gallery.lsPos+1==$.gallery.ls.length){$.gallery.next.hide();}
$.gallery.prev.show();evt.stopPropagation();},gtNext:function(evt){if(!$.gallery.ls.length||$.gallery.lsPos<=0){evt.stopPropagation();return;}
$.lightbox.content.hide();$.gallery.temp.onload=function(){$.lightbox.content.width($.gallery.temp.width+8);$.gallery.img.attr('src',$.gallery.temp.src);$.lightbox.content.show();}
$.gallery.lsPos--;$.gallery.temp.src=$.gallery.ls[$.gallery.lsPos].fullscreen;$.gallery.label.html($.gallery.ls[$.gallery.lsPos].title||'&nbsp;');if($.gallery.lsPos==0){$.gallery.prev.hide();}
$.gallery.next.show();evt.stopPropagation();},keyup:function(evt){if(37==evt.keyCode){$.gallery.gtNext();}
if(39==evt.keyCode){$.gallery.gtPrev();}}};$.gallery.view.append($.gallery.close).append($.gallery.img).append($.gallery.prev).append($.gallery.next).append($.gallery.label);$.gallery.view.click(function(evt){evt.stopPropagation();});$.gallery.close.click(function(evt){$.lightbox.hide();evt.stopPropagation();});$.gallery.next.click($.gallery.gtPrev);$.gallery.prev.click($.gallery.gtNext);$.lightbox.content.append($.gallery.view);$('a.figure').not('.no-ltb').click($.gallery.handleClick);});
