// JavaScript Document
<!--

/*****************************************************************************************

	Fading Slideshow with Multi-Browser Support
	
	Written By :  F. Robert Honeyman
	Version :  0.8 build 2007.02.22.1
	History :
		0.1 ~ opacity fades in firefox
		0.2 ~ multi browser design, description array support
		0.3 ~ function based loop structure
		0.4 ~ first/last/next/previous controls
		0.5 ~ slide to image number support, improved execution speed
		0.6 ~ stable play/pause controls, playdelay and desc patches
		0.7 ~ picture links array support
		0.8 ~ improved processing efficiency via auto quality

******************************************************************************************



	Usage - add the folowing into the head of the html or php file:
	
			<script type="text/javascript" language="javascript" src="slideshow.js"></script>
			<script type="text/javascript" language="javascript">
			<!--
			
				play = false;
				fadetime = 1;
				slidedelay = 1;
				slideimages = Array(
						"../../gallery/summer-trip-to-colorado-2003/01_just-before.jpg",
						"../../gallery/summer-trip-to-colorado-2003/02_photo-of-gro.jpg",
				slidedesc = Array(
						"just before leaving",
						"photo of the group",
				slidelink = Array(
						"../../gallery/summer-trip-to-colorado-2003/",
						"../../gallery/summer-trip-to-colorado-2003/");
			
			//-->
			</script>
	
	
	
	and the folowing to the body tag:
	
			<body onload="slideshow()">
	
	
	
	and the folowing into the body:
	
			<div id="ss_bkimg" align="center" style="height:500px; width:750px; background-position: top center; background-repeat:no-repeat;"><img id="ss_frimg" name="ss_frimg" src="../../gallery/loading_bk.gif" alt="" style="filter:alpha(opacity=100);" onClick="popuplink()"/></div>
	
	
	
	and optionally adding the folowing if you use descriptions anywhere in the body:
	
			<div id="ss_desc" style="color:#FFFFFF">&nbsp;</div><br>
	
	
	
	and optionally adding the folowing if you use controls anywhere in the body:
	
			<input name="First" type="button" value="First" onClick="slideto('first')">
			<input name="Previous" type="button" value="Previous" onClick="slideto('previous')">
			<input name="Play" type="button" value="Play" onClick="slideshow('play')">
			<input name="Pause" type="button" value="Pause" onClick="slideshow('pause')">
			<input name="Next" type="button" value="Next" onClick="slideto('next')">
			<input name="Last" type="button" value="Last" onClick="slideto('last')"><br>
		
			<span onMouseOver="slideto('0')">Image number 0</span><br>
			<span onMouseOver="slideto('1')">Image number 1</span><br>




*****************************************************************************************/







// Defaults, user editable.
	var play = false;  // true if play is turned on after load
	var fadetime = 10;  // fade time in tenths of a second
	var slidedelay = 5;  // delay between slide fades in seconds
	var imgindex = 0;  // first image to display on load
	var playdelay = false  // true if play button starts play after slide delay
	var slideimages = new Array();  // image path list
	var slidedesc = new Array();  // image description list
	var slidelink = new Array();  // image url link list
	var windowattrib =  'width=800, height=570,'  // new window attributes
	    windowattrib += 'resizable=yes, scrollbars=yes,'  // new window attributes
	    windowattrib += 'toolbar=yes, copyhistory=yes,'  // new window attributes
	    windowattrib += 'menubar=yes, directories=yes,'  // new window attributes
	    windowattrib += 'location=yes, status=yes'  // new window attributes


// Browser identification variables.
	var nua = navigator.userAgent;
	var op = (nua.indexOf('Opera')!=-1);
	var saf = (nua.indexOf('Safari')!=-1);
	var konq = (!saf && (nua.indexOf('Konqueror')!=-1) );
	var moz = ( (!saf && !konq) && (nua.indexOf('Gecko')!=-1) );
	var ie = (document.getElementById && (nua.indexOf('MSIE')!=-1) && !op);

// General presets, not user editable.
	var step = -3;
	var busy = true;
	var reflip = false;
	var buffer = 100;
	var downtime = 50;
	var quality = 4;
	var frImg = null;
	var bkImg = null;
	var delaysteps = 0;
	var desc = false;
	var linkactive = false;


