// JavaScript Document


var DHTML = (document.getElementById || document.all || document.layers);
if ( !DHTML ) alert('Your browser is not capable of displaying DHTML');

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else
	if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else
	if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}




slides = new Array( // The id's of the slides
	'slide0',
	'slide1',
	'slide2',
	'slide3',
	 'slide4',
	 'slide5',
	 'slide6',
	 'slide7',
	 'slide8',
	 'slide9',
	 'slide10',
	 'slide11',
	 'slide12',
	 'slide13');
	
var curImg = 0; // index of the array entry
var lastImg = 0;

//document.writeln(lastImg+", here I am.");

function slideshow(){
	//document.writeln("<h1>"+lastImg+", here I am.</h1>");
   	visib(slides[slides.length-1], false);
	visib(slides[0], true);
   setInterval("changeSlide()",9000);
}

function changeSlide() {
	if (!DHTML) return;
	//curImg += change;
	//document.writeln(lastImg+", here I am.");
	curImg = (curImg + 1) % slides.length;
	lastImg = (curImg - 1) % slides.length;
	
	if ( lastImg < 0) lastImg = slides.length-1;
	
	//if ( curImg < 0 ) curImg = slides.length-1;
	//else
	//	if ( curImg >= slides.length ) curImg = 0;
	//if ( fadeOn ) {
	//	firstFade = true;
	//	prepLyr(slides[lastImg], true );
	//	fadeLayer(slides[lastImg], 10, 50);
	//} else {
	
		visib(slides[lastImg], false);
		visib(slides[curImg], true);
		
	//}
	//lastImg = curImg;
}

function visib(objName, flag) {
	x = new getObj(objName);
	x.style.visibility = (flag) ? 'visible' : 'hidden';
}


var fadeOn = false;
function setFade(switchFade) {// Fade switch function
	if ( !fadeOn ) {
		prepLyr(slides[curImg], true);
		} else { // No fade
		stopFade();
		for ( var i = 0; i < slides.length; i++ ) {
			prepLyr(slides[i], true);
			if ( slides[i] != slides[curImg] )
				visib(slides[i], false);
		}
	}
	fadeOn = switchFade;
}




var firstFade = true;
function nextFade() {
	firstFade = false;
	prepLyr(slides[curImg], false);
	fadeLayer(slides[curImg], -10, 50);
}

var clipTop = 0;
var clipWidth = 150;
var clipBottom = 0;
var lyrheight = 0;
var time,amount,theTime,middle;
var slideSize = new Array()

function prepLyr(lyr, vis) {
	if (!DHTML) return;
	x = new getObj( lyr );
	if (document.layers) {
		if ( !slideSize[lyr] ) {
			lyrheight = x.style.clip.bottom;
			clipWidth = x.style.clip.right;
			slideSize[lyr] = lyrheight + 'x' + clipWidth;
		} else {
			lyrheight = parseInt(slideSize[lyr]);
			clipWidth = slideSize[lyr].substr(slideSize[lyr].indexOf('x')+1);
		}
		if ( vis ) {
			clipTop = 0;
			middle = Math.round(lyrheight/2);
			clipBottom = lyrheight;
		} else {
			middle = Math.round(lyrheight/2);
			clipBottom = middle;
			clipTop = middle;
		}
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
		x.style.visibility = 'show';
	} else
	if (document.getElementById || document.all) {
		lyrheight = x.obj.offsetHeight;
		clipWidth = x.obj.offsetWidth;
		if ( vis ) {
			clipTop = 0;
			middle = Math.round(lyrheight/2);
			clipBottom = lyrheight;
		} else {
			middle = Math.round(lyrheight/2);
			clipBottom = middle;
			clipTop = middle;
		}
		x.style.clip = 'rect('+clipTop+' '+clipWidth+' '+ clipBottom +' 0)';
		visib(lyr, true);
	}
}

function fadeLayer(layername, amt, tim) {
	if (!DHTML) return;
	thelayer = new getObj( layername );
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realFade();
}

function stopFade() {
	if (time) clearTimeout(time);
}

function realFade() {
	clipTop += amount;
	clipBottom -= amount;
	if (clipTop < 0 || clipBottom > lyrheight || clipTop > middle) {
		if ( clipTop > middle ) thelayer.style.visibility = 'hidden';
		if ( firstFade ) nextFade();
		return;
	}
	if (document.getElementById || document.all) {
		clipstring = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' 0)'
		thelayer.style.clip = clipstring;
	}	else
	if (document.layers) {
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
	}
	time = setTimeout('realFade()',theTime);
}


