jQuery(document).ready(function() {

	$('body').addClass('js');

	$('.folio-image, .rotate-images').hide();

	$(window).load(function() {

		$('.folio-image, .rotate-images').fadeIn(500);

		var colours = Array('#e63333','#fa4fb3','#bc6cf7','#47c5fe','#4afede','#a4fa24','#ffff3d','#ff9019'); // '#83858b',
		var count = 0;

		$('#nav-folio li a').each(function(index) {
			$(this).addClass('btn-'+index);
		});

		function onBefore() { 
			$('#nav-folio li a.btn-'+count).animate( { color: colours[count] }, 1000);
			$('.rotate-colour').animate( { backgroundColor: colours[count] }, 1000);
		}
		function onAfter() {
			$('#nav-folio li a.btn-'+count).animate( { color: '#000' }, 1500);
			if (count < 7) {  // 8
				count++;
			} else {
				count = 0;
			}
		}

		$('#logo .rotate-images').cycle({ 
		    fx:      'fade', 
		    speed:    1000, 
		    timeout:  500,
		    before:  onBefore, 
		    after:   onAfter
		});

		$('#emd-name .rotate-images, #emd-slogan .rotate-images').cycle({ 
		    fx:      'fade', 
		    speed:    1000, 
		    timeout:  500
		});

	});

	$('A[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });

});
