
window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

// General variables
var d=document, zInterval = null, current_txt=0, current_img=0, pause=false;
var transitionInterval = 15000;
// Testimonial Section variables
var txtIndex = 1;
var txts = new Array();
var textPreload = new Array();
var textList = new Array();
textList[0] = 'images/testimonials1.gif';
textList[1] = 'images/testimonials2.gif';
textList[2] = 'images/testimonials3.gif';
textList[3] = 'images/testimonials4.gif';
// Image section variables
var imgIndex = 1;
var imgs = new Array();
var imagesPreload = new Array();
var imageList = new Array();
imageList[0] = 'images/experience_1.jpg';
imageList[1] = 'images/relationships_1.jpg';
imageList[2] = 'images/neutral_1.jpg';

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	
	css = d.createElement("link");
	css.setAttribute("href","css/xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	
	for (i=0; i < imageList.length; i++)
	{
		imagesPreload[i] = new Image();
		imagesPreload[i].src = imageList[i];	
	}
	
	for (i=0; i < textList.length; i++)
	{
		textPreload[i] = new Image();
		textPreload[i].src = textList[i];
	}
	
	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	imgs[1].style.display = "none";
	imgs[1].xOpacity = 0;
	
	
	txts = d.getElementById("textContainer").getElementsByTagName("img");
	// for(i=1;i<txts.length;i++) txts[i].xOpacity = 0;
	txts[0].style.display = "block";
	txts[0].xOpacity = .99;
	txts[1].style.display = "none";
	txts[1].xOpacity = 0;
	
	setTimeout(so_xfade,transitionInterval);
}

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) + ")";
}

function so_xfade() {
	cOpacity = imgs[current_img].xOpacity;
	nImgIndex = imgs[current_img+1]?current_img+1:0;
	nTxtIndex = txts[current_txt+1]?current_txt+1:0;
	
	imgs[nImgIndex].src = imagesPreload[imgIndex].src;
	txts[nTxtIndex].src = textPreload[txtIndex].src;
	
	nOpacity = imgs[nImgIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nImgIndex].style.display = "block";
	imgs[current_img].xOpacity = cOpacity;
	imgs[nImgIndex].xOpacity = nOpacity;
	
	txts[nTxtIndex].style.display = "block";
	txts[current_txt].xOpacity = cOpacity;
	txts[nTxtIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current_img]); 
	setOpacity(imgs[nImgIndex]);
	setOpacity(txts[current_txt]); 
	setOpacity(txts[nTxtIndex]);
	
	if(cOpacity<=0) {
		if ( imgIndex < imageList.length-1 )
		{
			imgIndex++;
		} else {
			imgIndex=0;
		}
		if ( txtIndex < textList.length-1 )
		{
			txtIndex++;
		} else {
			txtIndex=0;
		}
		imgs[current_img].style.display = "none";
		txts[current_txt].style.display = "none";
		current_img = nImgIndex;
		current_txt = nTxtIndex;
		setTimeout(so_xfade,transitionInterval);
	} else {
		setTimeout(so_xfade,50);
	}	
}
