/* general variables */


//var galleryId = 'cimg'; /* change this to the ID of the gallery list */
//var	gallery; /* this will be the object reference to the list later on */
var imageList; /* array that will hold all child elements of the list */
var tagList;
var txtList;
var numObjects;
var currentNum; /* keeps track of which image should currently be showing */
var previousNum;
var preInitTimer;
//preInit();

function fadeObj(obj,opacity) {
	if (obj.style) {
		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 fader(num,opacity) {
	// helper function to deal specifically with images and the cross-browser differences in opacity handling 
	fadeObj(imageList[num],opacity);
	fadeObj(tagList[num],opacity);
	fadeObj(txtList[num],opacity);
}


function fadeInit(numObjs) {
	numObjects = numObjs;
	if (document.getElementById) {

		imageList = new Array;
		tagList = new Array;
		txtList = new Array;
		for(i=0;i<numObjects;i++) {
			tagList[i] = document.getElementById('ctag'+i);
			txtList[i] = document.getElementById('ctxt'+i);
			imageList[i] = document.getElementById('cimg'+i);
			fader(i,0);
			imageList[i].style.visibility = "visible";
			tagList[i].style.visibility = "visible";
			txtList[i].style.visibility = "visible";
		}

		/* initialise a few parameters to get the cycle going */
		currentNum=0;
		previousNum=numObjects-1;
		opacity=100;
		fader(currentNum,100);
		/* start the whole crossfade process after five seconds pause */
		window.setTimeout("crossfade(100)", 1000);
	}
}

function crossfade(opacity) {
		if (opacity <= 100) {
			fader(currentNum,opacity);
			fader(previousNum,100-opacity);
			opacity += 5;
			window.setTimeout("crossfade("+opacity+")", 30);
		} else {
			/* make the previous image - which is now covered by the current one fully - transparent */
			fader(previousNum,0);
			/* current image is now previous image, as we advance in the list of images */
			previousNum=currentNum;
			currentNum+=1;
			if (currentNum>=numObjects) {
				/* start over from first image if we cycled through all images in the list */
				currentNum=0;
			}
			/* make sure the current image is on top of the previous one */
			imageList[previousNum].style.zIndex = 0;
			imageList[currentNum].style.zIndex = 100;
			/* and start the crossfade after a second's pause */
			opacity=0;
			window.setTimeout("crossfade("+opacity+")", 6500);
		}
		
}
