var direction = -1; //1=fadein; -1 = fadeout

function nextSequenceFrame(cursor) {
	// validate the cursor
	if (!isSet(image_sequence[cursor])) {
		cursor = 0;
	}
		
	if (direction == -1) {
		jQuery('.imageSequence').css('background-image', 'url('+ image_sequence[cursor] +')');
		jQuery('.imageSequence').find('img').fadeOut(1500);
	} else {
		jQuery('.imageSequence').html('<img src="' + image_sequence[cursor] +'" style="display: none;"/>');
		jQuery('.imageSequence').find('img').fadeIn(1500);
	}
		
	// proceed to the next image, using the opposit transition direction
	cursor ++;
	direction = direction * -1;
	 
	// repeat
	setTimeout("nextSequenceFrame(" + cursor + ")", 10000);	
}

function isSet( variable ) {
	return( typeof( variable ) != 'undefined' );
}