$(document).ready(function(){
	
	// Only start the rotation if we have the images array
	if ($.isArray(images) && images.length > 1) {
		
		var $c = $('#rotator');
		
		// Insert every image except the first one and start loading them all
		$.each(images, function(index, item){
			
			if (0 == index) return;
			
			$c.append($('<img />', {
				src: item
			}));
		
		});
		
		$c.children('img:gt(0)').hide();
		
		setInterval(function(){
	      $c.children(':first-child').fadeOut(1000, function(){$(this).appendTo('#rotator')})
	         .next().fadeIn(1000);}, 
	      6000);
	}
	
	// Add page fader
	$('#wrapper')
		.append('<a />')
		.children('a')
			.addClass('sifr fader fader-ext-bg ly-fader')
			.toggle(function(e){
				$('#page').stop().fadeTo('slow', 0);
				$(this).removeClass('fader-ext-bg').addClass('fader-ext-ws');
			}, function(){
				$('#page').stop().fadeTo('slow', 1);
				$(this).removeClass('fader-ext-ws').addClass('fader-ext-bg');
			})
		// Preload the off-image
		.append('<a class="fader-ext-ws" style="display: none" id="kill-01" />')
		.children('#kill-01').remove();
});