// Root initializer function and play/pause controller. 
	function slideshow(command) {
		if (command=='play') {
			reflip = true;
			play = true;
			if (!playdelay) slideto('next');
		}
		else if (command == 'pause') {
			play = false;
		}
		// initialize slideshow
		else {
			for (i=0; i<slideimages.length; i++) {
				MM_preloadImages(slideimages[i]);
			}
			frImg = MM_findObj('ss_frimg');
			bkImg = MM_findObj('ss_bkimg');
			if (MM_findObj('ss_desc') && slidedesc.length>0) desc = true;
			if (fadetime<0 || fadetime>50) fadetime = 10;
			if (fadetime < 5) quality = 10;
			else if (fadetime < 15) quality = 4;
			else if (fadetime < 35) quality = 2;
			else quality = 1;
			if (slidedelay<0 || slidedelay>3600) slidedelay = 5;
			delaysteps = (1000/downtime)*slidedelay;
			windowattrib = windowattrib.replace(/[ \t\n\r\v\0]/g, "");
			bkImg.style.backgroundImage = "url("+frImg.src+")";
			setTimeout('flipimage()', buffer);
		}
	}


// Main executing slide loop function.
	function flipimage() {
		// Rearange image layers during -3 to -2.
		if (step == -3) {
			fadeto(0)
			step++;
			setTimeout('flipimage()', buffer);
		} else if (step ==  -2) {
			frImg.src = slideimages[imgindex];
			busy = true;
			step++;
			setTimeout('flipimage()', buffer);
		}
		
		// Fade in new image during step -1.
		else if (step == -1) {
			if (desc) setTimeout('updatedesc()', 10*fadetime);
			setTimeout('updatelink()', 10*fadetime);
			if (fadetime > 0) {
				for (i=quality; i<=100; i+=quality) {
					setTimeout('fadeto('+i+')', i*fadetime);
				}
			} else {
				fadeto('100');
			}
			step++;
			setTimeout('flipimage()', 100*fadetime+buffer);
		}
		
		// Reset the background image.
		else if (step == 0) {
			bkImg.style.backgroundImage = "url("+frImg.src+")";
			step++;
			setTimeout('flipimage()', buffer);
		}

		// Create downtime between images if needed.
		else if ( (step<=delaysteps || !play) && !reflip) {
			step++;
			setTimeout('flipimage()', downtime);
		}
		
		// Get next image and repeat.
		else {
			if (!reflip) slideto('next');
			busy = false;
			reflip = false;
			step = -3;
			flipimage();
		}
	}


// Update description div text.
	function updatedesc() {
		if (slidedesc[imgindex] == '') text = '&nbsp;';
		else text = slidedesc[imgindex];
		MM_setTextOfLayer('ss_desc','',text);
	}


// Update image link.
	function updatelink() {
		if (slidelink[imgindex]) {
			linkactive = true;
			frImg.style.cursor = "pointer";
		} else {
			linkactive = false;
			frImg.style.cursor = "default";
		}
	}


// Change the front image opacity to a value.
	function fadeto(opcty) {
		frImg.style.opacity = opcty/100;
		if (moz) frImg.style.MozOpacity = opcty/100;
		if (saf||konq) frImg.style.KhtmlOpacity = opcty/100;
		if (ie) frImg.filters['alpha'].opacity = opcty;
	}


// Change the front image opacity to a value.
	function popuplink() {
		if (linkactive) window.open(slidelink[imgindex],'',windowattrib);
	}


// User interupt handeler and next index generator.
	function slideto(command) {
		if (busy) reflip = true;
		if (command == parseInt(command,10)) {
			imgindex = command;
			if (imgindex >= slideimages.length) imgindex = slideimages.length-1;
		}
		else if (command == 'previous') {
			imgindex--;
			if (imgindex < 0) imgindex = slideimages.length-1;
		}
		else if (command == 'first') {
			imgindex = 0;
		}
		else if (command == 'last') {
			imgindex = slideimages.length-1;
		}
		else {
			imgindex++;
			if (imgindex >= slideimages.length) imgindex = 0;
		}
	}

//-->
