// www.jennifer-dungan.com


/*****

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

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

Image Cross Fade Redux
Version 1.x??
Revised May 3rd, 2006
Jennifer Dungan

Rewrite of code found here: http://slayeroffice.com/code/imageCrossFade/xfade2.html

- added image preloader
- updated code to work with prototype.js


*****/


/* Image Cross Fade Redux starts here ****************************************************/

imgs = new Array();
zInterval = null;
current = 0;
pause = false;

function loadImages()
{
	new Insertion.Bottom('mainImage', '<img src="http://www.jenniferdungan.com/images/dog.gif" width="320" height="364" alt="Nazca lines - Dog" id="img2" /><img src="http://www.jenniferdungan.com/images/flower.gif" width="320" height="364" alt="Nazca lines - Flower" id="img3" /><img src="http://www.jenniferdungan.com/images/lizard.gif" width="320" height="364" alt="Nazca lines - Lizard" id="img4" /><img src="http://www.jenniferdungan.com/images/monkey.gif" width="320" height="364" alt="Nazca lines - Monkey" id="img5" /><img src="http://www.jenniferdungan.com/images/spider.gif" width="320" height="364" alt="Nazca lines - Spider" id="img6" /><img src="http://www.jenniferdungan.com/images/tree.gif" width="320" height="364" alt="Nazca lines - Tree" id="img7" />');
	slideshow();
}

function slideshow() {
	if(!document.getElementById || !document.createElement)return;
	
	css = document.createElement("link");
	css.setAttribute("href","http://www.jenniferdungan.com/styles/xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	document.getElementsByTagName("head")[0].appendChild(css);
	
	imgs = $("img1", "img2", "img3", "img4", "img5", "img6", "img7");
	
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade,2000);
	
}


function so_xfade() {
	
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,2000);
	} 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) + ")";
	}
	
}

/* Image Cross Fade Redux ends here ****************************************************/

function loadEmail(){
	$("replace").innerHTML = "<div id='emailaddress'></div>";
	
	var string1 = "webmaster";
	var string2 = "@";
	var string3 = "jenniferdungan.com";
	var string4 = string1 + string2 + string3;
	var address = "<a href=" + "mail" + "to:" + string1 + string2 + string3 + ">" + string4 + "</a>";
	
	new Insertion.Top("emailaddress", address);
	
	loadImages();
}

function mainMenu()
{
	if (document.all&&document.getElementById) 
	{
		navRoot = $("nav");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					this.className+=" over";
				}
				node.onmouseout=function()
				{
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
	
	if ($("replace"))
	{
		loadEmail();
	}
	else
	{
		loadImages();
	}
}

window.onload=function()
{
	if (document.images)
	{
		image1 = new Image(320,364);
		image1.src = "http://www.jenniferdungan.com/images/condor.gif";
		
		image2 = new Image(320,364);
		image2.src = "http://www.jenniferdungan.com/images/dog.gif";
		
		image3 = new Image(320,364);
		image3.src = "http://www.jenniferdungan.com/images/flower.gif";
		
		image4 = new Image(320,364);
		image4.src = "http://www.jenniferdungan.com/images/lizard.gif";
		
		image5 = new Image(320,364);
		image5.src = "http://www.jenniferdungan.com/images/monkey.gif";
		
		image6 = new Image(320,364);
		image6.src = "http://www.jenniferdungan.com/images/spider.gif";
		
		image7 = new Image(320,364);
		image7.src = "http://www.jenniferdungan.com/images/tree.gif";
	}
	
	mainMenu();	
}
