var images = new Array();
var closed = false;

$(document).ready(function() 
{
	$('#background-image img').each(function() 
	{
		images.push($(this).attr('rel'))
	});
	$('#background-image').empty();
	
	// Load Images
	$({}).imageLoader(
	{
		images: images,
		async: false,
		complete: function(event, ui) 
		{	
			var el = '<img rel="'+ ui.i +'" src="' + images[ui.i] + '" />'
			$('#background-image').append(el);
			StageUtils.fitToStage($('#background-image img'));
			if (ui.i == 0) $('#background-image img').fadeIn('fast');
		},
		allcomplete: function(event, ui)
		{
			$('#background-image').cycle(
			{ 
				fx:      'uncover', 
				speed:    700, 
				timeout:  5000,
				after:  onAfter

 			});
			$('#background-image').removeClass('loading');
		}
	});
	
	$('#home-highlights-button-open').click(function()
	{
		$('#home-highlights').animate({ left: '80px', bottom: '90px', avoidTransforms:true}, { duration: 500, easing: "easeInOutCubic" });
		setTimeout(function() { $('#home-highlights-button-close').animate({ left: '+=24px', opacity: 100, avoidTransforms:true}, { duration: 300, easing: "easeInOutCubic" }); }, 600);
			$('#home-highlights-button-close').animate({'z-index' : '103'}, 1000);
			
})
	
	$('#home-highlights-button-close').click(function()
	{
		$('#home-highlights-button-close').css('z-index', '1').animate({ left: '-=24px', opacity: 0, avoidTransforms:true}, { duration: 300, easing: "easeInOutCubic" });
		setTimeout(function() { $("#home-highlights").animate({ left: '-700px', bottom: '-400px', avoidTransforms:true}, { duration: 500, easing: "easeInOutCubic" }); }, 500);
		
		closed = true;
	})
	
	placeElements();
	
	
	
})

function onAfter(curr, next, opts) 
{
	if (opts.currSlide == 1 && closed == false) 
	{
		/*$("#home-highlights").fadeOut();
		$('#home-highlights-button-close').fadeOut();*/
		//$("#home-highlights").animate({ left: -300, bottom: -300}, { duration: 3000, easing: "easeOutBack", delay: 500 });
		
	}
}


function placeElements()
{
	$('#home-contents').css('width', $(window).width());
	$('#home-contents').css('height', $(window).height() - 80 - 44);
}

$(window).resize(function() {placeElements();});
