<!--
/*****

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


*****/
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false, res_index=1, switch_res="-before", class_index=1;

//window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);
function so_init() {
	if(!d.getElementById || !d.createElement)return;

	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
	/*css = d.createElement("link");
	css.setAttribute("href","xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	*/
	//imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	imgs = d.getElementById("imageContainer").getElementsByTagName("div");
	for(i=3;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	imgs[1].style.display = "block";
	imgs[1].xOpacity = .99;
	imgs[2].style.display = "block";
	imgs[2].xOpacity = .99;
	
	setTimeout(function() {fade_photos()},3000);
	
}

function so_xfade(currentIndex,newIndex) {
	
	
	current=currentIndex;
	
	cOpacity = imgs[current].xOpacity;
	//nIndex = imgs[current+3]?current+3:0;
	nIndex = newIndex;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpac(imgs[current]); 
	setOpac(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		//current = nIndex;
		setTimeout(function() {fade_photos()},1500);
	} else {
		setTimeout('so_xfade('+current+','+nIndex+')',50);
	}	
	
}

function restoration_move() {
	
	for (i = 1; i <= 15; i++){

		//document.getElementById("block1").innerHTML=document.getElementById("block1").innerHTML + "Index i=" + i + "<br />";
		//d.getElementById('img_'+i+'-after').style.display = "none";
		if (i != 1){
			d.getElementById('img_'+i+'-before').xOpacity = 0;
			setOpac(d.getElementById('img_'+i+'-before'));
		}else{
			d.getElementById('img_'+i+'-before').xOpacity = 100;
			setOpac(d.getElementById('img_'+i+'-before'));
		}
		d.getElementById('img_'+i+'-after').xOpacity = 0;
		setOpac(d.getElementById('img_'+i+'-after'));

	}
	
	setTimeout(function() {restoration_xfade(1)},1000);

}

function restoration_xfade(nIndex) {
	
	if (switch_res.length=0 && nIndex==1) {
		switch_res="-after";
	}
	
	nOpacity = d.getElementById('img_'+nIndex+switch_res).xOpacity;
	
	nOpacity+=.05;
	
	d.getElementById('img_'+nIndex+switch_res).style.visibility = "visible";
	d.getElementById('img_'+nIndex+switch_res).xOpacity = nOpacity;
	
	setOpac(d.getElementById('img_'+nIndex+switch_res));
	
	if(nOpacity<1) {
		setTimeout('restoration_xfade('+nIndex+')',50);
	}else{
		if (switch_res=="-before") {
			switch_res="-after";
			setTimeout(function() {restoration_xfade(nIndex)},1000);
		}else{
			switch_res="-before";
			res_index+=1;
			if (res_index>15){
				return;
			}else{
				setTimeout(function() {restoration_xfade(res_index)},1000);
			}
		}
	}
	
	
}

function setOpac(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) + ")";
	obj.style.KhtmlOpacity = (obj.xOpacity);
}

function fade_photos()
{
	if (running) {
		
		//var random_class = 'photo' + Math.round(Math.random()*(2)+1);
		var div_photo;
		var is_visible;
		var currentImage;
		var currentIndex,newIndex;
		
		random_class = 'photo' + class_index;
		
		div_photo = getElementsByClassName(random_class,'div');
		
		//document.getElementById("block1").innerHTML=document.getElementById("block1").innerHTML + "Index=" + class_index + " Length=" + div_photo.length  + "<br />";
		
		do {
			var random_image = Math.round(Math.random()*(div_photo.length - 1));
			if (div_photo[random_image].style.display=="block") {
				is_visible=true;
			}else{
				is_visible=false;
			}
		} 
		while (is_visible);
		
		for ( var i in div_photo )
		{
			if (div_photo[i].style.display=="block"){	
				currentImage=i;
			}
		} 
	
		for (x=0;x<imgs.length;x++){
			if (imgs[x].id==div_photo[currentImage].id) {
				currentIndex=x;
			}else if (imgs[x].id==div_photo[random_image].id) {
				newIndex=x;
			//document.getElementById("block1").innerHTML=document.getElementById("block1").innerHTML + "New Index=" + newIndex + " Index=" + x  + " ID=" + imgs[x].id + "<br />";
			}
		}
		
		so_xfade(currentIndex,newIndex);
				
		if (class_index==3) {
			class_index=1;
		}else{
			class_index+=1;
		}

	}
}

