var _imagesArray = new Array("/images/ken_burns_js/caltrans.jpg", "/images/ken_burns_js/general_motors.jpg", "/images/ken_burns_js/nationals_stadium.jpg", "/images/ken_burns_js/philip_merrill.jpg", "/images/ken_burns_js/strathmore.jpg"); 
var _titleArray = new Array("Caltrans District 7 Headquarters", "General Motors Vehicle Engineering Facility", "Nationals Park", "Philip Merrill Environment Center", "The Music Center at Srathmore");
var _linkArray = new Array("http://www.clarkconstruction.com/index.php/projects/feature_project/18", "http://www.clarkconstruction.com/index.php/projects/feature_project/44", "http://www.clarkconstruction.com/index.php/projects/feature_project/288", "http://www.clarkconstruction.com/index.php/projects/feature_project/38", "");
var _transition = Fx.Transitions.linear;
var _inTime = 1000;
var _openTime = 3000;
var _zIndex = 1;

/*if the user does not have the required version of flash, preload the fallback images*/
if (swfobject.getFlashPlayerVersion().major < 9)
{
	var preImage = new Asset.images( _imagesArray );
}
function fallbackSlideshow()
{
	/*initial setup*/
	$('home_flash_content').set('html', '<img id="slide1" src="" alt="" /><img id="slide2" src="" alt="" />');
	$('home_flash_content').setStyle('position', 'relative');
	
	$('slide1').setStyles({'position': 'absolute', 'zIndex':_zIndex});
	$('slide2').setStyles({'position': 'absolute', 'zIndex':_zIndex++});
	
	$('slide1').store('index', 0);
	$('slide2').store('index', 1);
	
	$('slide1').set('morph', {duration:_inTime, link:'cancel', transition:_transition});
	$('slide2').set('morph', {duration:_inTime, link:'cancel', transition:_transition});
	
	nextSlide( $('slide1') );
	(function() {
		nextSlide( $('slide2') );
	}).delay(_openTime + _inTime);
	
	$('slide1').addEvent('click', function()
	{
		var loc = _linkArray[this.retrieve('index').toInt()];
		if (loc != "")
		{
			window.location = loc;
		}
	});
	
	$('slide2').addEvent('click', function()
	{
		var loc = _linkArray[this.retrieve('index').toInt()];
		if (loc != "")
		{
			window.location = loc;
		}
	});
}

function nextSlide(slide)
{
	/*read in the current index and increase it*/
	var currentIndex = slide.retrieve('index').toInt();
	var newIndex = (currentIndex >= _imagesArray.length - 1) ? 0 : ++currentIndex;
	slide.store('index', newIndex);
	slide.setProperty('src', _imagesArray[newIndex]);
	slide.setStyles({'zIndex': _zIndex++, 'opacity': 0});
	/*fade the slide in*/
	slide.morph({'opacity': 1});
	writeProjectName(_titleArray[newIndex]);
	/*fade the slide out*/
	(function() {
		this.morph({'opacity': 0});
	}).delay(_openTime + _inTime, slide);
	/*next slide*/
	(function() {nextSlide(this);}).delay(_openTime + _inTime * 2, slide);
	
	(_linkArray[newIndex] != "") ? slide.setStyle('cursor', 'pointer') : slide.setStyle('cursor', 'default');
}

