( function() {
		  
	function main() {
		setUpNav();
		animateSlide();
		animateBackground();
	}
	
	function setUpNav() {
		var backLI = $('<li class="back"><span></span></li>');
		var theNav = $('#main-nav ul');
		
		$(theNav[0]).append(backLI);
		
		backLI.css({
			'width' : theNav.find('.active').width() + 'px',
			'left' : theNav.find('.active').position().left + 'px'
		});
		
		$(theNav[0]).find('> li').hover(function(){
			var theSub = $(this).find('span.sub');
			//mouse over
			backLI.stop().animate({
				'width' : $(this).width() + 'px',
				'left' : $(this).position().left + 'px'		   
			}, 200, function(){
				$(theSub).fadeIn('fast');	
			});
		 }, function(){
			//mouse out
			$(this).find('span.sub').fadeOut('fast');
			backLI.stop().animate({
				'width' : theNav.find('.active').width() + 'px',
				'left' : theNav.find('.active').position().left + 'px'	   
			}, 500, 'easeOutBounce');
		 });
	}
	
	function animateSlide() {
		$('#books-slide ul').cycle({
			fx : 'scrollHorz',
			timeout : 7000,
			easing : 'easeInOutQuad'
		});
	}
	
	function animateBackground() {
		$('#resizeBG').cycle({
			fx : 'fade',
			timeout : 5000,
			random : true
		});
	}
	
	main();
	
} )();