function setOpacity(obj, o) {

    obj.style.opacity = (o / 100);
    obj.style.MozOpacity = (o / 100);
    obj.style.KhtmlOpacity = (o / 100);
    obj.style.filter = 'alpha(opacity=' + o + ')';
}

function pausecomp(millis) {
    var date = new Date();
    var curDate = null;

    do { curDate = new Date(); }
    while(curDate-date < millis);
} 


function getElementsByClassName(classname,tag) {
	var node = document.getElementsByTagName(tag);
	var a = [];
	var re = new RegExp('\\b' + classname + '\\b');
	var els = node;
	for(var i=0,j=els.length; i<j; i++)
	if(re.test(els[i].className))a.push(els[i]);
	return a;
}

function HasClassName(objElement, strClass) {
	// if there is a class
	if ( objElement.className ) {
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		// get uppercase class for comparison purposes
		var strClassUpper = strClass.toUpperCase();
		// find all instances and remove them
		for ( var i = 0; i < arrList.length; i++ ) {
			// if class found
			if ( arrList[i].toUpperCase() == strClassUpper ) {
				// we found it
				return true;
			}
		}
	}
	// if we got here then the class name is not there
	return false;
}

function AddClassName(objElement, strClass, blnMayAlreadyExist) {
	// if there is a class
	if ( objElement.className ) {
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		// if the new class name may already exist in list
		if ( blnMayAlreadyExist ) {
			// get uppercase class for comparison purposes
			var strClassUpper = strClass.toUpperCase();
			 // find all instances and remove them
			for ( var i = 0; i < arrList.length; i++ ) {
				// if class found
				if ( arrList[i].toUpperCase() == strClassUpper ) {
					// remove array item
					arrList.splice(i, 1);
					// decrement loop counter as we have adjusted the array's contents
					i--;
				}
			}
		}
		// add the new class to end of list
		arrList[arrList.length] = strClass;
		// add the new class to beginning of list
		//arrList.splice(0, 0, strClass);
		// assign modified class name attribute
		objElement.className = arrList.join(' ');
	}else {
		// assign modified class name attribute      
		objElement.className = strClass;
	}
}

function RemoveClasses(objElement) {

	if (isArray(objElement.className)) {
		var arrList = objElement.className.split(' ');
		arrList=[];
	}else{
		arrList="";
	}
	objElement.className = arrList;
}

function isArray(testObject) {       
	return testObject && !(testObject.propertyIsEnumerable('length')) && typeof testObject === 'object' && typeof testObject.length === 'number';
}

function RemoveClassName(objElement, strClass) {
	// if there is a class
	if ( objElement.className ) {
		// the classes are just a space separated list, so first get the list
		var arrList = objElement.className.split(' ');
		// get uppercase class for comparison purposes
		var strClassUpper = strClass.toUpperCase();
		// find all instances and remove them
		for ( var i = 0; i < arrList.length; i++ ) {
			// if class found
			if ( arrList[i].toUpperCase() == strClassUpper ) {
				// remove array item
				arrList.splice(i, 1);
				// decrement loop counter as we have adjusted the array's contents
				i--;
			}
		}
		// assign modified class name attribute
		objElement.className = arrList.join(' ');
	}
	// if there was no class
	// there is nothing to remove
}

function toggleTimer(s){
	if (s.value.toUpperCase()=="ON"){
		running=true;
		rotateEvery(2);
		s.value="Off";					
	}else{
		running=false;
		s.value="On";					
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

-->