﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

/*
* Namespace for RF Hotels that contains functionalities that share acroos the rocco sites
* such as top menu bar, slideshow, and panel toggle (Choo 20/07/2009)
*/
var RF = window.RF ||
{};

RF.Hotels = {};

RF.Hotels = (function()
{
	function init()
	{
		topMenu();
		slideShow();
		panels();
		expandDefaultPanelItem();
		slidingBodyContent();
		logging();
	}

	function topMenu()
	{
		//Show popup on click
		$("#header #top_menu li a").click(function(e)
		{
			if ($(this).hasClass("logo") == false) {
				//Css class of the click element must match the popup id
				var currentLanguage = $("#current_language_hiddenfield").val();
				var imageFilename = $(this).attr("name").split('_')[1] + "_images.htm";
				topMenuPopupHandler($("#" + $(this).attr("name")), imageFilename, currentLanguage);
				e.preventDefault();
			}
		});
		//Show popup on url keys
		if (window.location.hash.length > 0) {
			switch (window.location.hash) {
				case "#p-company":
					$("#top_menu a#company").click();
					break;
				case "#p-hotels":
					$("#top_menu a#hotels").click();
					break;
				case "#p-resorts":
					$("#top_menu a#resorts").click();
					break;
				case "#p-restaurants":
					$("#top_menu a#restaurants").click();
					break;
				case "#p-spas":
					$("#top_menu a#spas").click();
					break;
				case "#p-packages":
				case "#p-arrangements":
					$("#top_menu a#packages").click();
					break;
				case "#p-meetings-and-events":
				case "#p-meetings":
					$("#top_menu a#meetings").click();
					break;
				case "#p-weddings":
				case "#p-hochzeiten":
					$("#top_menu a#weddings").click();
					break;
				case "#p-families":
					$("#top_menu a#kids").click();
					break;
				case "#p-gifts":
				case "#p-geschenkgutscheine":
					$("#top_menu a#gifts").click();
					break;
				case "#p-festive":
				case "#p-christmas":
				case "#p-festlich":
					$("#top_menu a#festive").click();
					break;
			}
		}

		function topMenuPopupHandler(element, imageFilename, language)
		{
			if ($(element).is(":visible") == false) {
				$(".popup_content").hide();
				$(element).slideDown("fast", function getImages()
				{
					//Ajax calls to load images
					$(element).find(".include_image_container").load("/assets/group/" + language + "/html/include/" + imageFilename);
				});
				$("#header #top_menu li a").removeClass("active");
				$("#header #top_menu li ." + $(element).attr("id")).addClass("active");
				$("#overlay").css("height", $("#maincontent").css("height"));
				jQuery.each(jQuery.browser, function(i, val)
				{
					if (val == true) {
						if (i == "msie" && jQuery.browser.version.substr(0, 3) == "6.0") {
							var height = 0;
							if ($(".landing_image_container").length > 0) {
								height = $(".landing_image_container").css("height");
								height = height.substring(0, height.length - 2);
								height = parseInt(height, 10);
							}
							else {
								var el = document.getElementById("content_container");
								height = el.offsetHeight;
								height = parseInt(height, 10);
							}
							$("select").hide();
							$("#overlay").css("height", height);
						}
					}
				});
				$("#overlay").fadeIn("fast");
			} else {
				$(element).slideUp("fast");
				$(this).parents("ul").children("li").children("a").css("color", "#666666");
				$("#overlay").fadeOut("fast");
				//$("select").show();
				$("#top_menu li a").removeClass("active");
			}
		};
		//Hover
		$("#popup_hotels .right_panel a, #popup_resorts .left_panel a, #popup_packages .right_panel a, #popup_meetings .left_panel a, #popup_kids .right_panel a,#popup_festive .right_panel a, #popup_weddings .left_panel a, #popup_restaurants .right_panel a, #popup_spas .left_panel a, #popup_gifts .right_panel a").hover(function()
		{
			try {
				var elementClass = $(this).attr('class');
				if (elementClass != "" || elementClass != null) {
					$("img." + elementClass).fadeIn("slow");
				}
			} catch (e) { }
		}, function()
		{
			try {
				var elementClass = $(this).attr('class');
				if (elementClass != "" || elementClass != null) {
					$("img." + elementClass).fadeOut("slow");
				}
			} catch (e) { }
		});
		//Map
		$("#popup_hotels .left_panel li a").hover(function(e)
		{
			var selectedItem = $(this).parent().attr("class");
			var parent = $("#popup_hotels .right_panel li ." + selectedItem).parent().parent().parent();
			var parentName = $(parent).attr("class");
			if (parent.is(":visible") == false) {
				if (parentName == "opened_hotels_container") {
					switchToOpenedHotels();
				}
				else {
					switchToOpeningHotels();
				}
			}
			$("#popup_hotels .right_panel li ." + selectedItem).addClass("active");
		});
		$("#popup_hotels .left_panel li a").mouseout(function(e)
		{
			var selectedItem = $(this).parent().attr("class");
			$("#popup_hotels .right_panel li ." + selectedItem).removeClass("active");
		});
		//Close button
		$(".popup_content .close").click(function(e)
		{
			$("#overlay").hide();
			$(".popup_content").slideUp();
			$("#top_menu li a").removeClass("active");
		});
		//Hotel paging
		var openedHotelsContainer = $(".opened_hotels_container");
		var openingHotelsContainer = $(".opening_hotels_container");
		var openedHotelTrigger = $(".opened_hotels_trigger");
		var openingHotelTrigger = $(".opening_hotels_trigger");
		$(openingHotelsContainer).hide();
		$(openedHotelTrigger).hide();
		$(".hotel_paging_container a").click(function(e)
		{
			if ($(openedHotelsContainer).is(":visible") == true) {
				switchToOpeningHotels();
			}
			else {
				switchToOpenedHotels();
			}
			e.preventDefault();
		});

		function switchToOpeningHotels()
		{
			$(openedHotelsContainer).hide();
			$(openingHotelsContainer).fadeIn("slow");
			$(openedHotelTrigger).show();
			$(openingHotelTrigger).hide();
		}

		function switchToOpenedHotels()
		{
			$(openedHotelsContainer).show("slow");
			$(openingHotelsContainer).hide();
			$(openedHotelTrigger).hide();
			$(openingHotelTrigger).show();
		}
	}

	function slideShow()
	{
		slideshowEngine = new imageslideshowEngine();
		slideshowEngine.images = $("#image_container .images img").get();
		slideshowEngine.init(6000, "slow", imageSwitched);
		$("#thumbs img").each(function(i)
		{
			$(this).click(function(e)
			{
				slideshowEngine.jumpToPair(i, true);
				var altText = $(this).attr("alt");
				$("#image_caption").slideUp("fast", function()
				{
					$("#image_caption").html(altText).slideDown("slow");
				});
				e.preventDefault();
			});
		});
	}
	function imageSwitched(i)
	{
		try {
			if ($("#image_container .images img").size() > 0) {
				var altText = $("#image_container .images img").eq(i.to).attr("alt");
				$("#image_caption").slideUp("fast", function()
				{
					$("#image_caption").html(altText).slideDown("slow");
				});
			}
		} catch (e) { }
	}

	function panels()
	{
		$("#right_panel #panel li").each(function()
		{
			$(this).children(".panel_content").hide();
		});
		$("#right_panel #panel li .panel_header").click(function(e)
		{
			if ($(this).hasClass("default_link") == true) {
				return;
			}
			if ($(this).nextAll(".panel_content").is(":visible") == false) {
				$("#right_panel #panel li").children(".panel_content").slideUp("slow");
				$("#right_panel #panel li a").removeClass("active");
				$(this).addClass("active");
				$(this).nextAll(".panel_content").slideDown("slow");
			}
			else {
				$(this).removeClass("active");
				$(this).nextAll(".panel_content").slideUp("slow");
			}
			e.preventDefault();
		});
	}

	function expandDefaultPanelItem()
	{
		$("#panel #check_availability a.panel_header").addClass("active");
		$("#panel #check_availability .panel_content").show();
		$("#panel #online_booking a.panel_header").addClass("active");
		$("#panel #online_booking .panel_content").show();
		if ($("#panel #check_availability").size() == 0) {
			$("#panel #speak_to_hotel_panel a.panel_header").addClass("active");
			$("#panel #speak_to_hotel_panel .panel_content").show();
		}
	}

	function propertyChanged(sender, e)
	{
		try {
			var selectedValue = $(sender).val();
			if (selectedValue != "-1") {
				//Pickup current local from masterpage
				var currentLocale = $(".current_locale_hiddenfield").val().split('-')[0];
				switch (e) {
					case "factsheets":
						window.location = "http://" + selectedValue;
						break;
					case "brochures":
						switch (selectedValue) {
							case "www.verduraresort.com":
							case "www.thebalmoralhotel.com":
								window.location = "http://" + selectedValue + "/special/brochure";
								break;
							case "www.theaugustinehotel.de":
								window.location = "http://" + selectedValue + "/special/broschÃ¼ren";
								break;
							case "www.assoufid.com":
								window.location = "http://www.assoufid.com/about/";
								break;
							default:
								window.location = "http://" + selectedValue + "/special/brochures";
								break;
						}
					case "photographs":
						var categories = "";
						var categoryList = [];
						switch (selectedValue) {
							case "all":
								categoryList.push(4, 12, 6, 13, 8, 14, 7, 2, 3, 1, 9, 16, 15, 5, 10, 17, 0);
								break;
							case "abudhabi":
								categoryList.push(4, 6, 7, 2, 3, 5, 0);
								break;
							case "angleterre":
								categoryList.push(4, 12, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "amigo":
								categoryList.push(4, 6, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "assoufid":
								categoryList.push(13, 14, 1, 9, 10, 17, 0);
								break;
							case "astoria":
								categoryList.push(4, 12, 6, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "augustine":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "balmoral":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "browns":
								categoryList.push(4, 12, 13, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "charles":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 9, 5, 0);
								break;
							case "de_rome":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 9, 5, 0);
								break;
							case "de_russie":
								categoryList.push(4, 6, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "jeddah":
								categoryList.push(2, 0);
								break;
							case "le_richemond":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "lowry":
								categoryList.push(4, 6, 13, 8, 7, 2, 3, 9, 5, 0);
								break;
							case "roccoforte_team":
								categoryList.push(8, 10, 0);
								break;
							case "savoy":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 1, 9, 5, 0);
								break;
							case "verdura":
								categoryList.push(4, 12, 13, 8, 14, 7, 2, 3, 1, 9, 16, 15, 5, 10, 0);
								break;
							case "villa_kenedy":
								categoryList.push(4, 12, 13, 8, 7, 2, 3, 9, 5, 0);
								break;
							default:
								break;
						}
						categories = generateCategories(categoryList, currentLocale);
						$(".photographs_category_container").html(categories);
						break;
				}
			}
		} catch (e) { }
	}

	function generateCategories(categoryList, currentLocale)
	{
		var result = "";
		var title = "";
		for (var i = 0; i < categoryList.length; i++) {
			switch (currentLocale) {
				case "en":
					title = categoryList[i] == 0 ? "Show All Images" : title;
					title = categoryList[i] == 1 ? "Local Images" : title;
					title = categoryList[i] == 2 ? "Hotel External Images" : title;
					title = categoryList[i] == 3 ? "Hotel Internal Reception & Lobby Images" : title;
					title = categoryList[i] == 4 ? "Bedroom & Bathroom Images" : title;
					title = categoryList[i] == 5 ? "Restaurant and Bar Images" : title;
					title = categoryList[i] == 6 ? "Conference & Meeting Room Images" : title;
					title = categoryList[i] == 7 ? "Health Club & Spa Images" : title;
					title = categoryList[i] == 8 ? "Generic Images" : title;
					title = categoryList[i] == 9 ? "Logos" : title;
					title = categoryList[i] == 10 ? "Team Images" : title;
					title = categoryList[i] == 12 ? "Conference & Banqueting" : title;
					title = categoryList[i] == 13 ? "Detail Images" : title;
					title = categoryList[i] == 15 ? "Resort Images" : title;
					title = categoryList[i] == 16 ? "Pool" : title;
					title = categoryList[i] == 17 ? "Villas" : title;
					break;
				case "de":
					title = categoryList[i] == 0 ? "Alle Bilder zeigen" : title;
					title = categoryList[i] == 1 ? "Umgebung" : title;
					title = categoryList[i] == 2 ? "Hotelansicht" : title;
					title = categoryList[i] == 3 ? "Rezeption & Lobby" : title;
					title = categoryList[i] == 5 ? "Restaurant and Bar" : title;
					title = categoryList[i] == 4 ? "Zimmer & Suiten" : title;
					title = categoryList[i] == 6 ? "Konferenz & Bankett" : title;
					title = categoryList[i] == 7 ? "Fitness & Spa" : title;
					title = categoryList[i] == 8 ? "Generische" : title;
					title = categoryList[i] == 9 ? "Logos" : title;
					title = categoryList[i] == 10 ? "Team" : title;
					title = categoryList[i] == 12 ? "Konferenz & Bankett" : title;
					title = categoryList[i] == 13 ? "Detailansichten" : title;
					title = categoryList[i] == 15 ? "Resort Images" : title;
					title = categoryList[i] == 16 ? "Pool" : title;
					title = categoryList[i] == 17 ? "Villas" : title;
					break;
			}
			result += "<option value=\"" + categoryList[i] + "\">" + title + "</option>";
		}
		result = result != "" ? "<select class=\"photographs_category_dropdownlist\">" + result + "</select>" : "";
		return result;
	}

	function photographs()
	{
		var url = "http://imagelibrary.quadrant.uk.com/(S(fpug5uabzqe0q1450aovaq55))/rf/";
		var selectedProperty = $(".phogographs_dropdownlist").val();
		var selectedCategory = $(".photographs_category_dropdownlist").val();
		var parameters = "";
		var type = "";
		var clientId = 0;
		clientId = selectedProperty == "hotels" ? 0 : clientId;
		clientId = selectedProperty == "abudhabi" ? 68 : clientId;
		clientId = selectedProperty == "angleterre" ? 35 : clientId;
		clientId = selectedProperty == "browns" ? 33 : clientId;
		clientId = selectedProperty == "amigo" ? 2 : clientId;
		clientId = selectedProperty == "assoufid" ? 69 : clientId;
		clientId = selectedProperty == "astoria" ? 3 : clientId;
		clientId = selectedProperty == "de_rome" ? 46 : clientId;
		clientId = selectedProperty == "de_russie" ? 5 : clientId;
		clientId = selectedProperty == "jeddah" ? 67 : clientId;
		clientId = selectedProperty == "savoy" ? 9 : clientId;
		clientId = selectedProperty == "le_richemond" ? 41 : clientId;
		clientId = selectedProperty == "roccoforte_team" ? 32 : clientId;
		clientId = selectedProperty == "verdura" ? 49 : clientId;
		clientId = selectedProperty == "augustine" ? 64 : clientId;
		clientId = selectedProperty == "balmoral" ? 4 : clientId;
		clientId = selectedProperty == "charles" ? 42 : clientId;
		clientId = selectedProperty == "lowry" ? 6 : clientId;
		clientId = selectedProperty == "villa_kenedy" ? 44 : clientId;
		clientId = selectedProperty == "all" ? 0 : clientId;

		//If category is selected
		if (selectedCategory != null && selectedCategory != "" && selectedCategory != undefined) {
			type = "category";
		} else {
			type = "preview";
			selectedProperty = "0";
			selectedCategory = "";
		}
		window.location = window.location.protocol + "//" + window.location.host + "/photographs?type=" + type + "&client=" + clientId + "&category=" + selectedCategory;
		return false;
	}

	function ajaxCalendarArrivalDate(sender, e)
	{
		var selectedDate = sender._selectedDate;
		var todayDate = new Date();
		if (selectedDate < todayDate) {
			sender._selectedDate = todayDate;
			sender._textbox.set_Value(sender._selectedDate.format(sender._format));
			return false;
		}
		var arrivalDateElement;
		var departureDateElement;
		var delimiter;
		var type;
		if (sender._id.match("DLink") != null) {
			arrivalDateElement = ".dlink_arrival_date";
			departureDateElement = ".dlink_departure_date";
			type = "textbox";
		}
		else if (sender._id.match("Panel") != null) {
			arrivalDateElement = ".panel_arrival_date";
			departureDateElement = ".panel_departure_date";
			type = "textbox";
		}
		else if (sender._id.match("QuickBook") != null) {
			arrivalDateElement = ".quickbook_arrival_date";
			departureDateElement = ".quickbook_departure_date";
			type = "textbox";
		}
		var arrivalDate = $(arrivalDateElement).val();
		var temp = [];
		var temp2 = [];
		var departureDate = new Date();
		var arrivalDateJoined;
		var departureDateJoined
		if (arrivalDate.indexOf("/") > -1) {
			delimiter = "/";
		}
		else if (arrivalDate.indexOf(".") > -1) {
			delimiter = ".";
		}
		temp = arrivalDate.split(delimiter);

		//temp[0] = date
		//temp[1] = month
		//temp[2] = year		
		if (temp[0].charAt(0) == "0") {
			temp[0] = temp[0].substring(1, 2);
		}
		if (type == "textbox") {
			$(arrivalDateElement).val(temp[0] + delimiter + temp[1] + delimiter + temp[2]);
		}

		departureDate.setFullYear(temp[2], temp[1] - 1, temp[0]);
		departureDate.setFullYear(departureDate.getFullYear(), departureDate.getMonth(), departureDate.getDate() + 1);
		departureDate = departureDate.format('dd/MM/yyyy');
		if (departureDate.indexOf("/") > -1) {
			delimiter = "/";
		}
		else if (departureDate.indexOf(".") > -1) {
			delimiter = ".";
		}
		temp2 = departureDate.split(delimiter);
		if (temp2[0].charAt(0) == "0") {
			temp2[0] = temp2[0].substring(1, 2);
		}

		if (type == "dropdown") {
			$(departureDateDropDownList).val(parseInt(temp2[0], 10));
			if ($(departureMonthYearDropDownList).val().indexOf("/") > -1) {
				delimiter = "/";
			}
			else if ($(departureMonthYearDropDownList).val().indexOf(".") > -1) {
				delimiter = ".";
			}
			departureDateJoined = temp2[1] + delimiter + temp2[2];
			$(departureMonthYearDropDownList).val(departureDateJoined);
		}
		else if (type == "textbox") {
			$(departureDateElement).val(temp2[0] + delimiter + temp2[1] + delimiter + temp2[2]);
		}
	}

	function ajaxCalendarDepartureDate(sender, e)
	{
		var arrivalDateElement;
		var departureDateElement;
		var delimiter;
		var type;
		if (sender._id.match("DLink") != null) {
			arrivalDateElement = ".dlink_arrival_date";
			departureDateElement = ".dlink_departure_date";
			type = "dropdown";
		}
		else if (sender._id.match("Panel") != null) {
			arrivalDateElement = ".panel_arrival_date";
			departureDateElement = ".panel_departure_date";
			type = "textbox";
		}
		else if (sender._id.match("QuickBook") != null) {
			arrivalDateElement = ".quickbook_arrival_date";
			departureDateElement = ".quickbook_departure_date";
			type = "textbox";
		}

		var temp = [];
		var temp2 = [];
		var arrivalDate = new Date();
		var departureDate = new Date();
		var departureDateJoined;
		if ($(arrivalDateElement).val().indexOf("/") > -1) {
			delimiter = "/";
		}
		else if ($(arrivalDateElement).val().indexOf(".") > -1) {
			delimiter = ".";
		}
		temp = $(arrivalDateElement).val().split(delimiter);
		arrivalDate.setFullYear(temp[2], temp[1] - 1, temp[0]);
		temp2 = $(departureDateElement).val().split(delimiter);
		departureDate.setFullYear(temp2[2], temp2[1] - 1, temp2[0]);

		if (departureDate < arrivalDate) {
			var newDepartureDate = arrivalDate;
			newDepartureDate.setFullYear(newDepartureDate.getFullYear(), newDepartureDate.getMonth(), newDepartureDate.getDate() + 1);
			sender._selectedDate = newDepartureDate;
			sender._textbox.set_Value(sender._selectedDate.format(sender._format));
			return false;
		}

		if (departureDate < arrivalDate) {
			if (type == "textbox") {
				arrivalDate.setFullYear(arrivalDate.getFullYear(), arrivalDate.getMonth(), arrivalDate.getDate() + 1);
				$(departureDateElement).val(arrivalDate.getDate() + delimiter + arrivalDate.getMonth() + delimiter + arrivalDate.getFullYear());
			}
		}
	}

	function ajaxCalendarDepartureDateIsShowing(sender, e)
	{
		var dateValue = sender._element.value;
		if (dateValue.indexOf("/") > -1) {
			delimiter = "/";
		}
		else if (dateValue.indexOf(".") > -1) {
			delimiter = ".";
		}
		var temp = [];
		temp = dateValue.split(delimiter);
		var newDate = new Date();
		newDate.setFullYear(temp[2], temp[1] - 1, temp[0]);
		sender._selectedDate = newDate;
	}

	function arrivalDropDownList(type)
	{
		var arrivalDateDropDownList;
		var arrivalMonthYearDropDownList;
		var departureDateDropDownList;
		var departureMonthYearDropDownList;
		var delimiter;
		switch (type) {
			case "panel":
				arrivalDateDropDownList = ".panel_arrival_date_dropdownlist";
				arrivalMonthYearDropDownList = ".panel_arrival_monthyear_dropdownlist";
				departureDateDropDownList = ".panel_departure_date_dropdownlist";
				departureMonthYearDropDownList = ".panel_departure_monthyear_dropdownlist";
				break;
			case "dlink":
				arrivalDateDropDownList = ".dlink_arrival_date_dropdownlist";
				arrivalMonthYearDropDownList = ".dlink_arrival_monthyear_dropdownlist";
				departureDateDropDownList = ".dlink_departure_date_dropdownlist";
				departureMonthYearDropDownList = ".dlink_departure_monthyear_dropdownlist";
				break;
		}

		var selectedArrivalDate = $(arrivalDateDropDownList).val();
		var selectedArrivalMonthYear = $(arrivalMonthYearDropDownList).val();
		var temp = [];
		var arrivalDate = new Date();
		var departureDate = new Date();
		var departureDateJoined;
		if (selectedArrivalMonthYear.indexOf("/") > -1) {
			delimiter = "/";
		}
		else if (selectedArrivalMonthYear.indexOf(".") > -1) {
			delimiter = ".";
		}
		temp = selectedArrivalMonthYear.split(delimiter);
		//temp[0] = month
		//temp[1] = year
		arrivalDate.setFullYear(temp[1], temp[0] - 1, selectedArrivalDate);
		departureDate.setFullYear(arrivalDate.getFullYear(), arrivalDate.getMonth(), arrivalDate.getDate() + 1);
		$(departureDateDropDownList).val(departureDate.getDate());
		departureDateJoined = departureDate.getMonth() + 1;
		if (departureDateJoined < 10) {
			departureDateJoined = "0" + departureDateJoined;
		}
		departureDateJoined = departureDateJoined + delimiter + departureDate.getFullYear();
		$(departureMonthYearDropDownList).val(departureDateJoined);
		temp = selectedArrivalMonthYear.split(delimiter);

		if (temp[0].substring(0, 1) == 0) {
			temp[0] = temp[0].substring(1, temp[0].length);
		}
		switch (temp[0]) {
			//february                                                                                                                                                                                                                                                      
			case '2':
				if (selectedArrivalDate > 28) {
					$(arrivalDateDropDownList).val(28);
					$(departureDateDropDownList).val(departureDate.getDate() - 1);
				}
				break;
			//april, june, september or november                                                                                                                                                                                                                                                                                                                        
			case '4':
			case '6':
			case '9':
			case '11':
				if (selectedArrivalDate > 30) {
					$(arrivalDateDropDownList).val(30);
					$(departureDateDropDownList).val(departureDate.getDate() - 1);
				}
				break;
		}
	}

	function departureDropDownList(type)
	{
		var arrivalDateDropDownList;
		var arrivalMonthYearDropDownList;
		var departureDateDropDownList;
		var departureMonthYearDropDownList;
		var delimiter;
		switch (type) {
			case "panel":
				arrivalDateDropDownList = ".panel_arrival_date_dropdownlist";
				arrivalMonthYearDropDownList = ".panel_arrival_monthyear_dropdownlist";
				departureDateDropDownList = ".panel_departure_date_dropdownlist";
				departureMonthYearDropDownList = ".panel_departure_monthyear_dropdownlist";
				break;
			case "dlink":
				arrivalDateDropDownList = ".dlink_arrival_date_dropdownlist";
				arrivalMonthYearDropDownList = ".dlink_arrival_monthyear_dropdownlist";
				departureDateDropDownList = ".dlink_departure_date_dropdownlist";
				departureMonthYearDropDownList = ".dlink_departure_monthyear_dropdownlist";
				break;
		}
		var selectedArrivalDate = $(arrivalDateDropDownList).val();
		var selectedArrivalMonthYear = $(arrivalMonthYearDropDownList).val();
		var selectedDepartureDate = $(departureDateDropDownList).val();
		var selectedDepartureMonthYear = $(departureMonthYearDropDownList).val();
		var temp = [];
		var temp2 = [];
		var arrivalDate = new Date();
		var departureDate = new Date();
		var departureDateJoined;
		if (selectedArrivalMonthYear.indexOf("/") > -1) {
			delimiter = "/";
		}
		else if (selectedArrivalMonthYear.indexOf(".") > -1) {
			delimiter = ".";
		}
		temp = selectedArrivalMonthYear.split(delimiter);
		arrivalDate.setFullYear(temp[1], temp[0] - 1, selectedArrivalDate);
		temp2 = selectedDepartureMonthYear.split(delimiter);
		departureDate.setFullYear(temp2[1], temp2[0] - 1, selectedDepartureDate);
		departureDateJoined = arrivalDate.getMonth() + 1;
		if (departureDateJoined < 10) {
			departureDateJoined = "0" + departureDateJoined;
		}
		departureDateJoined = departureDateJoined + delimiter + arrivalDate.getFullYear();
		if (departureDate < arrivalDate) {
			$(departureDateDropDownList).val((arrivalDate.getDate() + 1));
			$(departureMonthYearDropDownList).val(departureDateJoined);
		}

		temp = [];
		temp = selectedDepartureMonthYear.split(delimiter);
		//temp[0] = month
		//temp[1] = year
		switch (temp[0]) {
			//february                                                                                                                                                                                                      
			case '2':
				if (selectedDepartureDate > 28) {
					$(departureDateDropDownList).val(28);
				}
				break;
			//april, june, september or november                                                                                                                                                                                                      
			case '4':
			case '6':
			case '9':
			case '11':
				if (selectedDepartureDate > 30) {
					$(departureDateDropDownList).val(30);
				}
				break;
		}
	}

	function setPPCTracking(sender)
	{
		try {
			//For google analytics PPC cross-site tracking
			if ($(sender).is("a") == true) {
				_gaq.push(['_link'], sender.href);
			}
			else {
				var currentForm = document.getElementById("aspnetForm");
				_gaq.push(['_linkByPost'], currentForm);
			}
		} catch (e) { }
	}

	function slidingBodyContent()
	{
		$("#canvas #content .curtain").hide();
		$("#canvas #content .trigger a").click(function(e)
		{
			if ($(this).parent().nextAll(".curtain").is(":visible") == false) {
				$(this).parent().nextAll(".curtain").slideDown("fast");
			}
			else {
				$(this).parent().nextAll(".curtain").slideUp("fast");
			}
			e.preventDefault();
		});
	}

	function ajaxCalendarCustomDate(dateTime)
	{
		//Prevent showing month in the past
		if (dateTime != null && dateTime != undefined) {
			var firstDayOfThisMonth = new Date();
			firstDayOfThisMonth.setFullYear(firstDayOfThisMonth.getFullYear(), firstDayOfThisMonth.getMonth(), 1);
			firstDayOfThisMonth.setHours(12, 0, 0, 0);
			if (dateTime.target == undefined) {
				if (dateTime < firstDayOfThisMonth) {
					return false;
				}
			}
			else {
				var yesterday = new Date();
				yesterday.setDate(yesterday.getDate() - 1);
				if (dateTime.target.mode == "day" && dateTime.target.date < yesterday) {
					return false;
				}
			}
			return true;
		}

		var today = new Date();
		today.setDate(today.getDate() - 1);
		//Styling for date in the past
		$(".ajax__calendar_day").each(function()
		{
			var sender = $(this);
			var title = $(sender).attr("title").toLowerCase();
			//Convert value to english
			title = title.replace(",", "");
			title = title.replace(".", "");
			//German
			title = title.replace("montag", "");
			title = title.replace("dienstag", "");
			title = title.replace("mittwoch", "");
			title = title.replace("donnerstag", "");
			title = title.replace("freitag", "");
			title = title.replace("samstag", "");
			title = title.replace("sonntag", "");
			title = title.replace("januar", "January");
			title = title.replace("februar", "February");
			title = title.replace("märz", "March");
			title = title.replace("mai", "May");
			title = title.replace("juni", "June");
			title = title.replace("juli", "July");
			title = title.replace("oktober", "October");
			title = title.replace("dezember", "December");
			//Russian
			title = title.replace("г", "");
			title = title.replace("январь", "January");
			title = title.replace("февраль", "February");
			title = title.replace("март", "March");
			title = title.replace("апрель", "April");
			title = title.replace("май", "May");
			title = title.replace("июнь", "June");
			title = title.replace("июль", "July");
			title = title.replace("август", "August");
			title = title.replace("сентябрь ", "September");
			title = title.replace("октября", "October");
			title = title.replace("ноября", "November");
			title = title.replace("декабря", "December");

			var cellDate = new Date(title);
			$(sender).parent().removeClass("past");
			if (cellDate < today) {
				$(sender).parent().addClass("past");
			}
			cellDate = null;
		});
		return true;
	}

	function logging()
	{
		$(".server_error").click(function(e)
		{
			var sender = $(this);
			if ($(sender).hasClass("trust")) {
				//Log trust booking link
				$.ajax({
					type: "POST",
					url: "/common/modules/roccoforte/roccobe/roccobe_gui/handler/LoggingHandler.ashx",
					data: "command=trust_booking",
					success: function(response)
					{
					}
				});
			}
		});
	}

	return {
		init: init,
		expandDefaultPanelItem: expandDefaultPanelItem,
		propertyChanged: propertyChanged,
		photographs: photographs,
		ajaxCalendarArrivalDate: ajaxCalendarArrivalDate,
		ajaxCalendarDepartureDate: ajaxCalendarDepartureDate,
		ajaxCalendarCustomDate: ajaxCalendarCustomDate,
		ajaxCalendarDepartureDateIsShowing: ajaxCalendarDepartureDateIsShowing,
		arrivalDropDownList: arrivalDropDownList,
		departureDropDownList: departureDropDownList,
		setPPCTracking: setPPCTracking
	};
})();

$(document).ready(RF.Hotels.init);
