$(document).ready(function() {
	
	$('section.slider ul.slides')
	.cycle({ 
		fx:    'scrollLeft', 
		sync:   0, 
		timeout: 10000,
		before: function(current, next) {
			var nextId = $(next).index()+1;
			var newBkg = $('.background-images img:nth-child('+nextId+')');
			newBkg.css({
				zIndex: 20,
				opacity: 0
			});
			$('.background-images img').each(function() {
				if ($(this).index() != newBkg.index()) {
					$(this).css({
						zIndex: 10
					});
				}
			});
			newBkg.animate({opacity: 1}, 1000);
		},
		next: $('section.slider .slide-navigation a.forward'),
		prev: $('section.slider .slide-navigation a.back'),
		pager: $('section.slider div.slidernav')
	});
	
	$('section.slider').mouseover(function() {
		$('section.slider ul.slides').cycle('pause');
	});
	
	$('section.slider ul.slidernav').click(function() {return false});
});
