/*Better(?) Image cross fader (C)2004 Patrick H. Lauke aka reduxInspired by Steve at Slayeroffice http://slayeroffice.com/code/imageCrossFade/ preInit "Scheduler" idea by Cameron Adams aka The Man in Bluehttp://www.themaninblue.com/writing/perspective/2004/09/29/ Tweaked to deal with empty nodes 19 Feb 2006*//* general variables */var galleryId = 'pinkbox'; /* 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 photoListId = 'photoItemsUl';var photoList;var photoItemsInList;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))&&(photoList=document.getElementById(photoListId))) {		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) {		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 */				galleryImages = new Array;		photoItemsInList = new Array;		var node = gallery.firstChild;		/* instead of using childNodes (which also gets empty nodes and messes up the script later)		we do it the old-fashioned way and loop through the first child and its siblings */		while (node) {			if (node.nodeType==1) {				galleryImages.push(node);			}			node = node.nextSibling;		}		node = photoList.firstChild;		while(node){			if (node.nodeType==1) {				photoItemsInList.push(node);			}			node = node.nextSibling;		}		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;
			galleryImages[i].style.display='block';			/* set their opacity to transparent */			fader(i,0);		}		gallery.style.visibility = 'visible';		//var randomSelection = Math.round(Math.random()*5);				fader(0,100);		galleryImages[0].style.zIndex=100;		photoItemsInList[1].firstChild.style.borderColor='#ffffff';		photoItemsInList[1].firstChild.style.color='#ffffff';		currentImage = 0;		previousImage = 0;	}}function runFader(setCurrentImage){		if (setCurrentImage != currentImage) {			previousImage = currentImage;	    	currentImage = setCurrentImage; 			crossfade(0);		}	}function crossfade(opacity) {		if (opacity <= 100) {			/* current image not faded up fully yet...so increase its opacity */			fader(currentImage,opacity);			/* fader(previousImage,100-opacity); */			photoItemsInList[currentImage+1].firstChild.style.borderColor='#ffffff';			photoItemsInList[currentImage+1].firstChild.style.color='#ffffff';			photoItemsInList[previousImage+1].firstChild.style.color='#999999';			photoItemsInList[previousImage+1].firstChild.style.borderColor='#999999';			photoItemsInList[currentImage+1].firstChild.blur();			galleryImages[previousImage].style.zIndex = 0;			galleryImages[currentImage].style.zIndex = 100;			if (galleryImages[previousImage].style.opacity!=null) {				opacity += 10;				window.setTimeout("crossfade("+opacity+")", 1);			} else {				opacity += 5;				window.setTimeout("crossfade("+opacity+")", 10);							}					} else {			fader(previousImage,0);		}		}