/*######################################*/
/*  lightbox - nicolas stey 22.11.2007  */
/*######################################*/


var lightboxFadeStep=4;
var img1;
var oldImg;
var imgWidth=0;
var imgWidthStep=400;
var shut=true;



function getSize() { 
	sizes=new Array();
	if (navigator.appName=='Netscape' && navigator.appVersion.charAt(0)>='4')
	{ 
		sizes['hoehe']=innerHeight;
		sizes['breite']=innerWidth;
	}
	if (navigator.appName=='Microsoft Internet Explorer' && navigator.appVersion.charAt(0)>='4')
	{ 
		sizes['hoehe']=document.body.clientHeight;
		sizes['breite']=document.body.clientWidth; 
	}
	return sizes;
}




/* Lightbox wird initialisiert */

function lightboxInit(){
	document.write('<div  onclick="lightboxHide()" id="lightboxBg">&nbsp;</div><div onmouseover="shut=true;" onclick="lightboxHide()" class="lightbox" id="lightbox"><div onclick="lightboxHide()" id="lightboxContent"><img id="lightboxImage" src="plugin/lightbox/images/blank.gif"><br><span id="lightboxDescription"></span></div></div>');
}

/* Setzt die Opacity in allen möglichen Browsern */

function setOpacity(ob, opacity) {
	var obj=document.getElementById(ob);
	opacity = (opacity == 100)?99.999:opacity; // IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")"; // Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;  // Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100; // Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}


/* Der Fader */

function lightboxResize(imgWidth,imgWidthStep){
	if (imgWidthStep<imgWidth){
		imgWidthStep=imgWidthStep+10;
		document.getElementById('lightboxImage').style.width=imgWidthStep+'px';	
		if (imgWidthStep<imgWidth){
			window.setTimeout('lightboxResize('+imgWidth+','+imgWidthStep+')',1);
		}
	}
}


function lightboxFade(lightboxAlpha){
	lightboxAlpha=lightboxAlpha+lightboxFadeStep;
	if (lightboxAlpha<100){
		setOpacity('lightboxContent', lightboxAlpha); 
		window.setTimeout('lightboxFade('+lightboxAlpha+','+imgWidth+')',lightboxFadeStep);
	}
}

function lightboxShow(img,description,index){
	
	
	//alert(img);
	
	/* Wenn das Bild zuletzt auch aufgerufen wurde, 
	wird es einfach wieder eingeblendet und muss nicht neu geladen werden */
	
	if (img!=oldImg){
		//alert(img);
		/* Das Bild wird auf den Ladebalken gesetzt und sobald geladen durch echten Bildpfad ersetzt */
		//document.getElementById('lightboxImage').src="plugin/lightbox/images/loading.gif";
		
	
		img1 = new Image(); 
		img1.src = img;
		document.getElementById('lightboxContent').style.width=(500)+'px';
	}
	else
	{
		lightboxResize(img1.width,(img1.width-100));
		lightboxFader=lightboxFade(0);
		
		document.getElementById('lightbox').style.display='block';
		document.getElementById('lightboxBg').style.display='block';
	}
	

	
	/* Wartet bis das Bild geladen wurde */
	
	img1.onload=function(){
			
			if (index>=0){
				newpic=index+1;
				oldpic=index-1;
				description=''+description+'<br><br><a href="#" onclick="lightboxNext(oldpic);"><img border="0" src="plugin/lightbox/images/pre.gif"></a> <a href="#" onclick="lightboxNext(newpic);"><img border="0" src="plugin/lightbox/images/next.gif"></a>';
			}
			
			document.getElementById('lightboxDescription').innerHTML=description;
			document.getElementById('lightboxImage').src=img;			
			document.getElementById('lightboxContent').style.width=img1.width+'px';	
			
			
			sizee=new Array();
			sizee=getSize();
			document.getElementById('lightboxContent').style.left=(sizee['breite']/2)-(img1.width)/2+'px';
			document.getElementById('lightboxContent').style.top=(sizee['hoehe']/2)-(img1.height)/2-70+'px';

			
			
			
			document.getElementById('lightbox').style.display='block';
			document.getElementById('lightboxBg').style.display='block';
			
			/* DER FADER */
			lightboxResize(img1.width,(img1.width-100));
			lightboxFader=lightboxFade(0);
			
	}
var scrollposition=document.documentElement.scrollTop; /* Liest die Scrollposition aus */
	
	if (scrollposition==0){
		scrollposition=document.body.scrollTop;
	}
	
	
	document.getElementById('lightbox').style.top=scrollposition+'px';
	oldImg=img;

}
function lightboxHide(){
	if (shut==true){
		document.getElementById('lightbox').style.display='none';
		document.getElementById('lightboxBg').style.display='none';
	}

}

function lightboxNext(index){
	
	
	if ((index+1)<=images.length && index>=0){
		setOpacity('lightboxContent',0); 	
		shut=false;
		lightboxShow(images[index]['link'],images[index]['description'],index)
	}
	else
	{
		shut=true;		
	}
//alert('Sie haben Bild Nummer '+images[nextpic]+' aufgerufen.');	
}


lightboxInit();