jQuery( document ).ready( function(){
	start_slides( '#header-quote-holder p', 5500 );
	start_slides( '.slide-images img', 5500 );
	start_slides( '.slide-testimonials p', 5500 );
});

function start_slides( item, time, callback ) {
	var all_items = jQuery( item ).length;
	if ( all_items < 1 ) return;
	var zindex = all_items;
	var i=0;
	jQuery( item ).each( function(){
		jQuery( this ).css( { 'z-index': zindex } );
		if ( i > 0 ) jQuery( this ).hide();
		zindex--;
		i++;
		var img = new Image();
		img.src = jQuery( this ).attr('src');
	});
	
	var index = 0;
	var next;
	var time = time || 5000;
	var callback = callback || function(){};
	
	var interval = window.setInterval( function(){
		if ( index == all_items ) index = 0;
		next = index + 1;
		
		if ( next == all_items ) next = 0;
		
		jQuery( item + ":eq(" + index + ")" ).fadeOut(1200);
		jQuery( item + ":eq(" + next + ")" ).fadeIn(1200, function(){
			callback( next );
		});
		
		index++;
	}, time);
}