﻿
var PP = window.PP ||
{};

if (!PP.Plaza)
{ PP.Plaza = {}; }

PP.Plaza.PageSlides = (function($) {
	var slideshowEngine;
	var config = {
		quoteFadeInterval: 6000,
		quoteFadeSpeed: 500
	};


	function init() {
		/***---start function***/
		//processing booking dropdown values into textboxes

		$(".booking .dateTextBox").datepicker({ dateFormat: 'dd/mm/yy' });

		$('.booking .dateTextBox').change(function() {
			$('.time_textbox').val("");
		})


		$('.booking .timeListBox').change(displayTimeVals);
		$('.booking .time_textbox').val($('.booking .timeListBox').val());

		function displayTimeVals() {
			var curtime = $('.timeListBox').val();
			$('.time_textbox').val(curtime);
		}
		$('.booking .peopleListBox').change(displayQuantityVals);
		$('.booking .quantity_textbox').val($('.booking .peopleListBox').val());

		function displayQuantityVals() {
			var curtime = $('.booking .peopleListBox').val();
			$('.booking .quantity_textbox').val(curtime);

		}
		//slide images
		slideshowEngine = new imageslideshowEngine();
		slideshowEngine.images = $('.slide-images #slide-images-content li').children().get();
		slideshowEngine.init(6000, 1500);

		$('.sub-nav-container img').click(function() {
			$('.sub-nav-container .sub-nav, .sub-nav-container .sub-nav ul').animate({ width: 'toggle' });
		});

		//home page slide show only 
		if ($(".slide-imageshow").is(':visible')) {

			$(".left-column .unit li").hover(function() {
				$(this).addClass("active");
			}, function() {
				$(this).removeClass("active");
			});
			//slide images
			if ($('.slide-images li.first').size() > 0) {
				slideshowEngine = new imageslideshowEngine();
				slideshowEngine.images = $('.slide-images li.first .imageshow').children().get();
				slideshowEngine.init(6000, 1500);
			}
			if ($('.slide-images li.second').size() > 0) {
				slideshowEngine = new imageslideshowEngine();
				slideshowEngine.images = $('.slide-images li.second .imageshow').children().get();
				slideshowEngine.init(6000, 1500);
			}
			if ($('.slide-images li.third').size() > 0) {
				slideshowEngine = new imageslideshowEngine();
				slideshowEngine.images = $('.slide-images li.third .imageshow').children().get();
				slideshowEngine.init(6000, 1500);

			}
		}

		//map
		$('#google_map').click(function(e) {
			$('#pageoverlay').show();
			$('#popup').addClass("active");
			e.preventDefault();
		});

		$('#popup #close').click(function() {
			$('#pageoverlay').hide();
			$('#popup').removeClass("active");
		});

		//****---end function

	}

	$(".check_availability_button").click(function(e) {
		var URL = "";

		var currentRestaurant = $(".current_restaurant").find("input[type=hidden]").val();
		switch (currentRestaurant) {
			case "13593": //Brasserie Joel				
				URL = "http://www.opentable.com/single.aspx?rid=41440&restref=41440";
				break;
			case "13592": //Ichi Sushi
				URL = "http://www.opentable.com/single.aspx?rid=41437&restref=41437";
				break;
			case "13591": //Bar primo
				URL = "http://www.opentable.com/single.aspx?rid=42766&restref=42766";
				break;
			default:
				return false;
		}

		var numberOfPeople = $(".peopleListBox").val(); ;
		var arrivalDate = $(".dateTextBox").val();
		var arrivalTime = $(".timeListBox").val();

		var validDate = new Date();
		validDate.setFullYear(arrivalDate.split("/")[2], arrivalDate.split("/")[1], arrivalDate.split("/")[0]);
		if (validDate.getDate().toString() != "NaN") {
			URL = URL + "&p=" + numberOfPeople + "&d=" + validDate.getMonth() + "/" + validDate.getDate() + "/" + validDate.getFullYear() + " " + arrivalTime.replace(" ", "+");
			window.open(URL, "opentable");
		}
		return false;
	});

	return {
		init: init
	};

})(jQuery);

jQuery(PP.Plaza.PageSlides.init);
