Event.observe(window,'load',function(){Lightbox.init()});Event.observe(window,'resize',function(){if($('lightbox')&&$('lightbox').style.display=='block'&&Lightbox.currentImage.getAttribute('src'))Lightbox.resize()});var Lightbox={currentImage:new Image(),galleryImages:new Array(),imageTitles:new Array(),imageIndex:0,init:function(){var objLink=document.createElement('link');objLink.setAttribute('rel','stylesheet');objLink.setAttribute('href','lightbox/lightbox.css');objLink.setAttribute('type','text/css');objLink.setAttribute('media','all');document.getElementsByTagName('head')[0].appendChild(objLink);var objOverlay=document.createElement('div');objOverlay.id='lbox-overlay';objOverlay.onclick=function(){Lightbox.hide()};var objLoadingImage=document.createElement('img');objLoadingImage.id='loading_img';objLoadingImage.setAttribute('src','lightbox/loading.gif');objLoadingImage.setAttribute('width',126);objLoadingImage.setAttribute('height',22);objLoadingImage.setAttribute('alt','');var objLightbox=document.createElement('div');objLightbox.id='lightbox';var objImageCont=document.createElement('div');objImageCont.id='lbox-image_cont';var objImage=document.createElement('img');objImage.setAttribute('src','');objImage.setAttribute('alt','');objImageCont.appendChild(objImage);var objNav=document.createElement('div');objNav.id='lbox-nav';var objBackBtn=document.createElement('a');objBackBtn.id='lbox-prev_btn';objBackBtn.setAttribute('href','javascript: ');objBackBtn.onclick=function(){Lightbox.changeImage(-1)};objBackBtn.appendChild(document.createTextNode('előző'));var objNextBtn=document.createElement('a');objNextBtn.id='lbox-next_btn';objNextBtn.setAttribute('href','javascript: ');objNextBtn.onclick=function(){Lightbox.changeImage(1)};objNextBtn.appendChild(document.createTextNode('következő'));objNav.appendChild(objBackBtn);objNav.appendChild(objNextBtn);objImageCont.appendChild(objNav);var objBottom=document.createElement('div');objBottom.id='lbox-bottom';var objCloseButton=document.createElement('a');objCloseButton.id='lbox-close_btn';objCloseButton.setAttribute('href','javascript: ');objCloseButton.setAttribute('title','bezár');objCloseButton.onclick=function(){Lightbox.hide()};objCloseButton.appendChild(document.createTextNode('bezár'));var objParagraph=document.createElement('p');objBottom.appendChild(objCloseButton);objBottom.appendChild(objParagraph);objLightbox.appendChild(objImageCont);objLightbox.appendChild(objBottom);document.body.appendChild(objOverlay);document.body.appendChild(objLoadingImage);document.body.appendChild(objLightbox);$$('a').each(function(anchor){if(anchor.getAttribute('href')&&anchor.getAttribute('rel')&&anchor.getAttribute('rel').indexOf('lightbox')>-1){Event.observe(anchor,'click',function(event){Event.stop(event);Lightbox.show(this);return false})}})},show:function(obj){var dimensions=this.getPageDimensions();$('lbox-overlay').style.width=dimensions.pageWidth+'px';$('lbox-overlay').style.height=dimensions.pageHeight+'px';$('lbox-overlay').style.display='block';$('loading_img').style.display='block';if(obj!=null){this.galleryImages=new Array();this.imageTitles=new Array();if(obj.getAttribute('rel').indexOf('[')>-1&&obj.getAttribute('rel').indexOf(']')>-1){galleryName=obj.getAttribute('rel').substr(obj.getAttribute('rel').indexOf('[')+1,obj.getAttribute('rel').indexOf(']')-obj.getAttribute('rel').indexOf('[')-1);$$('a').each(function(anchor){if(anchor.getAttribute('rel')&&anchor.getAttribute('rel').indexOf('lightbox')>-1&&anchor.getAttribute('rel').indexOf('[')>-1&&anchor.getAttribute('rel').indexOf(']')>-1&&anchor.getAttribute('rel').substr(anchor.getAttribute('rel').indexOf('[')+1,anchor.getAttribute('rel').indexOf(']')-anchor.getAttribute('rel').indexOf('[')-1)==galleryName){if(obj==anchor)Lightbox.imageIndex=Lightbox.galleryImages.push(anchor.getAttribute('href'))-1;else Lightbox.galleryImages.push(anchor.getAttribute('href'));if(anchor.getElementsByTagName('img')[0]&&anchor.getElementsByTagName('img')[0].getAttribute('alt'))Lightbox.imageTitles.push(anchor.getElementsByTagName('img')[0].getAttribute('alt'));else Lightbox.imageTitles.push('')}})}else{this.galleryImages.push(obj.getAttribute('href'));if(obj.getElementsByTagName('img')[0]&&obj.getElementsByTagName('img')[0].getAttribute('alt'))this.imageTitles.push(obj.getElementsByTagName('img')[0].getAttribute('alt'));else this.imageTitles.push('');this.imageIndex=0}}this.changeImage(0)},changeImage:function(direction){$('lightbox').style.display='none';$('loading_img').style.display='block';if((direction==-1&&this.imageIndex>0)||(direction==1&&this.imageIndex<this.galleryImages.length-1))this.imageIndex+=direction;this.currentImage.src=this.galleryImages[this.imageIndex];this.currentImage.onload=function(){$$('#lightbox img')[0].setAttribute('src',Lightbox.currentImage.src);$$('#lbox-bottom p')[0].innerHTML=(Lightbox.galleryImages.length>1?'['+(Lightbox.imageIndex+1)+'/'+Lightbox.galleryImages.length+']':'')+(Lightbox.imageTitles[Lightbox.imageIndex]?' <span>'+Lightbox.imageTitles[Lightbox.imageIndex]+'</span>':'');Lightbox.resize();$('loading_img').style.display='none'};if(this.imageIndex>0){$('lbox-prev_btn').style.display='block';var prevImage=new Image();prevImage.src=this.galleryImages[this.imageIndex-1]}else $('lbox-prev_btn').style.display='none';if(this.imageIndex<this.galleryImages.length-1){$('lbox-next_btn').style.display='block';var nextImage=new Image();nextImage.src=this.galleryImages[this.imageIndex+1]}else $('lbox-next_btn').style.display='none'},resize:function(){$('lbox-overlay').style.width='0px';$('lbox-overlay').style.height='0px';var dimensions=this.getPageDimensions();$('lbox-overlay').style.width=dimensions.pageWidth+'px';$('lbox-overlay').style.height=dimensions.pageHeight+'px';var imageWidth=this.currentImage.width;var imageHeight=this.currentImage.height;var minWidth=300;var minHeight=300;var maxWidth=dimensions.windowWidth-120;var maxHeight=dimensions.windowHeight-120;if(maxWidth>minWidth&&imageWidth>minWidth&&imageWidth>maxWidth){var resizeBy=maxWidth/imageWidth;imageWidth=maxWidth;imageHeight=imageHeight*resizeBy}else if(maxWidth<minWidth&&imageWidth>minWidth){var resizeBy=minWidth/imageWidth;imageWidth=minWidth;imageHeight=imageHeight*resizeBy}if(maxHeight>minHeight&&imageHeight>minHeight&&imageHeight>maxHeight){var resizeBy=maxHeight/imageHeight;imageWidth=imageWidth*resizeBy;imageHeight=maxHeight}else if(maxHeight<minHeight&&imageHeight>minHeight){var resizeBy=minHeight/imageHeight;imageWidth=imageWidth*resizeBy;imageHeight=minHeight}$$('#lightbox img')[0].setAttribute('width',imageWidth);$$('#lightbox img')[0].setAttribute('height',imageHeight);$('lightbox').style.display='block';$('lightbox').style.width=$$('#lightbox img')[0].offsetWidth+'px';$('lightbox').style.top=((dimensions.windowHeight-$('lightbox').offsetHeight)/2)+'px';$('lightbox').style.left=((dimensions.windowWidth-$('lightbox').offsetWidth)/2)+'px'},hide:function(){$('lbox-overlay').style.display='none';$('loading_img').style.display='none';$('lightbox').style.display='none';$$('#lightbox img')[0].setAttribute('src','')},getPageDimensions:function(){var pageWidth=0,pageHeight=0;if(document.documentElement){if(document.documentElement.scrollHeight>document.documentElement.offsetHeight)pageHeight=document.documentElement.scrollHeight;else pageHeight=document.documentElement.offsetHeight}else if(document.body){if(document.body.scrollHeight>document.body.offsetHeight)pageHeight=document.body.scrollHeight;else pageHeight=document.body.offsetHeight}if(document.documentElement){if(document.documentElement.scrollWidth>document.documentElement.offsetWidth)pageWidth=document.documentElement.scrollWidth;else pageWidth=document.documentElement.offsetWidth}else if(document.body){if(document.body.scrollWidth>document.body.offsetWidth)pageWidth=document.body.scrollWidth;else pageWidth=document.body.offsetWidth}var windowWidth=0,windowHeight=0;if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight}if(pageHeight<windowHeight)pageHeight=windowHeight;if(pageWidth<windowWidth)pageWidth=windowWidth;return{windowWidth:windowWidth,windowHeight:windowHeight,pageWidth:pageWidth,pageHeight:pageHeight}}};
