//Created by: brainerror.net.  Oct. 2006 update stated all script are public domain.
//Modified by: Brendan Billingsley on Feb, 2008.
var timeOuts = new Array();
var opacTimeOuts = new Array();
var curColor = "black";
var loops = 0;

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--) {
			opacTimeOuts[loops] = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
			loops++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			opacTimeOuts[loops] = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
			loops++;
		}
	}
}

function hideObj(id) {
	var object = document.getElementById(id).style;
	object.visibility = "hidden";
}

//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)
}

function changeColor(id, color) {
	var object = document.getElementById(id).style; 
	var curColor = object.color;
	object.color = color;
	return curColor;
}

function introSequence() {
	changeOpac(0, "bodytext");
	curColor = changeColor("bodytext", "white"); //IE doesn't respect the previous line, so this makes text non-visible
	changeOpac(0, "layer2");
	changeOpac(0, "layer3");
	changeOpac(100, "layer4");
	timeOuts[0] = setTimeout("opacity('layer4', 100, 0, 1000)", 2000);
	timeOuts[1] = setTimeout("opacity('layer3', 0, 100, 1000)", 2000);
	timeOuts[2] = setTimeout("opacity('layer3', 100, 0, 1000)", 6000);
	timeOuts[3] = setTimeout("opacity('layer2', 0, 100, 1000)", 6000);
	timeOuts[4] = setTimeout("opacity('layer2', 100, 0, 1000)", 10000);
	timeOuts[5] = setTimeout("hideObj('skip')", 10000);
	timeOuts[6] = setTimeout("changeColor('bodytext', '" + curColor + "');", 10000); //Make the text visible again
	timeOuts[7] = setTimeout("opacity('bodytext', 0, 100, 1000)", 10500);
}

function twolayerintro() {
	changeOpac(0, "bodytext");
	curColor = changeColor("bodytext", "white"); //IE doesn't respect the previous line, so this makes text non-visible
	changeOpac(0, "layer2");
	changeOpac(100, "layer3");
	timeOuts[0] = setTimeout("opacity('layer3', 100, 0, 1500)", 2000);
	timeOuts[1] = setTimeout("opacity('layer2', 0, 100, 1000)", 2000);
	timeOuts[2] = setTimeout("opacity('layer2', 100, 0, 1000)", 7000);
	timeOuts[3] = setTimeout("hideObj('skip')", 7000);
	timeOuts[4] = setTimeout("changeColor('bodytext', '" + curColor + "');", 7000); //Make the text visible again
	timeOuts[5] = setTimeout("opacity('bodytext', 0, 100, 1000)", 7500);
}

function load() {
	introSequence();
}

function skip() {
	for(timeout in timeOuts) {
		clearTimeout(timeOuts[timeout]);
	}
	for(opactimeout in opacTimeOuts) {
		clearTimeout(opacTimeOuts[opactimeout]);
	}
}

function skiptwo() {
	skip();
	changeOpac(0, "layer2");
	changeOpac(0, "layer3");
	hideObj("skip");
	changeColor('bodytext', curColor);
	changeOpac(100, 'bodytext');
}

function skipthree() {
	skip();
	changeOpac(0, "layer2");
	changeOpac(0, "layer3");
	changeOpac(0, "layer4");
	hideObj("skip");
	changeColor('bodytext', curColor);
	changeOpac(100, 'bodytext');
}
