// strategyevolution.net javascript

var homeImage = 0;
var picRoot = "images/";
var pic = new Array();
var timeoutId;

$(document).ready( function() {
	animateIcons();
	slideShow();
});

function animateIcons() {
	$('.icon .riser').css({ top: '180px', display: 'block' });
	$('.icon').hover( function() {
		$(this).find('.riser').animate({
			top: '0'
		}, { duration: 200, easing: 'easeOutCirc' } );
	}, function() {
		$(this).find('.riser').animate({
			top: '180'
		}, { duration: 200, easing: 'easeInCirc' } );
	});
}


var slideShow = function() {
	//put images into array
	var picCount = 0;
	$('#loader input').each( function() {
		pic[picCount] = $(this).val();
		picCount ++;
	});

	if ( pic.length > 0 ) {
		//load images
		$('#loader img').hide();
		loadImage( 0 );
	}
}


var loadImage = function(i) {
	var img = new Image();
	
	$(img).load( function() {
	    var e = this;
	    $('#loader img:first').fadeOut(1000, function() {
	        $('#loader img:first').remove();
		    //hide it
		    $(e).hide();
		    //put the image into its container
		    $('#loader').append(e);
		    //fade image in
		    $(e).fadeIn( 1000, function() {
			    //remove unwanted image
			    //$(this).parent().find('img:first').remove();
			    timeoutId = setTimeout( function() { loadImage( nextImage() ) }, 6000 )
		    });
		});
	})
	.error( function() {
		//alert('error');
	})
	.attr({ src: picRoot + pic[i] });
}

var nextImage = function() {
	//increment the image counter
	homeImage++;	
	if ( homeImage > pic.length-1 ) {
		homeImage = 0;
	}
	
	return homeImage;
}

