
$(document).ready(function(){lightbox();});$(document).unbind('keypress');function lightbox(){var gurl='img/';var templateUrl='';maxPreviewPics=20;var activeType='Bild';var links=$("a[href*="+gurl+"]");var overlay=$(jQuery('<div id="overlay" style="display: none"></div>'));var container=$(jQuery('<div id="lightbox" style="display: none"></div>'));var target=$(jQuery('<div class="target"></div>'));var video=$(jQuery('<div id="lb-video">Videos funktionieren derzeit noch nicht!</div>'));var topbar=$(jQuery('<div id="lb-topbar"></div>'));var previews=$(jQuery('<div id="lb-previews"></div>'));var data=$(jQuery('<div id="lb-data">Gallery</div>'));var maxpic=parseInt($("#pagenavi :last-child")[0].childNodes[0].data)+0;var arr=links[0].href.split("/");var galid=arr[arr.length-2];$('body').append(overlay).append(topbar).append(container);topbar.append(previews).append(data);container.append(target);container.show().css({'top':Math.round((($(window).height()>window.innerHeight?window.innerHeight:$(window).height())-container.outerHeight())/2)+'px','left':Math.round(($(window).width()-container.outerWidth())/2)+'px','margin-top':35,'margin-left':0}).hide();for(var i=1;i<=13;i++){previews.append(jQuery('<img class="previewImg" id="pimg_'+i+'" height="35" width="47" />'));if(i==6){i++;previews.append(jQuery('<img class="previewImg pnav arrow" id="prevImg" height="35" width="35" src="'+templateUrl+'img/imagebox/left.gif" />'));previews.append(jQuery('<img class="previewImg pnav" id="galleryImg" src="'+templateUrl+'img/imagebox/gallery.gif" height="35" width="47" />'));previews.append(jQuery('<img class="previewImg pnav arrow" id="nextImg" height="35" width="35" src="'+templateUrl+'img/imagebox/right.gif" />'));}}
var gallery=$(jQuery('<div id="lb-gallery"></div>'));for(var i=1;i<=maxpic;i++){gallery.append(jQuery('<img src="'+gurl+galid+'/thumb_'+i+'.jpg" class="previewImg2 '+(Math.floor(i/maxPreviewPics)*maxPreviewPics)+'" id="pgimg_'+i+'" height="116" width="155" />'));}
container.append(gallery);$(".previewImg2").unbind('click').click(function(){open(this.src.replace('/thumb_','/'));});overlay.click(function(c){overlay.add(container).add(topbar).fadeOut('normal');$(document).unbind('keydown');});links.each(function(index){var link=$(this);link.click(function(c){c.preventDefault();open(link.attr('href'));});link.attr({'lb-position':index});});var open=function(url){gallery.hide();target.show();if(container.is(':visible')){target.children().fadeOut('normal',function(){target.children().remove();loadImage(url);});}else{target.children().remove();overlay.add(container).fadeIn('normal',function(){loadImage(url);});topbar.fadeIn();}
var thisid=parseInt(url.split("/").pop().slice(0,-4))+0;data.html(thisid+" von "+maxpic);$(document).unbind('keydown');$(document).keydown(function(e){switch(e.which){case 27:overlay.add(container).add(topbar).fadeOut('normal');break;case 37:if(thisid>0)
open(gurl+galid+'/'+(thisid-1)+'.jpg');break;case 39:if(thisid<maxpic)
open(gurl+galid+'/'+(thisid+1)+'.jpg');break;default:}});for(var i=1;i<=13;i++){previewid=thisid+i-7;if(previewid<1||previewid>maxpic){$(".previewImg:not(.arrow)").eq(i-1).attr('src','images/blank.gif').unbind('click');}else{if(thisid!==previewid){$(".previewImg:not(.arrow)").eq(i-1).attr('src',gurl+galid+'/'+'thumb_'+previewid+'.jpg').unbind('click').click(function(){open(this.src.replace('/thumb_','/'));});}}}
$("#galleryImg").unbind('click').click(function(){container.animate({'width':840,'height':500,'top':Math.round((($(window).height()>window.innerHeight?window.innerHeight:$(window).height())-500-parseInt(container.css('padding-top'),10)-parseInt(container.css('padding-bottom'),10))/2)+'px','left':Math.round(($(window).width()-840-parseInt(container.css('padding-left'),10)-parseInt(container.css('padding-right'),10))/2)+'px'},'fast');gallery.show();target.hide();data.html("Schnellwahl");$(".previewImg:not(.pnav)").attr('src','images/blank.gif').unbind('click');var first=Math.floor(thisid/maxPreviewPics)*maxPreviewPics;$(".previewImg2").hide();$("."+first+"").show();$(this).unbind('click').click(function(){open(gurl+galid+'/'+thisid+'.jpg');});$("#prevImg").unbind('click').click(function(){if(thisid-maxPreviewPics>=0){var first=(Math.floor(thisid/maxPreviewPics)*maxPreviewPics);$("."+first+"").hide();thisid=first-maxPreviewPics;$("."+thisid+"").show();}});$("#nextImg").unbind('click').click(function(){if(thisid+maxPreviewPics<maxpic){var first=(Math.floor(thisid/maxPreviewPics)*maxPreviewPics);$("."+first+"").hide();thisid=first+maxPreviewPics;$("."+thisid+"").show();}});});$("#prevImg").unbind('click').click(function(){if(thisid>1)open(gurl+galid+'/'+(thisid-1)+'.jpg');});$("#nextImg").unbind('click').click(function(){if(thisid<maxpic)open(gurl+galid+'/'+(thisid+1)+'.jpg');});var pPI=new Image();pPI.src=gurl+galid+'/'+(thisid-1)+'.jpg';var pNI=new Image();pNI.src=gurl+galid+'/'+(thisid+1)+'.jpg';}
var loadImage=function(url){activeType='Bild';if(container.is('.loading')){return;}
container.addClass('loading');var img=new Image();img.onload=function(){img.style.display='none';var maxWidth=($(window).width()-parseInt(container.css('padding-left'),0)-parseInt(container.css('padding-right'),0))-20;var maxHeight=(($(window).height()>window.innerHeight?window.innerHeight:$(window).height())-parseInt(container.css('padding-top'),0)-parseInt(container.css('padding-bottom'),0))-100;if(img.width>maxWidth||img.height>maxHeight){var ratio=img.width/img.height;if(img.height>=maxHeight){img.height=maxHeight;img.width=maxHeight*ratio;}else{img.width=maxWidth;img.height=maxWidth*ratio;}}
container.animate({'width':img.width,'height':img.height,'top':Math.round((($(window).height()>window.innerHeight?window.innerHeight:$(window).height())-img.height-parseInt(container.css('padding-top'),10)-parseInt(container.css('padding-bottom'),10))/2)+'px','left':Math.round(($(window).width()-img.width-parseInt(container.css('padding-left'),10)-parseInt(container.css('padding-right'),10))/2)+'px'},'fast',function(){target.append(img);$(img).fadeIn('normal',function(){container.removeClass('loading');});})
$(img).unbind('click').click(function(c){overlay.add(container).add(topbar).fadeOut('normal');$(document).unbind('keydown');});}
img.onerror=function(){img.src='images/blank.gif';target.children().remove();activeType='Video';target.append(video).fadeIn();$(video).fadeIn();};img.src=url;}}
