/* general variables */

var galleryId = 'gallery'; /* change this to the ID of the gallery list */
var	gallery; /* this will be the object reference to the list later on */
//var galleryImages; /* array that will hold all child elements of the list */
var currentImage; /* keeps track of which image should currently be showing */
var previousImage;
//preInit();

/* functions */

function preInit() {

	/* an inspired kludge that - in most cases - manages to initially hide the image gallery list
	   before even onload is triggered (at which point it's normally too late, and the whole list already
	   appeared to the user before being remolded) */
	if ((document.getElementById)&&(gallery=document.getElementById(galleryId))) {
		gallery.style.visibility = "hidden";
		clearTimeout(preInitTimer);
	} else {
		preInitTimer = setTimeout("preInit()",2);
	}
}





function fader(imageNumber,opacity) {
	/* helper function to deal specifically with images and the cross-browser differences in opacity handling */
	var obj=galleryImages[imageNumber];
	if (obj.style.MozOpacity!=null) {
		/* Mozilla's pre-CSS3 proprietary rule */
		obj.style.MozOpacity = (opacity/100) - .001;
	} else if (obj.style.opacity!=null) {
		/* CSS3 compatible */
		obj.style.opacity = (opacity/100) - .001;
	} else if (obj.style.filter!=null) {
		/* IE's proprietary filter */
		obj.style.filter = "alpha(opacity="+opacity+")";
	}
}

function fadeInit() {
	if (document.getElementById) {
		preInit(); /* shouldn't be necessary, but IE can sometimes get ahead of itself and trigger fadeInit first */
		/* get all child nodes...yes, lazy, as i should really check that they're the "proper" type
		of child nodes (i.e. filter out duff text only nodes, such as white space) */
		galleryImages = gallery.childNodes;
		for(i=0;i<galleryImages.length;i++) {

			/* loop through all these child nodes and set up their styles */
			galleryImages[i].style.position='absolute';
			galleryImages[i].style.top=0;
			galleryImages[i].style.zIndex=0;

			/* set their opacity to transparent */
			fader(i,0);
		}
		/* make the list visible again */
		gallery.style.visibility = 'visible';
		/* initialise a few parameters to get the cycle going */
		currentImage=0;
		previousImage=galleryImages.length-1;
		opacity=100;
		fader(currentImage,100);
		/* start the whole crossfade process after a second's pause */
		window.setTimeout("crossfade(100)", 1000);
	}
}

function crossfade(opacity) {
		if (opacity < 100) {
			/* current image not faded up fully yet...so increase its opacity */
			fader(currentImage,opacity);
			/*Added so as to fade out previous*/
			fader(previousImage,100-opacity);
			/* fader(previousImage,100-opacity); */
			opacity += 3; /* was 10 */
			window.setTimeout("crossfade("+opacity+")", 80);  /* wae 30 */
		} else {
			/* make the previous image - which is now covered by the current one fully - transparent */
			fader(previousImage,0);
			/* current image is now previous image, as we advance in the list of images */
			previousImage=currentImage;
			currentImage+=1;
			if (currentImage>=galleryImages.length) {
				/* start over from first image if we cycled through all images in the list */
				currentImage=0;
			}
			/* make sure the current image is on top of the previous one */
			galleryImages[previousImage].style.zIndex = 0;
			galleryImages[currentImage].style.zIndex = 100;
			/* and start the crossfade after a second's pause */
			opacity=0;
			window.setTimeout("crossfade("+opacity+")", 3000);
		}

}

/* initialise fader by hiding image object first
addEvent (window,'load',fadeInit)
 Added to cope with back
addEvent (window,'reload',fadeInit) */


//-->

  //SlideShows
var
   previousSlideShow;
var
  currentSlideShow;

// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 2000

// Duration of crossfade (seconds)
var crossFadeDuration = 2

// Specify the image files
//var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

/*
Pic[0] = 'assets/boris.jpg'
Pic[1] = 'assets/siren.gif'
Pic[2] = 'assets/rustam.jpg'
Pic[3] = 'assets/malmo.jpg'
Pic[4] = 'assets/fishes.jpg'
Pic[5] = 'assets/ouls2.jpg'
Pic[6] = 'assets/access.jpg'
Pic[7] = 'assets/tatetoursanimated.gif'
Pic[8] = 'assets/rys0.gif'
Pic[9] = 'assets/barney.jpg'
*/


// =======================================
// do not edit anything below this line
// =======================================

var t
var j = 0
var lastj = 0
/*var picArrayLength = Pic.length*/
var loop = 0;

/*
var galleryImages = new Array()

for (i = 0; i < picArrayLength; i++){
   galleryImages[i] = new Image();
   galleryImages[i].src = Pic[i];
   galleryImages[i].title = Titles[i];
}

*/


function preInitObj() {

	/* an inspired kludge that - in most cases - manages to initially hide the image gallery list
	   before even onload is triggered (at which point it's normally too late, and the whole list already
	   appeared to the user before being remolded) */
	if ((document.getElementById)&&(gallery=document.getElementById(SlideShow1))) {
		document.getElementById(SlideShow1).style.visibility = "hidden";
		clearTimeout(preInitTimer);
	} else {
		preInitTimer = setTimeout("preInit()",2);
	}
}


function fadeInitObj() {

//preInitObj();

		/* initialise a few parameters to get the cycle going */
		currentImage=0;
		previousImage=galleryImages.length-1;
		Objfader(document.images.SlideShow1,0);
  		previousSlideShow=document.images.SlideShow1;
  		currentSlideShow=document.images.SlideShow2;
		currentSlideShow.src = galleryImages[0].src;

		opacity=100;

		//Objfader(document.images.SlideShow1,100);
		/* start the whole crossfade process after a second's pause */
		window.setTimeout("crossfadeObj(100)", 1000);

}

function crossfadeObj(opacity) {
		if (opacity < 100) {
			/* current image not faded up fully yet...so increase its opacity */
			Objfader(currentSlideShow,opacity);
			/*Added so as to fade out previous*/
			Objfader(previousSlideShow,100-opacity);
			/* fader(previousImage,100-opacity); */
			opacity += 3; /* was 10 */
			window.setTimeout("crossfadeObj("+opacity+")", 80);  /* wae 30 */
		} else {
			/* make the previous image - which is now covered by the current one fully - transparent */
			Objfader(previousSlideShow,0);
			/* current image is now previous image, as we advance in the list of images */
			previousImage=currentImage;
			storeSlideShow=previousSlideShow;
			previousSlideShow=currentSlideShow;
			currentSlideShow=storeSlideShow;

			currentImage+=1;
			if (currentImage>=galleryImages.length) {
				/* start over from first image if we cycled through all images in the list */
				currentImage=0;
			}
			/* make sure the current image is on top of the previous one */

			previousSlideShow.style.zIndex = 0;
			currentSlideShow.style.zIndex = 100;

			currentSlideShow.src = galleryImages[currentImage].src;

			/* and start the crossfade after a second's pause */
			opacity=0;
			window.setTimeout("crossfadeObj("+opacity+")", 2000);
		}

}

function runSlideShow(){

 fadeInitObj();
}

