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


var lightboxFadeStep=7;
var img1;
var oldImg;
var imgWidth=0;
var imgWidthStep=400;

/* Lightbox wird initialisiert */

function lightboxInit(){
	document.write('<div id="lightboxBg">&nbsp;</div><div 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){
	
	
	//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";
		document.getElementById('lightboxContent').style.width='600px';	
	
		img1 = new Image(); 
		img1.src = img;
	}
	else
	{
		lightboxResize(img1.width,(img1.width-100));
		document.getElementById('lightbox').style.display='block';
		document.getElementById('lightboxBg').style.display='block';
	}
	
	/* Wartet bis das Bild geladen wurde */
	
	img1.onload=function(){
			document.getElementById('lightboxDescription').innerHTML=description;
			document.getElementById('lightboxImage').src=img;			
			document.getElementById('lightboxContent').style.width=img1.width+'px';	
			
			document.getElementById('lightbox').style.display='block';
			document.getElementById('lightboxBg').style.display='block';
			
			/* DER FADER */
			lightboxResize(img1.width,(img1.width-100));
			lightboxFader=lightboxFade(0);
			
	}

	oldImg=img;

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

lightboxInit();
