	/*****
	
	Heavily modified by Seth Dillingham and Dan Wood, June 2008 
	
	Image Cross Fade Redux
	Version 1.0
	Last revision: 02.15.2006
	steve@slayeroffice.com
	
	Please leave this notice intact. 
	
	Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
	
	*****/
	
	window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

	var d=document, imgs, current=0;
	var between = 4000;				// how many milliseconds between images.
	var width = 340, height = 327;	// size of all images.		340 x 327 originally
	var numberOfImagesToLoad = 21;	// count of list below.
	var imagesToLoad = {			// URL of image and the 'alt' text for it.
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/242.sandvox.Earth_and_Sky.png": "Earth and Sky",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/212.sandvox.Cirrus.png": "Cirrus",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/164.sandvox.Industrial.png": "Industrial",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/176.sandvox.Grey_Leaf.png": "Grey Leaf",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/157.sandvox.Cathedral.png": "Cathedral",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/263.sandvox.SmoothDark.png": "Smooth Dark",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/186.sandvox.This_Modern_Life.png": "This Modern Life",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/158.sandvox.Serengeti.png": "Serengeti",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/293.sandvox.Sunburst.png": "Sunburst",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/162.sandvox.NeoNews.png": "Neo News",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/204.sandvox.Clean_Sheets.png": "Clean Sheets",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/185.sandvox.Imagine.png": "Imagine",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/187.sandvox.Clockwork.png": "Clockwork",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/209.sandvox.Gnarled.png": "Gnarled",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/216.sandvox.Reflections.png": "Reflections",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/235.sandvox.Skyline.png": "Skyline",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/245.sandvox.Open_All_Night.png": "Open All Night",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/251.sandvox.Pacific_Sky.png": "Pacific Sky",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/280.sandvox.Glass_Box.png": "Glass Box",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/289.sandvox.Rounded_Blue.png": "Rounded Blue",
"/FILECACHE/images/plugin.previews/72238c415c09cacd6211aa33ced77bd2/300.sandvox.Night_Breeze.png": "Night Breeze",
	};

	// Initialize when the page is loaded. Creates a container for the images, and kicks off the 
	// insertion/loading of the first one.
	
	function so_init() {
		if(!d.getElementById || !d.createElement)return;
		
		if (-1 != navigator.userAgent.indexOf('Sandvox')) return;
		
	
		// Create the imageContainer and its innards
		var ioc = d.getElementById("imageOuterContainer");
		
		if (!ioc)		// TEMP -- for smaller variation
		{
			ioc = d.getElementById("imageOuterContainer2");
			width = 200;
			height= 200;
		}
		
		var ic = d.createElement("div");
		ic.id = "imageContainer";
		ic.style.width = width + "px";
		ic.style.height = height + "px";
		ic.style.zIndex = 42;
		ioc.appendChild(ic);
		loadNextImage();		// kick off the first image load.
	}
	

	// Figure out which image to load based on how many images have already been loaded.
	// Insert a new image tag into the DOM, and if it's not the last image, schedule another check of this
	// as soon as that image is loaded.  This will cause the images to all be loaded sequentially
	// rather than in parallel.  When the last image is in place and starts loading, kick off the timer
	// to fade between images. (We could theoretically start that sooner...)
	
	function loadNextImage()
	{
		var ic = d.getElementById("imageContainer");
		var children = ic.childNodes;
		var len = children.length;
		// Dumb hack -- get the nth item, can't get imagesToLoad[len]
		var nthURL;
		var ct = 0;
		for (var url in imagesToLoad) {
			nthURL = url;
			if (ct++ >= len) break;
		}
		var img = d.createElement("img");
		img.style.zIndex = 42;
		img.src = url;
		img.width = width;
		img.height = height;
		img.alt = imagesToLoad[url];
		if (0 == len)		// is this the first image?
		{
			img.xOpacity = 0.99;	// if we set it to 1.00, then for some reason it's faded out immediately.
		}
		else
		{
			img.xOpacity = 0;
		}
		if (len+1 < numberOfImagesToLoad) {
			img.onload = loadNextImage;
		}
		else
		{
			// last image put into place; save list of img's and start the timer
			imgs = ic.getElementsByTagName("img");	// get an array so we can get first one
			img.onload = function(){ setTimeout(so_xfade,between); };
		}
		setOpacity( img );
		ic.appendChild(img);
	}
	
	function so_xfade() {
		cOpacity = imgs[current].xOpacity;
		nIndex = imgs[current+1]?current+1:0;
	
		nOpacity = imgs[nIndex].xOpacity;
		
		cOpacity-=.05; 
		nOpacity+=.05;
		
		imgs[current].xOpacity = cOpacity;
		imgs[nIndex].xOpacity = nOpacity;
		
		setOpacity(imgs[current]); 
		setOpacity(imgs[nIndex]);
		
		if(cOpacity<=0) {
			current = nIndex;
			setTimeout(so_xfade,between);
		}
		else
		{
			setTimeout(so_xfade,50);
		}
	}

	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
