var slider = {};

slider.initialise = function()
{
	$( window ).load( slider.loadSliderData );
};

slider.loadSliderData = function()
{
	//$( '#homeAnimation' ).load( 'homeAnimation.html #homeAnimation li', slider.loadSliderDataComplete );
	$( '#homeAnimation' ).load( 'http://www.gsquare.co.uk/HomeAnimation.aspx #homeAnimation li', slider.loadSliderDataComplete );
};

slider.loadSliderDataComplete = function(response, status, xhr)
{
	if( status == "error" )
	{
		var msg = "Sorry but there was an error: ";
		$( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
	}
	
	$( '#homeAnimation li' ).each( slider.setBackgroundImageAndValidate );
	
	$( slider.instantiateSlider );
};

slider.setBackgroundImageAndValidate = function( index, element )
{
	var imagePath = $( this ).children( "span.backgroundImagePath" ).text();
	
	if( imagePath.length == 0 )
	{
		$( this ).remove();
	}
	
	$( this ).css( 'background', 'url(' + imagePath + ') no-repeat top left' );
}

slider.instantiateSlider = function()
{
	var options = {};
	options.buildArrows = true;
	options.autoPlay = true;
	options.pauseOnHover = true;
	options.delay = 9000;
	
	$( '#homeAnimation' ).anythingSlider( options );
};
