/*
	Lightbox scripting -- use with lightbox.css
	Made for SoundWaters Camp Image Gallery by Vlad Ionescu
	2009
*/

/*
	To use, make anchor tags in HTML with href="javascript:void(0);" and onClick="toggleLightbox(imagePath, caption);"
	Make sure there is an element (preferably the header/title) with id="title" and the contents being "Week x". Replace x with the corresponding week number.
*/
function resetOp() {
	document.getElementById('dark').style.opacity = 0.0;
	document.getElementById('dark').style.MozOpacity = 0.0;
	document.getElementById('dark').style.filters = "alpha(opacity=0)";
}

function fadein(alphaWhole) {
	var d = document.getElementById('dark');
	
	if (alphaWhole == null) {
		alphaWhole = 0;
	}
	
	if (alphaWhole < 75) {
		d.style.opacity = alphaWhole/100;
		d.style.MozOpacity = alphaWhole/100;
		d.style.filters = "alpha(opacity=" + alphaWhole + ")";
		
		alphaWhole += 5;
		
		window.setTimeout("fadein(" + alphaWhole + ")", 10);
	} else {
		alphaWhole = 70;
	}
}

function fadeout(alphaA) {
	var d = document.getElementById('dark');
	var l = document.getElementById('light');

	if (alphaA == null) {
		alphaA = 70;
	}

	if (alphaA === 0) {
		d.style.display='none';
		l.style.display='none';	
	} else {	
		d.style.opacity = alphaA/100;
		d.style.MozOpacity = alphaA/100;
		d.style.filters = "alpha(opacity=" + alphaA + ")";
		
		alphaA -= 5;
		
		window.setTimeout("fadeout(" + alphaA + ")", 10);
	}
}

function toggleLightbox(imagePath, caption) {
	var d = document.getElementById('dark');
	var l = document.getElementById('light');

	if (d.style.display != 'block' && l.style.display != 'block') {
		if (caption == null && imagePath != null) {
			caption = "Camp week " + document.getElementById('title').innerHTML.substring(4) + ", image #" + imagePath.substr((imagePath.length - 6), 2);
		} else if (caption == null && imagePath == null) {
			caption = "SoundWaters lightbox design and coding by Vlad I, 2009";
			imagePath = '/picture na.jpg';
		} else {
			caption = "n/a";
			imagePath = '/picture na.jpg';
		}
		document.getElementById('lightCaption').innerHTML = caption;
		document.getElementById('imageLarge').setAttribute('src', imagePath);
		resetOp();
		d.style.display='block';
		fadein();
		window.setTimeout("document.getElementById('light').style.display='block'", 200);
	} else {
		fadeout();

	}
}
