﻿/// <reference path="../../_shared/scripts/jquery-1.3.2-vsdoc.js" />

/*
* Namespace for RF Hotel_2
*/
var RF = window.RF ||
{};

RF.Hotel_2 = {};

RF.Hotel_2 = (function() {

	var fastSpeed = 500;
	var slowSpeed = 1000;
	var defaultSpeed = "fast";
	var slideshowEngine;
	var flashTag = "";
	var allText = "";
	var altText = "";
	var currentIndex = -1;
	var landingImageCount = 0;
	var loop = 0;
	var targetIndex;

	function init() {
		groupRates();
		groupRatesSlideShow();
	}

	function introduction() {
		$(".landing_rf_logo_container").show();
		if ($(".landing_logo_container").is(":visible") == true) {
			setTimeout(animateLogo, 4000);
		}
		function animateLogo() {
			var value = $(".landing_text_container").html().trim().split('___')[0];
			var width = "";
			var height = "";
			var path = "";
			if (value == "promotion") {
				//Exception for winter promotions
				var currentLanguage = $("#current_language_hiddenfield").val();
				if (currentLanguage == "de") {
					path = "/common/templates/hotel/hotel_2/flash/winter_de.swf";
				}
				else {
					path = "/common/templates/hotel/hotel_2/flash/winter.swf";
				}
				width = "550";
				height = "300";
				$(".landing_text_container").css("margin-left", "75px");
				$(".landing_text_container").css("margin-top", "60px");
			}
			else {
				width = "911";
				height = "150";
				path = "/common/templates/hotel/hotel_2/flash/landing_text.swf";
			}
			flashTag = '<object width="' + width + '" height="' + height + '" id="RoccoForteLandingText" data="' + path + '" type="application/x-shockwave-flash" >' +
					   '<param value="' + path + '" name="movie" />' +
					   '<param value="high" name="quality" />' +
					   '<param value="transparent" name="wmode" />' +
					   '<param value="dynamic_text=__value__" name="flashvars" />' +
					   '</object>';
			flashTag = flashTag.replace("__value__", escape(value));
			flashTag = flashTag.replace("__value__", escape(value));
			landingSlideShow();
			$(".landing_text_container").html("");
			$(".landing_logo_container").fadeOut(slowSpeed, function loadDynamicText() {
				$(".landing_text_container").html(flashTag).hide().delay(1000).fadeIn("fast");
			});
		}
	}

	function landingSlideShow() {
		slideshowEngine = new imageslideshowEngine();
		landingImageCount = $(".landing_image_container a img").size();
		slideshowEngine.images = $(".landing_image_container a img").get();
		var displayTime = $(".landing_image_display_time").find("input[type=hidden]").val();
		displayTime = (parseInt(displayTime, 10) + 2) * 1000;
		allText = $(".landing_text_container").html().trim().split('___');
		altText = $(".landing_image_container a img").eq(0).attr("alt");
		slideshowEngine.init(displayTime, slowSpeed, imageSwitch);
	}

	function imageSwitch(i) {
		if (i.to == (landingImageCount - 1)) {
			loop = loop + 1;
			//slideshowEngine.pauseEngine();
		}
		var currentAltText = $(".landing_image_container a img").eq(i.to).attr("alt");
		if (altText != currentAltText) {
			targetIndex = i.to;
			targetIndex = targetIndex == 0 ? landingImageCount : targetIndex;
		}
		if (i.from == targetIndex - 1) {
			if (currentIndex == -1) {
				currentIndex = 1;
			}
			else {
				currentIndex = (loop != 0 && currentIndex == (allText.length - 1)) ? 0 : currentIndex + 1;
				//console.log("landingImageCount=" + landingImageCount + "i.to=" + i.to + "i.from=" + i.from + "currentIndex=" + currentIndex);				
			}
			if (window.document.RoccoForteLandingText) {
				//console.log("sent: " + allText[currentIndex]);
				window.document.RoccoForteLandingText.SetVariable("slogan", escape(allText[currentIndex]));
			}
		}
		altText = currentAltText;
	}

	function groupRates() {
		$(".group_rates_container .each .content").hide();
		$(".group_rates_container .each .findoutmore").click(function(e) {
			if ($(this).nextAll(".content").is(":visible") == false) {
				$(this).nextAll(".content").slideDown(fastSpeed);
			}
			else {
				$(this).nextAll(".content").slideUp(fastSpeed);
			}
			e.preventDefault();
		});
	}

	//Internal functions
	function groupRatesSlideShow() {
		try {
			$(".group_rates_container .each").each(function() {
				slideshowEngine = new imageslideshowEngine();
				slideshowEngine.images = $(this).children(".group_rates_image_container").children("img").get();
				slideshowEngine.init(6000, slowSpeed);
			});
		} catch (e) { }
	}

	return {
		init: init,
		introduction: introduction
	};
})();

$(RF.Hotel_2.init);