var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;

LightboxOptions=Object.extend({fileLoadingImage:'images/lightbox/loading.gif',fileBottomNavCloseImage:'images/modalBuddy/close.png',overlayOpacity:0.8,animate:true,resizeSpeed:10,borderSize:10,labelImage:"Bild",labelOf:"von"},window.LightboxOptions||{});var Lightbox=Class.create();Lightbox.prototype={imageArray:[],activeImage:undefined,initialize:function(){this.updateImageList();this.keyboardAction=this.keyboardAction.bindAsEventListener(this);if(LightboxOptions.resizeSpeed>10)LightboxOptions.resizeSpeed=10;if(LightboxOptions.resizeSpeed<1)LightboxOptions.resizeSpeed=1;this.resizeDuration=LightboxOptions.animate?((11-LightboxOptions.resizeSpeed)*0.15):0;this.overlayDuration=LightboxOptions.animate?0.2:0;var size=(LightboxOptions.animate?250:1)+'px';var objBody=$$('body')[0];objBody.appendChild(Builder.node('div',{id:'overlay'}));objBody.appendChild(Builder.node('div',{id:'lightbox'},[Builder.node('div',{id:'outerImageContainer'},Builder.node('div',{id:'imageContainer'},[Builder.node('img',{id:'lightboxImage'}),Builder.node('div',{id:'hoverNav'},[Builder.node('a',{id:'prevLink',href:'#'}),Builder.node('a',{id:'nextLink',href:'#'})]),Builder.node('div',{id:'loading'},Builder.node('a',{id:'loadingLink',href:'#'},Builder.node('img',{src:LightboxOptions.fileLoadingImage})))])),Builder.node('div',{id:'imageDataContainer'},Builder.node('div',{id:'imageData'},[Builder.node('div',{id:'imageDetails'},[Builder.node('span',{id:'caption'}),Builder.node('span',{id:'numberDisplay'})]),Builder.node('div',{id:'bottomNav'},Builder.node('a',{id:'bottomNavClose',href:'#'},Builder.node('img',{src:LightboxOptions.fileBottomNavCloseImage})))]))]));$('overlay').hide().observe('click',(function(){this.end();}).bind(this));$('lightbox').hide().observe('click',(function(event){if(event.element().id=='lightbox')this.end();}).bind(this));$('outerImageContainer').setStyle({width:size,height:size});$('prevLink').observe('click',(function(event){event.stop();this.changeImage(this.activeImage-1);}).bindAsEventListener(this));$('nextLink').observe('click',(function(event){event.stop();this.changeImage(this.activeImage+1);}).bindAsEventListener(this));$('loadingLink').observe('click',(function(event){event.stop();this.end();}).bind(this));$('bottomNavClose').observe('click',(function(event){event.stop();this.end();}).bind(this));var th=this;(function(){var ids='overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink '+'imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose';$w(ids).each(function(id){th[id]=$(id);});}).defer();},updateImageList:function(){this.updateImageList=Prototype.emptyFunction;document.observe('click',(function(event){var target=event.findElement('a[rel^=lightbox]')||event.findElement('area[rel^=lightbox]');if(target){event.stop();this.start(target);}}).bind(this));},start:function(imageLink){$$('select','object','embed').each(function(node){node.style.visibility='hidden'});var arrayPageSize=this.getPageSize();$('overlay').setStyle({width:arrayPageSize[0]+'px',height:arrayPageSize[1]+'px'});new Effect.Appear(this.overlay,{duration:this.overlayDuration,from:0.0,to:LightboxOptions.overlayOpacity});this.imageArray=[];var imageNum=0;if((imageLink.rel=='lightbox')){this.imageArray.push([imageLink.href,imageLink.title]);}else{this.imageArray=$$(imageLink.tagName+'[href][rel="'+imageLink.rel+'"]').collect(function(anchor){return[anchor.href,anchor.title];}).uniq();while(this.imageArray[imageNum][0]!=imageLink.href){imageNum++;}}
var arrayPageScroll=document.viewport.getScrollOffsets();var lightboxTop=arrayPageScroll[1]+(document.viewport.getHeight()/10);var lightboxLeft=arrayPageScroll[0];this.lightbox.setStyle({top:lightboxTop+'px',left:lightboxLeft+'px'}).show();this.changeImage(imageNum);},changeImage:function(imageNum){this.activeImage=imageNum;if(LightboxOptions.animate)this.loading.show();this.lightboxImage.hide();this.hoverNav.hide();this.prevLink.hide();this.nextLink.hide();this.imageDataContainer.setStyle({opacity:.0001});this.numberDisplay.hide();var imgPreloader=new Image();imgPreloader.onload=(function(){this.lightboxImage.src=this.imageArray[this.activeImage][0];this.resizeImageContainer(imgPreloader.width,imgPreloader.height);}).bind(this);imgPreloader.src=this.imageArray[this.activeImage][0];},resizeImageContainer:function(imgWidth,imgHeight){var widthCurrent=this.outerImageContainer.getWidth();var heightCurrent=this.outerImageContainer.getHeight();var widthNew=(imgWidth+LightboxOptions.borderSize*2);var heightNew=(imgHeight+LightboxOptions.borderSize*2);var xScale=(widthNew/widthCurrent)*100;var yScale=(heightNew/heightCurrent)*100;var wDiff=widthCurrent-widthNew;var hDiff=heightCurrent-heightNew;if(hDiff!=0)new Effect.Scale(this.outerImageContainer,yScale,{scaleX:false,duration:this.resizeDuration,queue:'front'});if(wDiff!=0)new Effect.Scale(this.outerImageContainer,xScale,{scaleY:false,duration:this.resizeDuration,delay:this.resizeDuration});var timeout=0;if((hDiff==0)&&(wDiff==0)){timeout=100;if(Prototype.Browser.IE)timeout=250;}
(function(){this.prevLink.setStyle({height:imgHeight+'px'});this.nextLink.setStyle({height:imgHeight+'px'});this.imageDataContainer.setStyle({width:widthNew+'px'});this.showImage();}).bind(this).delay(timeout/1000);},showImage:function(){this.loading.hide();new Effect.Appear(this.lightboxImage,{duration:this.resizeDuration,queue:'end',afterFinish:(function(){this.updateDetails();}).bind(this)});this.preloadNeighborImages();},updateDetails:function(){if(this.imageArray[this.activeImage][1]!=""){this.caption.update(this.imageArray[this.activeImage][1]).show();}
if(this.imageArray.length>1){this.numberDisplay.update(LightboxOptions.labelImage+' '+(this.activeImage+1)+' '+LightboxOptions.labelOf+'  '+this.imageArray.length).show();}
new Effect.Parallel([new Effect.SlideDown(this.imageDataContainer,{sync:true,duration:this.resizeDuration,from:0.0,to:1.0}),new Effect.Appear(this.imageDataContainer,{sync:true,duration:this.resizeDuration})],{duration:this.resizeDuration,afterFinish:(function(){var arrayPageSize=this.getPageSize();this.overlay.setStyle({height:arrayPageSize[1]+'px'});this.updateNav();}).bind(this)});},updateNav:function(){this.hoverNav.show();if(this.activeImage>0)this.prevLink.show();if(this.activeImage<(this.imageArray.length-1))this.nextLink.show();this.enableKeyboardNav();},enableKeyboardNav:function(){document.observe('keydown',this.keyboardAction);},disableKeyboardNav:function(){document.stopObserving('keydown',this.keyboardAction);},keyboardAction:function(event){var keycode=event.keyCode;var escapeKey;if(event.DOM_VK_ESCAPE){escapeKey=event.DOM_VK_ESCAPE;}else{escapeKey=27;}
var key=String.fromCharCode(keycode).toLowerCase();if(key.match(/x|o|c/)||(keycode==escapeKey)){this.end();}else if((key=='p')||(keycode==37)){if(this.activeImage!=0){this.disableKeyboardNav();this.changeImage(this.activeImage-1);}}else if((key=='n')||(keycode==39)){if(this.activeImage!=(this.imageArray.length-1)){this.disableKeyboardNav();this.changeImage(this.activeImage+1);}}},preloadNeighborImages:function(){var preloadNextImage,preloadPrevImage;if(this.imageArray.length>this.activeImage+1){preloadNextImage=new Image();preloadNextImage.src=this.imageArray[this.activeImage+1][0];}
if(this.activeImage>0){preloadPrevImage=new Image();preloadPrevImage.src=this.imageArray[this.activeImage-1][0];}},end:function(){this.disableKeyboardNav();this.lightbox.hide();new Effect.Fade(this.overlay,{duration:this.overlayDuration});$$('select','object','embed').each(function(node){node.style.visibility='visible'});},getPageSize:function(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else 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(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
return[pageWidth,pageHeight];}}
document.observe('dom:loaded',function(){new Lightbox();});

/*#######################################################################################################
Program written by Dominik Kressler
Project Name: 	modalBuddy
Version: 		1.1 RC3
Date: 			2010-08-07
#########################################################################################################
#########################################################################################################
REQUIREMTENS:
	Libraries:
		Prototype: 		1.6.1
		Scriptaculous: 	1.8.1
########################################################################################################*/

var frameResize = true;
var buildGallery = false;
var allMoveable = false;

var boxPadding = (boxPadding) ? Number(boxPadding) : 10;
var closeImage = (closeImage) ? closeImage : "images/modalBuddy/close.png";
var effectDuration = (effectDuration) ? Number(effectDuration) : 0.3;
var overlayOpacity = (overlayOpacity) ? Number(overlayOpacity) : 0.5;
var moveable = new Boolean();
var targets = new Array();
var targetSources = new Array();
var targetSource = new String();
var targetHeight = new Number();
var targetWidth = new Number();
var targetTitle = new String;
var boxWidth = new Number();
var boxHeight = new Number();
var typeOfCurrent = new String();
var image = new Image();
var source = new String();
var index = 1;

var modalBuddy = Class.create
({
	initialize:function()
	{
		insertOverlayInDOM();
		if(buildGallery) insertGallery();
		$$("a[rel=modalBuddy]").each
		(
			function(source)
			{
				sourceType = source.readAttribute('class');
				handleSRC(source,sourceType);
				if(allMoveable) source.addClassName('moveable');
				if(buildGallery) insertThumbnail(source, index);
				index++;
			}
		)
	}
});
var handleSRC=function(source,sourceType)
{
	$(source).observe('click', function(event)
	{
		Event.stop(event);	
		showLoader();
		targetSource = source.readAttribute('href');
		targetTitle = source.readAttribute('title');
		if (!targetSource.complete) {
			moveable = ($$('a.moveable') != "") ? true : false ;
			if ($(source).hasClassName('iframe') || $(source).hasClassName('iFrame')) openIframe(targetSource, targetTitle);
			else openImage(targetSource, targetTitle);
			typeOfCurrent = source;
		}
	});
}
var showLoader=function()
{
	$('modalLoader').appear({duration:0.1}).setStyle({
		top:imageY($('modalLoader').getHeight())+"px",
		left:imageX($('modalLoader').getWidth())+"px"
	});	
}
var insertOverlayInDOM=function()
{
	Event.stopObserving(window, 'load', modalBuddyInit);
	if(!$('modalLoader')) Element.insert(document.body, '<div id="modalLoader">Lade Daten...</div>');
	if(!$('modal'))
	{
		Element.insert(document.body, '<div id="modal"></div>');
		$("modal").insert(new Element("div", { id: "modalBox" })).insert(new Element("div", { id: "modalHead", style: "position:relative; padding:0 "+boxPadding+"px" }));
		$("modalHead").insert(new Element("img", { id: "modalHeadHandler", src: closeImage, style: "position:absolute;" })).insert(new Element("p", { id:"modalTitle", style: "width:90%; font-size:11px;" }));
		Element.insert(document.body, '<div id="modalOverlay"></div>');
	}
	$('modalLoader').setStyle
	({
	 	display:'none',
		top:'50%',
		left:'50%'
	});
	$('modalHeadHandler').setStyle
	({
		bottom: boxPadding +"px",
		right: boxPadding +"px"
	});
	$("modalTitle").setStyle
	({
		paddingBottom:boxPadding+"px",					 
		paddingTop:boxPadding+"px"
	});	
	$("modalOverlay").setStyle({display:'none'});
	$("modal").setStyle({display:'none'});
	$("modalBox").setStyle({padding: boxPadding+"px"});
	$("modalHead").setStyle
	({
		display:'none',
		minHeight:"25px"
	});
	$("modalHeadHandler").observe('click', modalKill);
}
var openIframe=function(targetSource, targetTitle)
{
	$('modalTitle').update(targetTitle);
	$('modalBox').insert(new Element("iframe", 
	{
		id: "modalContent",
		height: "100%",
		width: "100%",
		scrolling: "auto",
		src: targetSource,
		frameborder: "0"
	}));
	showOverlay();
	boxHeight=document.viewport.getHeight()-120;
	boxWidth=document.viewport.getWidth()-100;
	$("modalBox").setStyle
	({
		width:boxWidth+"px",
		height:boxHeight+"px"
	});
	$("modal").appear
	({
		from:0,
		to:1,
		afterFinish: function() { setHeader(boxWidth, boxHeight); $('modalLoader').setStyle({display:'none'}); },
		duration: 1.5
	}).setStyle
	({
		width:boxWidth + (boxPadding*2) +"px",
		height:boxHeight + (boxPadding*2) +"px",
		top:imageY(boxHeight + (boxPadding*2))-15+"px",
		left:imageX(boxWidth + (boxPadding*2))+"px"
	});
}
var openImage=function(targetSource, targetTitle)
{
	$('modalTitle').update(targetTitle);
	var image = new Image();
	image.src = targetSource;	
	$('modalBox').insert(new Element("img", {id: "modalContent",src: targetSource })).setStyle({width:"auto", height:"auto"});
	Event.observe(image, 'load', function(){
		showOverlay();
		$("modal").appear
		({
			to:1,
			afterFinish:function(){setHeader(targetWidth, targetHeight); $('modalLoader').setStyle({display:'none'});},
			duration:effectDuration
		}).setStyle
		({
			width:getImageWidth(targetSource) + (boxPadding*2)+"px",
			height:getImageHeight(targetSource) + (boxPadding*2) + 1 +"px",
			top:imageY(targetHeight)+window.pageYOffset+"px",
			left:imageX(targetWidth)+"px"
		});
	});
	if(buildGallery) 
	{
		thumbHandler();
		$('modalThumbnailList').childElements().each(function(elm){
			if(image.src == elm.firstDescendant().readAttribute('href'))
			{
				elm.firstDescendant().setStyle({height:'70px',width:'70px',margin:'5px 0 0 5px'});
				elm.setStyle({background:'#ccc'});
			}
		});
	}
}
var showOverlay=function()
{
	$("modalOverlay").appear
	({
		to:0.5,	
		duration: effectDuration
	}).setStyle
	({
		width:"100%",
		height:document.body.parentNode.scrollHeight+"px"
	});	
	if (moveable)
	{
		$('modal').addClassName('moveableBox');
		new Draggable('modal', 
		{
			onStart:function()
			{
				$('modalOverlay').fade({to:0.1,duration:effectDuration});
				if(buildGallery)$('modalThumbnails').fade({to:0.1,duration:effectDuration});
			},
			onEnd:function()
			{
				$('modalOverlay').fade({to:0.5,duration:effectDuration});
				if(buildGallery)$('modalThumbnails').fade({to:1,duration:effectDuration});
			}
		});	
	}
	$("modalOverlay").observe('click', modalKill);
	Event.observe(window, 'resize', resize);
}
var modalKill=function()
{
	Draggables.drags.each(function(draggable) { draggable.destroy(); } );
	$('modalOverlay').stopObserving('click', modalKill);
	Event.stopObserving(window, 'resize', resize);
	$("modalOverlay").fade
	({
		to:0,
		duration: effectDuration
	});
	$("modalHead").fade({
		to:0,
		duration: effectDuration
	});	
	$("modal").fade({
		to:0,
		duration: effectDuration,
		afterFinish:clearModalBox()
	});		
	$('modalLoader').setStyle({display:'none'});
	
	if ($('modal').hasClassName('moveableBox')) $('modal').removeClassName('moveableBox');
	if(buildGallery) $('modalThumbnails').fade({to:0,duration:effectDuration});
}

var insertGallery = function()
{	
	Element.insert(document.body, '<div id="modalThumbnails" style="display:none;"></div>');
	Element.insert('modalThumbnails', '<ul id="modalThumbnailList"></ul>');
}

var insertThumbnail = function(source,imageNum)
{
	thumbPath = source.firstDescendant().readAttribute('src');	
	thumbTitle = source.readAttribute('title');
	if(!$('modalThumbnailList'))Element.insert('modalThumbnailList', '<li><a id="modalThumb-'+imageNum+'" title="'+thumbTitle+'" href="'+source+'" class="modalGalleryThumb"><img width="80" height="80" src="'+thumbPath+'" /></a></li>');
}
var thumbHandler = function()
{
	showLoader();
	$('modalThumbnails').appear({duration:effectDuration});
	var thumbs = $('modalThumbnailList').childElements();
	thumbs.each(function(elm){
		elm.firstDescendant().setStyle({height:'80px',width:'80px',margin:'0'});
		elm.setStyle({background:'none'});
	});	
	$$('.modalGalleryThumb').each(function(modalGalleryThumb)
	{
		modalGalleryThumb.observe('click',function(event){
			Event.stop(event);
			$('modalHead').fade({to:0,duration:effectDuration});
			$('modal').fade(
			{
				duration:effectDuration,
				to:0,
				afterFinish:function()
				{
					clearModalBox(); 
					newNum=modalGalleryThumb.readAttribute('id').substr(11);
					openImage(modalGalleryThumb.readAttribute('href'),modalGalleryThumb.readAttribute('title'),newNum[0]);
				}
			});
		});
	});	
	multiplikator = $('modalThumbnailList').childElements().length;
	$('modalThumbnailList').setStyle({
		height:"80px",
		width:(multiplikator*80)+((multiplikator-1)*15)+"px"
	});
	$('modalThumbnails').setStyle({
		left:imageX($('modalThumbnails').getWidth())+"px"
	});
}

var clearModalBox=function (){$('modalContent').remove();image.src="";}
function getImageWidth(targetSource)
{
	var newImg=new Image();
	newImg.src=targetSource;
	targetWidth=newImg.width;
	if(newImg.complete)return parseInt(targetWidth);
}
var getImageHeight=function(targetSource)
{
	var newImg=new Image();
	newImg.src=targetSource;
	targetHeight=newImg.height;
	if(newImg.complete)return parseInt(targetHeight);
}
var imageX=function(targetWidth)
{
	var viewportHalf=Math.floor(document.viewport.getWidth())/2;
	var targetWidthHalf=parseInt(targetWidth)/2; 
	var imageX=viewportHalf-targetWidthHalf;
	return imageX;
}
var imageY=function(targetHeight)
{
	var imageY=Math.floor(document.viewport.getHeight())/2-targetHeight/2;
	var galleryheight=(buildGallery) ? 100 : 0 ;
	return imageY-galleryheight;
}
var setHeader=function(targetWidth,targetHeight)
{	
	$("modalHead").setStyle
	({
		width:parseInt(targetWidth)+"px",
		minHeight:"25px"
	}).appear({
		duration:0.3
	});
}
var resize=function()
{
	boxHeight = document.viewport.getHeight()-200;
	boxWidth = document.viewport.getWidth()-200;
	$("modalOverlay").setStyle({width:"100%",height:document.body.parentNode.scrollHeight+"px"});	
	if( ($(typeOfCurrent).hasClassName('iframe') || $(typeOfCurrent).hasClassName('iFrame')))
	{
		if(frameResize)
		{
			$("modalBox").setStyle
			({
				width:boxWidth+"px",
				height:boxHeight+"px"
			});
		
			$("modal").setStyle
			({
				width:boxWidth + (boxPadding*2) +"px",
				height:boxHeight + (boxPadding*2) +"px"
			});
			setHeader(boxWidth, boxHeight);
		}
		$("modal").setStyle
		({
			top:imageY(boxHeight)+window.pageYOffset+"px",
			left:imageX(boxWidth)+"px"
		});
	}
	else
	{
		$("modal").setStyle
		({
			top:imageY(targetHeight)+window.pageYOffset+"px",
			left:imageX(targetWidth)+"px"
		});	
	}
	if(buildGallery)
	{
		$('modalThumbnails').setStyle({
			left:imageX($('modalThumbnails').getWidth())+"px"
		});
	}
}

if(!modalBuddyInit)
{
	var modalBuddyInit = function(){modalBuddy = new modalBuddy();}
}
if (IE6 == false) Event.observe(window,'load',modalBuddyInit);
