//strings for the front page
var textLines = 
	[
		"Well-trained and with an average employment history of 15 years, experienced Shirlee Industries personnel are ready to meet or exceed demanding requirements.",
		"For more than 40 years of progressive growth, Shirlee Industries, Inc. has taken steps to advance in technology and continues to acquire the latest equipment. Shirlee Industries can work with mild steel, aluminum, copper, brass and most other metal alloys.",
		"At Shirlee Industries, technical innovation is key to enabling on-time delivery of best value, quality components. Even Proven methodologies are constant challenged.",
		"Well-trained and with an average employment history 15 years, experienced Shirlee Industiries personnel are ready to meet or exceed demanding requirements.",
		"In-house sheet metal fabrication capability ensures Shirlee Industries will deliver high quality, complex mechanical components on time.",
		"From large steel structures to delicate, thin-walled aluminum Shirlee Industries' certified welders are ready to meet or exceed your requirements."
	];

//images for the backgrounds
var backgrounds = 
	[
		"home-0.png",
		"home-1.png",
		"home-2.png",
		"home-3.png",
		"home-4.png",
		"home-5.png"
	];

//go through and preload all the images
var preloadedImage = new Image();
for (var i = 0; i < backgrounds.length; i++)
{
	preloadedImage = new Image();
	preloadedImage.src = "images/home/" + backgrounds[i];
}

//duration between animations
var delay = 3000;

//onload start the timeouts
$(function() 
{
	setTimeout(cycleAll, delay)
});

//
var backgroundDone = false;
var textDone = false;
var animText = false;
var currentText = 0;
var currentBg = 0;
function cycleAll()
{
	backgroundDone = false;
	textDone = false;
	
	$("#home-images").fadeOut(function()
	{
		currentBg++;
		if (currentBg == backgrounds.length)
			currentBg = 0;
			
		$(this).css({backgroundImage : "url(images/home/" + backgrounds[currentBg] + ")"});
		$(this).fadeIn(function()
		{
			backgroundDone = true;
				
			if (animText)
			{
				if (backgroundDone && textDone) 
				{
					setTimeout(cycleAll, delay);
					animText = !animText;
				}				
			}
			else
			{
				setTimeout(cycleAll, delay);
				animText = !animText;
			}
		});
	});
	
	if (animText)
	{
		$("#home-panel").fadeTo("normal", 0, function()
		{
			currentText++;
			if (currentText == textLines.length)
				currentText = 0;
				
			$("#home-panel-text").text(textLines[currentText]);
			$("#home-panel").fadeTo("normal", .7, function()
			{
				textDone = true;
				if (backgroundDone && textDone) 
				{
					setTimeout(cycleAll, delay);
					animText = !animText;
				}		
			});
		});
	}
}

