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


var lightboxFadeStep=5;
var img1;
var oldImg;
var imgWidth=0;
var imgWidthStep=200;
var shut=true;
var viewed=new Array();
var navigation;

var imgWidthStep_default=40;
var imgWidthStep_default_start=50;

if(!images)
{
	var images = new Array;
}

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;
}

function in_array(item,arr) {
	for(p=0;p<arr.length;p++) if (item == arr[p]) return true;
	return false;
}


/* Lightbox wird initialisiert */

function lightboxInit(){
	document.write('<div  onclick="lightboxHide()" id="lightboxBg"></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 lightboxResizeOnce(imgWidth){
	document.getElementById('lightboxImage').style.width=imgWidth+'px';		
}


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


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

function lightboxShow(img,description,index){
	
	
	document.style='overflow: hidden;';
	
	//alert(img);
	
	/* Wenn das Bild zuletzt auch aufgerufen wurde, 
	wird es einfach wieder eingeblendet und muss nicht neu geladen werden */
	
	if (!in_array(img,viewed)){
		//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
	{
		img1.src = img;
		lightboxResize(img1.width,imgWidthStep_default_start);
		lightboxFader=lightboxFade(30);
		//document.getElementById('lightbox').style.display='block';
		//document.getElementById('lightboxBg').style.display='block';
	}
	
	/* Wartet bis das Bild geladen wurde */
	
	img1.onload=function(){
			
			viewed[viewed.length+1]=img;
			
			if (images.length>1){
				newpic=index+1;
				oldpic=index-1;
				navigation=true;
				navigation='<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>';
			}
			
			else
			{
				navigation='';
			}
			
			if (document.getElementById('lightboxDescription')){
				document.getElementById('lightboxDescription').innerHTML=description+' '+navigation;
				document.getElementById('lightboxImage').src=img;			
				document.getElementById('lightboxContent').style.width=img1.width+'px';	
				
							
			sizee=new Array();
			sizee=getSize();
			//alert(sizee['hoehe']);
			
			document.getElementById('lightboxContent').style.left=(sizee['breite']/2)-(img1.width)/2+'px';
			document.getElementById('lightboxContent').style.top=100+'px'

			
			
			
			document.getElementById('lightbox').style.display='block';
			document.getElementById('lightboxBg').style.display='block';
			}
			/* DER FADER */
			
			
			lightboxResize(img1.width,imgWidthStep_default_start);
			lightboxFader=lightboxFade(20);
			
	}
	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';
		document.getElementById('lightboxImage').src='plugin/lightbox/images/blank.gif';
	}

}



function lightboxNext(index){

	lightboxResizeOnce(imgWidthStep_default_start);

	if ((index+1)<=images.length && index>=0){
		document.getElementById('lightboxContent').style.width=(0)+'px';
		setOpacity('lightboxContent',0); 	
		
		document.getElementById('lightbox').style.display='';
		document.getElementById('lightboxImage').src='plugin/lightbox/images/blank.gif';
		
		shut=false;
		if (!images[index]['description']){
			images[index]['description']="";
		}
		
		lightboxShow(images[index]['link'],images[index]['description'],index)
	}
	else
	{
		document.getElementById('lightbox').style.display='';
		document.getElementById('lightboxBg').style.display='';
		shut=true;	
		lightboxHide();
	}
//alert('Sie haben das Bild '+images[index]['link']+' aufgerufen.');	
}


lightboxInit();
