// EXCURSIONS

function showHide(theId) {

	var i;
	
	for (i=1; i<=5; i++) {
	
		document.getElementById('ex_'+i).style.display = 'none';
		//document.getElementById('ex_img_'+i).setAttribute('class','faderbox');
	
	}
	
	document.getElementById(theId).style.display = 'block';
	//document.getElementById(theId).setAttribute('class','faderbox active');
	
}

// SLIDESHOW

function slideshowOn(theImages) {

	slide=0;
	theImagesArray = theImages.split(',');
	
	// PRELOAD THE IMAGES
	
	for (x in theImagesArray) {
	
		thePreloads = new Image();
		thePreloads.src = theImagesArray[x];
		
	}

	// CHECK IF MSIE <= v6

	if (slideshowCheckBrowser()) {
	
		slideshowWindow = window.open('','slideshowWindow','toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=yes,directories=no,width=400,height=300,left=100,top=100');
		slideshowWindow.focus();
		
		slideshowWindow.document.write('<html><head><title>Slideshow<\/title><\/head><body style="margin:0;"><\/body><\/html>');
		
		slideshowBoring();
		slideshow = setInterval('slide++;slideshowBoring();',5000);
	
	} else {

		document.body.innerHTML += '<div id="slideshow_background" onClick="slideshowOff()"><\/div>';
		document.body.innerHTML += '<div id="slideshow_foreground"><\/div>';
		document.body.innerHTML += '<div id="slideshow_close" onClick="slideshowOff()"><\/div>';
	
		document.getElementById('slideshow_background').style.visibility = 'visible';
	
		slideshowLoop(theImagesArray[slide]);
		slideshow = setInterval('slide++;slideshowLoop();',5000);

	}

}

function slideshowBoring() {
		
	if (slide < theImagesArray.length) { slideshowWindow.document.body.innerHTML = '<img src="'+theImagesArray[slide]+'" id="slideshow_image" onload="window.resizeTo(this.width,this.height+20);" onerror="alert(\'error\')">'; }
	else { clearInterval(slideshow); slideshowWindow.close(); }
}

function slideshowLoop() {

	slideshowUnloadImage();

	if (slide < theImagesArray.length) { document.getElementById('slideshow_foreground').innerHTML = '<img src="'+theImagesArray[slide]+'" id="slideshow_image" onload="slideshowLoadImage()" onerror="alert(\'error\')">'; }
	else { slideshowOff(); }

}

function slideshowLoadImage() {  
	
	var posLeft = (slideshowInnerWidth() - document.getElementById('slideshow_image').width)/2;
	var posTop = (slideshowInnerHeight() - document.getElementById('slideshow_image').height)/2;

	document.getElementById('slideshow_foreground').style.left = ''+ posLeft +'px';
	document.getElementById('slideshow_foreground').style.top = ''+ posTop +'px';
	
	document.getElementById('slideshow_close').style.left = ''+ (posLeft - 15) +'px';
	document.getElementById('slideshow_close').style.top = ''+ (posTop - 12) +'px';
	
	document.getElementById('slideshow_foreground').style.visibility = 'visible';
	document.getElementById('slideshow_close').style.visibility = 'visible';
	
}

function slideshowUnloadImage() {

	document.getElementById('slideshow_foreground').style.visibility = 'hidden';
	document.getElementById('slideshow_close').style.visibility = 'hidden';

}

function slideshowOff() {

	clearInterval(slideshow);

	document.getElementById('slideshow_foreground').style.visibility = 'hidden';
	document.getElementById('slideshow_close').style.visibility = 'hidden';
	document.getElementById('slideshow_background').style.visibility = 'hidden';
	document.getElementById('slideshow_foreground').innerHTML = '';

}

function slideshowInnerWidth() {

	if (self.innerWidth) return self.innerWidth; 
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	else if (document.body) return document.body.clientWidth;

}

function slideshowInnerHeight() {

	if (self.innerHeight) return self.innerHeight; 
	else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	else if (document.body) return document.body.clientHeight;

}

function slideshowCheckBrowser() {

	var browser=navigator.appVersion;

	if (browser.match('MSIE 6') || browser.match('MSIE 5') || browser.match('MSIE 4')) return true;
	else return false;

}

// OTHER

function setOpacity(obj,opacity) {

	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;

}

function fadeIn(objId,opacity) {

	if (document.getElementById) {
	
		obj = document.getElementById(objId);

		if (opacity <= 100) {

			setOpacity(obj, opacity);
			opacity += 10;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);

		}

	}

}
