/***************  javascript/comp.allHotelsSlideshow.js  ***************/
	// ONLY FOR GROUP HOMEPAGE AND HOTELS PAGE

	jQuery(document).ready(function(){
		$('.widget_bestRate').pukkaPNGFix();
		$('#illustrations .slideshow').cycle({fx: 'fade', before:onbefore});
		
		$("#reservation-form .hotel select").change(function(){
			$('#illustrations .slideshow').cycle('pause');
			var hotelId = this.value;
			var option = $("option[value=" + hotelId + "]", this)[0];
			var hotelKey = option.className.match(/hotel-([^\s]*)/)[1];
			showHotel(hotelKey);
		});
	});
	
	onbefore = function(prevelem)
	// Will be called when the slideshow is about to fade out the frame
	// 'prevelem' is the frame to fade out, 'this' is the frame to fade in
	{
		if (!prevelem) return;
		var hotelKey = prevelem.className.match(/hotel-([^\s]*)/)[1]; // Gets the hotelKey from the classes attached to the element (PHP puts them there in the template)
		var location = this.className.match(/location-([^\s]*)/)[1];
		changeCity(location);
	}
		
	showHotel = function(hotelKey)
	{
		$("#illustrations .slide").css({"opacity" : "1"}).hide();
		$("#illustrations .hotel-" + hotelKey).show();
		var location = $("#illustrations .hotel-" + hotelKey)[0].className.match(/location-([^\s]*)/)[1];
		changeCity(location);
	}
	
	window.onload = function()
	{
		changeCity("barcelona");
	}

	// Functions to communicate with map.swf
	function changeCity(city){
		callToActionscript(city);
	}
	
	function getFlashMovie(movieName) {
  		var isIE = navigator.appName.indexOf("Microsoft") != -1;
  		return (isIE) ? window[movieName] : document[movieName];
	}

	function callToActionscript(city) {
		try {
			getFlashMovie("map").sendToActionscript(city);
		} catch(e){};
	}

