$(document).ready(function(){

	//preload images	
	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	$.preloadImages(
		"images/outdoors.png", 
		"images/menuImg.png",
		"images/location.png",
		"images/catering.png",
		"images/contactUs.png",
		"images/localFarm.png",
		"images/bBistro.png", 
		"images/outdoors2.png"
	)
	
	
	//slideshow
	$('#slideshow').after('<div id="controls" class="nav">').cycle({
		fx:    'fade',
		timeout: 0,
		pager: '#controls',
		pauseOnPagerHover: 1,
		speed:  650, 
		pause: 1
	 });
	 
	/* $('#controls').css('display', 'none');
	 
	 $('#billboard').hover(
	 	function(){
	 		$('#controls').fadeIn(300);
	 	},
	 	function() {
	 		$('#controls').fadeOut(300);
	 	
	 	}
	 );*/
	
	
	
	//rollover effects for image buttons
	
	$('.fade-area').children().hover(function() {
		$(this).siblings().stop().fadeTo(300,0.5);
		$(this).css('cursor', 'pointer')
	}, function() {
		$(this).siblings().stop().fadeTo(300,1);
	});
	
	
	//primary Nav	
	var currentPage = 'Menu.html';
	
	$('#content').css('display', 'none');
	
	$('#content').load(currentPage, function(){
		$(this).fadeIn('slow');
	});

	$('.primNav').hover(function(){
		$('li#sampLink').fadeIn('fast');
	}, function(){
		$('li#sampLink').fadeOut('fast');
	});
	
	$('#header ul.primNav li a').click(function(){
		
		//setup the target page url
		var targetAttr = $(this).attr('title');
		var targetPage = targetAttr + '.html';
		
		//exit if it's the menu preview
		if(targetAttr == 'Preview'){
			$('li#sampLink').fadeOut('fast');
			return;
		}
				
		//test to see if it's the current page
		if(targetPage == currentPage){
			$.scrollTo('#footerNav', 600);
			return false; 
		}
		
		//make this the active link
		$(this).parent().addClass('active');
		
		//remove the active class previously active items
		$(this).parent().siblings().removeClass('active');

		//remove active styles and style the sidebar
		$('#subnav-col ul li').removeClass('active');
		$('#subnav-col ul li').css('border-top', '1px solid #4F050B');
		$('#footerNav ul li').removeClass('active');
		
		//tell the footer to activate it's link
		$('ul.primNav li a').each(function(){
			if($(this).attr('title') == targetAttr){
				$(this).parent().addClass('active');
			}
		});
		
		//scroll to the bottom
		$.scrollTo('#footerNav', 600); 
		
		//load the page in the target div and scroll to it
		$.ajax({
		  url: targetPage,
		  cache: false,
		  success: function(html){
		  	$('#content .cushycms').fadeOut(200, function(){
				$(this).html(html).fadeIn('200');
					});
				}
			});
		
		//setup the current page var for the test above
		currentPage = $(this).attr("title") + '.html';
	  
	  	//tell the link to shutup
		return false;		
	});
	
	
	
	$('#footerNav ul.primNav li a').click(function(){
	
			//setup the target page url
			var targetAttr = $(this).attr('title');
			var targetPage = targetAttr + '.html';
			
			//test to see if it's the current page
			if(targetPage == currentPage){
				return false; 
			}
			
			//test to see if it's back to top
			if($(this).parent().hasClass('backUp')){
				$("ul.primNav li").removeClass('active');
				$.scrollTo('#header', 300);
				return false;
			}
			
			//make this the active link
			$(this).parent().addClass('active');

			//remove active styles and style the sidebar
			$(this).parent().siblings().removeClass('active');			
			$('#header ul.primNav li').removeClass('active');
			$('#subnav-col ul li').removeClass('active');
			$('#subnav-col ul li').css('border-top', '1px solid #4F050B');

			
			//tell the footer to activate it's link
			$('ul.primNav li a').each(function(){
				if($(this).attr('title') == targetAttr){
					$(this).parent().addClass('active');
				}
			});
			
			//load the page in the target div and scroll to it
			$.ajax({
			  url: targetPage,
			  cache: false,
			  success: function(html){
			  	$('#content .cushycms').fadeOut(200, function(){
					$(this).html(html).fadeIn('200');
						});
			   		}
				});
				
		  	//setup the current page var for the test above
			currentPage = $(this).attr("title") + '.html';
	  
	  	//tell the link to shutup
		return false;			
	});
	
	
	//Yes, this can be turned into a plugin or a more concise function.  I'm tired.  
	
	
	//tertiarey nav
	$('#subnav-col ul li a').click(function(){
	
		if($(this).hasClass('localLink') == true){
		
			if($(this).parent().hasClass('active')){
				return false;
			}

			$('#header ul li, #footerNav ul li').removeClass('active');
		
			$(this).parent().addClass('active');
			$(this).parent().css('border-top', '1px solid #aF050B');
			$(this).parent().siblings().removeClass('active');
			$(this).parent().siblings().css('border-top', '1px solid #4F050B');
						
			var targetPage = $(this).attr("title") + '.html';
			
			$.ajax({
			  url: targetPage,
			  success: function(html){
				$('#content').fadeOut(200, function(){
					$(this).html(html).fadeIn('200');
					})
			   }
			});
		  	currentPage = $(this).attr("title") + '.html';
			return false;
		};
	});
			
});