$(document).ready(function() {
	
	var photos 
	
	if ($('#page-drink').length){
		photos = [ {
				"title" : "Bisato Drink Specials",
				"image" : "image14.JPG"
			}, {
				"title" : "Bisato Drink Specials",
				"image" : "image18.JPG"
			}, {
				"title" : "Bisato Drink Specials",
				"image" : "image19.JPG"
			}, {
				"title" : "Bisato Drink Specials",
				"image" : "image20.JPG"
			}, {
				"title" : "Bisato Drink Specials",
				"image" : "image22.JPG"
			}, {
				"title" : "Bisato Drink Specials",
				"image" : "image23.JPG"
			}
		];

	} else if ($('#page-chef').length) {
		photos = [ {
				"title" : "Scott Carsberg",
				"image" : "scott.jpg"
			}
			// , {
			// 				"title" : "Scott Carsberg",
			// 				"image" : "Bisato-3-8-11-11.jpg"
			// 			}, {
			// 				"title" : "Scott Carsberg",
			// 				"image" : "Bisato-3-8-11-06.jpg"
			// 			}
		]
	// } else if ($('#page-contact').length) {
	// 	photos = [ {
	// 			"title" : "",
	// 			"image" : "Bisato-3-8-11-19.jpg"
	// 		}
	// 	]
	} else {
		photos = [ {
				"title" : "Orange Confit with chocolate mousse",
				"image" : "image1.JPG"
			}, {
				"title" : "Pink Lady apple filled Sonoma Foie Gras",
				"image" : "Bisato-3-8-11-01.jpg"
			}, {
				"title" : "Umbrian truffle pasta with fonduta cheese sause and parmesan",
				"image" : "Bisato-3-8-11-04.jpg"
			}, {
				"title" : "Crudo of Escolar, Yellow Tail and Hamachi with oyster mousse",
				"image" : "Bisato-3-8-11-07.jpg"
			}, {
				"title" : "Rum Baba with vanilla creme and apricot glaze",
				"image" : "Bisato-3-8-11-10.jpg"
			}, {
				"title" : "Dark chocolate strips with pistacio creme",
				"image" : "Bisato-3-8-11-12.jpg"
			}, {
				"title" : "Smoked riccota ravioli with Calabrese sauce",
				"image" : "Bisato-3-8-11-13.jpg"
			}, {
				"title" : "Culatello ham and parmesan ice cream with 20-year balsamic ",
				"image" : "Bisato-3-8-11-15.jpg"
			}, {
				// "title" : "The begginings of Orange confit, dish of the year in Seattle Metropolitan Magazine ",
				// 	"image" : "Bisato-3-8-11-18.jpg"				
				// }, {
				"title" : "Domestic salami in olive oil",
				"image" : "image2.JPG"
			}, {
				"title" : "Parma Proscuitto aged 18 months",
				"image" : "image3.JPG"
			}, {
				"title" : "Local Sardelli house cured with blood orange",
				"image" : "image4.JPG"
			}, {
				"title" : "Foie gras filled figs with braised duck ham",
				"image" : "image5.JPG"
			}, {
				"title" : "Red beet blini with house gravlax cured coho salmon",
				"image" : "image6.JPG"
			}, {
				"title" : "Pumpkin risotto flavored with amaretti",
				"image" : "image7.JPG"
			}, {
				"title" : "Selection of Italian Salami",
				"image" : "image10.JPG"
			}, {
				"title" : "Pecorino toscano baked on local cedar with truffle honey",
				"image" : "image11.JPG"
			}, {
				"title" : "Italian cheese selection from the Veneto",
				"image" : "image12.JPG"
			}, {
				"title" : "Warm prawns with fava bean salad",
				"image" : "Bisato-Prawns-Fava-Beans1.jpg"
			}, {
			// 	"title" : "Italian cheese selection from the Veneto",
			// 	"image" : "image13.JPG"
			// }, {
			// 	"title" : "Tomato filled with halibut rillette served with panzanella sauce",
			// 	"image" : "Bisato-Tomato-Halibut-1.JPG"
			// }, {
				"title" : "Squid Pasta",
				"image" : "Bisato-Squid-Pasta-1.JPG"
			}, {
				"title" : "Tomato filled with halibut rillette served with panzanella sauce",
				"image" : "tomato_with_halibut_rillette.jpg"	
			}, {
				"title" : "Bucatini",
				"image" : "Bisato-Bucatini-1.JPG"
			}
		];
	}
	
	// Forward navigation
	$("#arrow-right").click(function() {
		//stopAnimation();
		navigate("next");
		
	});
	$("#arrow-right").css("cursor","pointer")
	
	
	var currentImg = 0;
	
	function navigate (direction) {
		
		// Check which current image we need to show
		// if(direction == "next") {
		// 			currentImg++;
		// 			if(currentImg == photos.length + 1) {
		// 				currentImg = 1;
		// 			}
		// 		} else {
		// 			currentImg--;
		// 			if(currentImg == 0) {
		// 				currentImg = photos.length;
		// 			}
		// 		}

		currentImg++
		showNextImage(photos[currentImg%photos.length]);
	};
	
	
	
	function randomImage(){
		
		currentImg = Math.floor(Math.random()*photos.length);
		var photoObject = photos[currentImg];
		
		$('#bg1').attr("src", "img/" + photoObject.image);
		
		$('#header p').css({"top": -20})
		$('#header p').delay(800).animate({ "top": "0px" }, {duration: 1000, easing: 'easeOutQuint'});
		
		$('#header p').text("~ " + photoObject.title)
	}
	
	function showNextImage(photoObject){

		$("#bg1").fadeOut("fast", function() { 
		  $(this).load(function() { $(this).fadeIn("fast"); }); 
		  $(this).attr("src", "img/" + photoObject.image); 
		});
		
		
		// swap image title
		$('#header p').fadeOut(500, function (){
			$('#header p').text("~ " + photoObject.title).show().css({ "top" : "-20px" }).
			animate({ "top": "0px" }, {duration: 1000, easing: 'easeOutQuint'});
		})
			
	}
	
	// We should statically set the first image
	//navigate("next");
	if ($('#page-home').length) {
		showNextImage(photos[currentImg]);
	} else {
		randomImage()
	}
	
	
	$('#content #text').css({"right":-$(window).width()/2})
	$('#content #text').delay(800).animate({ "right": "0px" }, {duration: 2000, easing: 'easeOutQuint'});
	
	// Beard award toggle
	$('#beard-award-text').hide()
	$('#beard-award').hover(
		function () {
	    	$('#beard-award-text').fadeIn();
	  	}, 
	  	function () {
	    	$('#beard-award-text').fadeOut();
	  	})
	$("#beard-award-text").css("cursor","pointer")
	
	// content box clicked to hide
	$('#content #close').toggle(function() {
	  	$(this).attr("src", "img/open.png"); 
		$('#content #text').fadeOut();
	}, function() {
	  	$(this).attr("src", "img/close.png");
		$('#content #text').fadeIn();
	});
	
	
	var initContentH = $('#content #text p').height();
	//RESIZING
	$(window).resize(function(){
	
		if ($(window).height() < initContentH+265){
			var newH = $(window).height() - 295;
			$('#content p').css({"overflow" : "scroll", "overflow-x" : "hidden", "height":newH, "padding-right": "15px"});
			$('#content #text').css({"border-bottom-width": "100px", "border-bottom-color": "#222"});
		} else {
			$('#content p').css({"overflow" : "hidden", "overflow-x" : "hidden", "height":initContentH, "padding-right": "0px"});
			$('#content #text').css({"border-bottom-width": "10px", "border-bottom-color": "#000"});
		};
	});
	
	$(window).resize();
	
});


