var topMainOut;
var topFooterOut;
var topMainIn;
var topFooterIn;

var topMainDiv;
var bottomMainDiv;
var topFooterDiv;
var bottomFooterDiv;

var nextNum = 1;

var pathPrefix = 'images/';
var ext = '.jpg';

function createFadeOut(ID, transTime) {
	var fadeOut = new YAHOO.util.Anim(   
		ID,    
		{opacity: {to: 0 } },    
		transTime
	);
	return fadeOut;
}
function createFadeIn(ID, transTime) {
	var fadeIn = new YAHOO.util.Anim(   
		ID,    
		{opacity: {to: 1 } },    
		transTime
	);
	return fadeIn;
}
function setBackground (div, filename) {
	
	div.style.backgroundImage = "url(" + pathPrefix + filename + ext + ")";
}
	

function fadeImages() {
	// Configuration variables to change
	var numImages = 5;
	var fadeTimeSec = 2;
	var fadeTimeSecMilli = fadeTimeSec * 1000;
	var waitSecMilli = 3000;
	var repeatTimes = 5;
	
	
	// Creates objects for the top and bottom divs of the footer and main 
	
	topMainDiv = document.getElementById("topMainImage");
	bottomMainDiv = document.getElementById("bottomMainImage");
	topFooterDiv = document.getElementById("topFooterImage");
	bottomFooterDiv = document.getElementById("bottomFooterImage");
	
	// Creates YUI animation objects for the top/bottom divs for both footer and main images
	 topMainOut = createFadeOut('topMainImage', fadeTimeSec);
	 topFooterOut = createFadeOut('topFooterImage', fadeTimeSec);
	 topMainIn = createFadeIn('topMainImage', fadeTimeSec);
	 topFooterIn = createFadeIn('topFooterImage', fadeTimeSec);
	
	nextNum = 1;
	var currTime = 0;
	var counter = 0;
	
	
	// Sets up the top layers with a starting image
  setTimeout("setBackground(topMainDiv, '1main')", currTime);
	setTimeout("setBackground(topFooterDiv, '1footer')", currTime);
	
	currTime = currTime + waitSecMilli/2;
  setTimeout("setBackground(bottomMainDiv, '2main')", currTime);
  setTimeout("setBackground(bottomFooterDiv, '2footer')", currTime);
		
	// Loop starts at 1 and reaches the number of images
	while (counter < repeatTimes) {
	
		
		// Fades top image out
		currTime = currTime + waitSecMilli/2; //3000ms
		setTimeout("topMainOut.animate();", currTime);
		setTimeout("topFooterOut.animate();", currTime);
		
		// Sets the (now hidden) top div to a new image 6500ms
		currTime = currTime + waitSecMilli/2 + fadeTimeSecMilli;
		setTimeout("setBackground(topMainDiv, '4main')", currTime);
		setTimeout("setBackground(topFooterDiv, '4footer')", currTime);
		
		// Fades the top image out, revealing the bottom image 8000ms
		currTime = currTime + waitSecMilli/2;
		setTimeout("topMainIn.animate()", currTime);
		setTimeout("topFooterIn.animate()", currTime);
		
		currTime = currTime + waitSecMilli/2 + fadeTimeSecMilli; //1150ms
		setTimeout("setBackground(bottomMainDiv, '3main')", currTime);
		setTimeout("setBackground(bottomFooterDiv, '3footer')", currTime);
		
		// Fades top image out
		currTime = currTime + waitSecMilli/2; //1300ms
		setTimeout("topMainOut.animate()", currTime);
		setTimeout("topFooterOut.animate()", currTime);
		
		currTime = currTime + waitSecMilli/2 + fadeTimeSecMilli; //1650ms
		// Sets the (now hidden) top div to a new image
		setTimeout("setBackground(topMainDiv, '5main')", currTime);
		setTimeout("setBackground(topFooterDiv, '5footer')", currTime);
		
		currTime = currTime + waitSecMilli/2;
		// Fades the top image out, revealing the bottom image
		setTimeout("topMainIn.animate()", currTime);
		setTimeout("topFooterIn.animate()", currTime);
		
		currTime = currTime + waitSecMilli/2 + fadeTimeSecMilli;
		setTimeout("setBackground(bottomMainDiv, '1main')", currTime);
		setTimeout("setBackground(bottomFooterDiv, '1footer')", currTime);
		
		
		counter++;
	}
}

function showCallOut(button, opacity) {
	if (document.getElementById('home')) {
		var callOutIn = new YAHOO.util.Anim(   
			'callout',    
			{opacity: {to: 1 } },    
			.5
		);

		var callOutDiv = document.getElementById('callout');
		if (button == "talent") 
				callOutDiv.innerHTML = "BHS is a talented group of people with a shared goal. Our diversity, creative collaboration and synergy generates interesting and effective products.";
		else if (button == "demos")
				callOutDiv.innerHTML = "Here we are offering a glimpse of some of our e-learning training demos so that you can get a better idea about the quality of our work.";
		else if (button == "services")
				callOutDiv.innerHTML = "We create multimedia presentations and e-learning modules that are customized for each client.";
		else if (button == "contact")
				callOutDiv.innerHTML = "Contact us and we will design a creative multimedia or e-learning module to suit your particular needs.";
		callOutIn.animate();
	}
}
function quickHideCallOut() {
	var callOutOut = createFadeOut("callout", .005);
	callOutOut.animate();
}
function hideCallOut() {
	var callOutOut = createFadeOut("callout", .5);
	callOutOut.animate();
}
