$(function(){

	(function($) {
	  var cache = [];
	  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
	
	$('div.menu section:first-child').show();

	$('ul.menu li a').click(function(){
		var clicked = $(this).parent().index();
		$('div.menu section').hide();
		$('div.menu section:eq(' + clicked + ')').fadeIn('fast');
		console.log(clicked);
		var backgroundimg = $(this).attr('rel');
		console.log(backgroundimg);
		$("div#wrapper div.food, div#wrapper div.drinks").css("background","url(" + backgroundimg + ")");
		return false;
	})

	$('ul.menu li a').each(function(){
		var bgpreload = $(this).attr('href');
		jQuery.preLoadImages(bgpreload);
	});
	



	$('ul.thumbs li img').click(function(){

		$('ul.thumbs li img#selected').attr('id','');
		$(this).attr('id','selected');
		var clicked = $(this).attr('rel');
		
		$('div.gallery img:visible').stop().fadeOut(250, function() { 
			$('div.gallery img.' + clicked).fadeIn(500)
		});

		$('div.captions span:visible').stop().fadeOut(250, function() { 
			$('div.captions span.' + clicked).fadeIn(500)
		});

	});

});

