function setRoomHome(nrooms, label_adults, label_children, label_children_age, label_room, element) {
	var form = element.parents('form');
	var myResults = '';
	
	if (nrooms > 1)	// se viene scelta più di una camera...
	{
		for (var i=2; i<=nrooms; i++)	// preparo la stringa da accodare alla prima camera, contenente i campi necessari
		{
			myResults = myResults + '<li class="room'+ i +' roomTitle">'+ label_room +' '+ i +'</li>';
			
			myResults = myResults +	'<li class="room'+ i +' adults">'+
										'<label>'+ label_adults +'</label>'+
										'<select name="bform[reqRooms]['+ i +'][adults]">'+
											createSelect(6, 1, label_adults, "", 2)+
										'</select>'+
									'</li>'+
									'<li class="room'+ i +' children">'+
										'<label>'+ label_children +'</label>'+
										'<select name="bform[reqRooms]['+ i +'][child]" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\', $(this));">'+
											createSelect(4, 0, label_children, "", 0)+
										'</select>'+
									'</li>'+
									'<li class="room'+ i +' childAge chdAge_'+ i +'"></li>';
		}
		
		$('li.room1.roomTitle', form).remove();				// rimuovo il titolo della camera 1 (per evitare duplicazioni nel caso sia già presente: vedi istruzione successiva)
		$('li.room1:first', form).before('<li class="room1 roomTitle">'+ label_room +' 1</li>');		// aggiungo il titolo della camera 1, prima del primo campo della camera 1
		$('li.room1:last', form).nextAll().remove();		// rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1
		$('li.room1:last', form).after(myResults);			// aggiungo dopo l'ultimo elemento della camera 1, la stringa preparata in precedenza
	}
	else			// se viene scelta una sola camera...
	{
		$('li.room1.roomTitle', form).remove();				// rimuovo il titolo della camera 1
		$('li.room1:last', form).nextAll().remove();		// rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1
	}
}


function setChildAge(nchild, chdid, roomn, label_children_age, element){
	var form = element.parents('form');
	var selectHtml = "";
	
	if(nchild > 0){
		selectHtml = '<label>'+ label_children_age +'</label>';
		for (var cc=1; cc<=nchild; cc++) {
			selectHtml =  selectHtml + '<select name="bform[reqRooms]['+roomn+'][childAge][' + cc + ']">' +
                '<option value="0">&lsaquo;1</option>';
				for(var k=1; k<=18; k++){
					k_opt = k<10 ? "&nbsp;"+ k : k;
					selectHtml =  selectHtml + "\n" + '<option value="'+ k +'">'+ k_opt +'</option>';
				}
				selectHtml =  selectHtml + '</select>';
		}
	}

	if($('.'+chdid, form)){
		$('.'+chdid, form).html(selectHtml);
	}
}


function createSelect(num, init, label, labels, selected){
	if(label != ""){
		label = " "+ label;
	}
	if(labels != ""){
		labels = " "+ labels;
	} else {
		labels = label;
	}
	var mySel = "";
	for(var k=init; k<=num; k++){
		if(k!=init) label = labels;
		if (selected != 0 && selected == k){
			//mySel = mySel + "\n" + '<option value="'+ k +'" selected="selected">'+ k + label +'</option>';	// numero + nome
			mySel = mySel + "\n" + '<option value="'+ k +'" selected="selected">'+ k + '</option>';				// solo numero
		} else {
			//mySel = mySel + "\n" + '<option value="'+ k +'">'+ k + label +'</option>';	// numero + nome
			mySel = mySel + "\n" + '<option value="'+ k +'">'+ k + '</option>';				// solo numero
		}
	}
	return mySel;
}

function goToUrl(url) {
	location.href='http://www.rivellashotels.com'+url;
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function addslashes (str) {
    // http://kevin.vanzonneveld.net
    return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

//======================================	FUNZIONI PER LA MAPPA V3
var jbase64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(input){var output="";var chr1,chr2,chr3,enc1,enc2,enc3,enc4;var i=0;input=jbase64._utf8_encode(input);while(i<input.length){chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}output=output+this._keyStr.charAt(enc1)+this._keyStr.charAt(enc2)+this._keyStr.charAt(enc3)+this._keyStr.charAt(enc4);}return output;},decode:function(input){var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(i<input.length){enc1=this._keyStr.indexOf(input.charAt(i++));enc2=this._keyStr.indexOf(input.charAt(i++));enc3=this._keyStr.indexOf(input.charAt(i++));enc4=this._keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}if(enc4!=64){output=output+String.fromCharCode(chr3);}}output=jbase64._utf8_decode(output);return output;},_utf8_encode:function(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128)utftext+=String.fromCharCode(c);else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}return utftext;},_utf8_decode:function(utftext){var string="";var i=0;var c=c1=c2=0;while(i<utftext.length){c=utftext.charCodeAt(i);if(c<128){string+=String.fromCharCode(c);i++;}else if((c>191)&&(c<224)){c2=utftext.charCodeAt(i+1);string+=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2;}else{c2=utftext.charCodeAt(i+1);c3=utftext.charCodeAt(i+2);string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3;}}return string;}};


var maps;var infowindow = new Array();var marker = new Array();var setDirectionMultiple = {options: {dirContainer: document.getElementById('dirContainer'),dirService: "",dirRenderer: "",myMarker: "",mapId: "",zoom: "",mapType: "",mapLat: "",mapLon: "",showCursor: "",point: new Array()},set: function (mapId, optiones, zoom, mapType, showCursor) {setDirectionMultiple.options.mapId = mapId;setDirectionMultiple.options.zoom = zoom;setDirectionMultiple.options.mapType = mapType;setDirectionMultiple.options.showCursor = showCursor;setDirectionMultiple.options.myMarker = new Array();var aryLat = new Array();var aryLon = new Array();for (names in optiones) {if (names == 'point') {for (name in optiones[names]) {setDirectionMultiple.options.point[name] = optiones[names][name];for (nameee in optiones[names][name]) {if (nameee == 'lat') aryLat[name] = optiones[names][name][nameee];if (nameee == 'lon') aryLon[name] = optiones[names][name][nameee];if (nameee == 'icon') {if (optiones[names][name]['iconAnchor'] != undefined && optiones[names][name]['iconSize'] != undefined) {var myPoint = optiones[names][name]['iconAnchor'].split(',');var mySize = optiones[names][name]['iconSize'].split(',');setDirectionMultiple.options.point[name]['icon'] = new google.maps.MarkerImage(optiones[names][name][nameee], new google.maps.Size(mySize[0] * 1, mySize[1] * 1), new google.maps.Point(0, 0), new google.maps.Point(myPoint[0] * 1, myPoint[1] * 1));}}}setDirectionMultiple.options.point[name]['infowindow'] = '<div class="balloon" id="balloon_' + name + '"><h5>' + setDirectionMultiple.addslashes(setDirectionMultiple.options.point[name]['labelTitle']) + '</h5>' + setDirectionMultiple.options.point[name]['infowindow'] + '<br /><br />' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelCalculate']) + '<br /><a href="javascript:;" onclick="setDirectionMultiple.init(\'<h5>' + setDirectionMultiple.options.point[name]['labelTitle'] + '</h5><br />' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelCalculate']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelFrom']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelTo']) + '\', \'FROM\', \'' + setDirectionMultiple.options.point[name]['lat'] + ', ' + setDirectionMultiple.options.point[name]['lon'] + '\',' + name + ');" title="' + setDirectionMultiple.options.myMarker['labelCalculate'] + '"><strong>' + setDirectionMultiple.options.myMarker['labelFrom'] + '</strong></a> - <a href="javascript:;" onclick="setDirectionMultiple.init(\'<h5>' + setDirectionMultiple.options.point[name]['labelTitle'] + '</h5><br />' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelCalculate']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelFrom']) + '\', \'' + setDirectionMultiple.addslashes(setDirectionMultiple.options.myMarker['labelTo']) + '\', \'TO\', \'' + setDirectionMultiple.options.point[name]['lat'] + ', ' + setDirectionMultiple.options.point[name]['lon'] + '\',' + name + ');" title="' + setDirectionMultiple.options.myMarker['labelCalculate'] + '"><strong>' + setDirectionMultiple.options.myMarker['labelTo'] + '</strong></a></div>';}} else {setDirectionMultiple.options.myMarker[names] = optiones[names];}}setDirectionMultiple.options.mapLon = setDirectionMultiple.setMiddlePoint(aryLon);setDirectionMultiple.options.mapLat = setDirectionMultiple.setMiddlePoint(aryLat);setDirectionMultiple.openMap();},setMiddlePoint: function (myAry) {var myMin, myMax;for (a in myAry) {if (myMin == undefined) {myMin = myAry[a];} else if (myAry[a] < myMin) {myMin = myAry[a];}if (myMax == undefined) {myMax = myAry[a];} else if (myAry[a] > myMax) {myMax = myAry[a];}}return myMin + ((myMax - myMin) / 2);},openMap: function () {var latlng = new google.maps.LatLng(setDirectionMultiple.options.mapLat, setDirectionMultiple.options.mapLon);if (setDirectionMultiple.options.mapType == undefined) setDirectionMultiple.options.mapType = "ROADMAP";if (setDirectionMultiple.options.showCursor == undefined) setDirectionMultiple.options.showCursor = false;var myOptions = {disableDefaultUI: setDirectionMultiple.options.showCursor,mapTypeControl: true,mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},zoom: setDirectionMultiple.options.zoom,center: latlng,mapTypeId: google.maps.MapTypeId[setDirectionMultiple.options.mapType]};maps = new google.maps.Map(document.getElementById(setDirectionMultiple.options.mapId), myOptions);for (punto in setDirectionMultiple.options.point) {var myLatLng = new google.maps.LatLng(setDirectionMultiple.options.point[punto]['lat'], setDirectionMultiple.options.point[punto]['lon']);marker[punto] = new google.maps.Marker({position: myLatLng,map: maps,title: setDirectionMultiple.options.point[punto]['labelTitle'],icon: setDirectionMultiple.options.point[punto]['icon'],zIndex: 10000});if (setDirectionMultiple.options.point[punto]['infowindow'] != "") {infowindow[punto] = new google.maps.InfoWindow({content: setDirectionMultiple.options.point[punto]['infowindow'],maxWidth: 350,position: myLatLng,zIndex: 100});attachInfoBox(marker[punto], maps, punto);}}},init: function (myText, from, to, direction, latLan, id) {fromS = setDirectionMultiple.addslashes(from);toS = setDirectionMultiple.addslashes(to);for (punto in setDirectionMultiple.options.point) {if (punto == id && document.getElementById('balloon_' + id)) {setDirectionMultiple.options.dirService = new google.maps.DirectionsService();setDirectionMultiple.options.dirRenderer = new google.maps.DirectionsRenderer();var myFormDirection, textDirection;if (direction == "FROM") {myFormDirection = '<form name="direction" action="javascript:;" method="get"><input id="from-input" type="hidden" value="' + latLan + '" />';myFormDirection += '<input id="to-input" type="text" value="" class="inputE" />';myFormDirection += '<input class="inputB" onclick="setDirectionMultiple.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value, ' + id + ');" type="button" value=">" /></form>';textDirection = myText + '<br /><strong>' + from + '</strong> - <a href="javascript:;" onclick="setDirectionMultiple.init(\'' + myText + '\', \'' + fromS + '\', \'' + toS + '\', \'TO\', \'' + latLan + '\', ' + id + ');"><strong>' + to + '</strong></a>' + myFormDirection;} else {myFormDirection = '<form name="direction" action="javascript:;" method="get"><input id="from-input" type="text" value="" class="inputE" />';myFormDirection += '<input id="to-input" type="hidden" value="' + latLan + '" />';myFormDirection += '<input class="inputB" onclick="setDirectionMultiple.getDirections(document.getElementById(\'from-input\').value, document.getElementById(\'to-input\').value, ' + id + ');" type="button" value=">" /></form>';textDirection = myText + '<br /><a href="javascript:;" onclick="setDirectionMultiple.init(\'' + myText + '\', \'' + fromS + '\', \'' + toS + '\', \'FROM\', \'' + latLan + '\', ' + id + ');"><strong>' + from + '</strong></a> - <strong>' + to + '</strong>' + myFormDirection;}document.getElementById('balloon_' + id).innerHTML = textDirection;}}},getDirections: function (fromStr, toStr, id) {var dirRequest = {origin: fromStr,destination: toStr,travelMode: google.maps.DirectionsTravelMode.DRIVING,unitSystem: google.maps.DirectionsUnitSystem.METRIC,provideRouteAlternatives: true};setDirectionMultiple.options.dirService.route(dirRequest, setDirectionMultiple.showDirections);},showDirections: function (dirResult, dirStatus) {if (dirStatus != google.maps.DirectionsStatus.OK) {if (typeof (dirStatusError) != undefined) {alert(dirStatusError + "\n(Google reports: " + dirStatus + ")");} else {alert("The address entered was not found\n(Google reports: " + dirStatus + ")");}return;}setDirectionMultiple.openMap();if (typeof jq == 'function') {jq('html,body').animate({scrollTop: jq('#' + setDirectionMultiple.options.mapId).offset().top - 20}, 1000);} else if (typeof jQuery == 'function') {$('html,body').animate({scrollTop: $('#' + setDirectionMultiple.options.mapId).offset().top - 20}, 1000);}setDirectionMultiple.options.dirRenderer.setMap(null);setDirectionMultiple.options.dirRenderer.setMap(maps);document.getElementById('dirContainer').innerHTML = '';setDirectionMultiple.options.dirRenderer.setPanel(document.getElementById('dirContainer'));setDirectionMultiple.options.dirRenderer.setDirections(dirResult);},addslashes: function (str){return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');}};function attachInfoBox(marker, myMap, id) {google.maps.event.addListener(marker, "click", function () {for (infoBox in infowindow) {infowindow[infoBox].close();}infowindow[id].open(myMap, marker);});};
//======================================	FINE MAPPA

function openModal(url) {
	url = decodeURIComponent((jbase64.decode(url) + '').replace(/\+/g, '%20'));
	if (window.showModalDialog) {
		window.showModalDialog(url, "socials", "dialogHeight:450px;dialogWidth:880px");
	} else {
		window.open(url, 'socials', 'height=450,width=880,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
	}
}

function scrollOffers() {
	if ($('#offers li').length > 1) {
		$('#offers li:first').animate(
			{opacity:0,
			marginTop: $('#offers li:first').outerHeight(true)*-1
			},
			500,
			'',
			function(){
				$(this).remove().insertAfter('#offers li:last');
				$('#offers li').removeAttr('style');
			}
		);
	}
}

function scrollGuestReviews() {
	if ($('#last_review p').length > 1) {
		$('#last_review p:first').animate(
			{opacity:0,
			marginTop: $('#last_review p:first').outerHeight(true)*-1
			},
			500,
			'',
			function(){
				$(this).remove().insertAfter('#last_review p:last');
				$('#last_review p').removeAttr('style');
			}
		);
	}
}

function slideShow() {

    active = $('#slideshow').children(':first');
	
	active
		.remove()
		.insertAfter($('#slideshow').children(':last'))
		.animate({opacity: 1.0}, 1000, function() {
			$(this).siblings().css('opacity', 0);
		});
}

$(document).ready(function(){

	if ($('.home').length == 1)
	{
		resizeDimensions = "135x78c50";
		wordsLimit = "20";
	}
	else
	{
		resizeDimensions = "90x52c50";
		wordsLimit = "8";
	}
	
	$.get('/assets/include_offers.php', { 'resizeDimensions': resizeDimensions, 'wordsLimit': wordsLimit }, function(data) {
		$('#offers').append(data);
		//=============================== SCROLL OFFERTE
		setInterval( 'scrollOffers()', 6000 );
	});
						   
	if ($('#slideshow img').length > 1)
	{
		$('#slideshow div').css('opacity', 0);
		
		// aggiungo uno span per simulare la text-shadow solo in IE
		if(!jQuery.support.opacity) {
			txt = $('#slideshow div p a:first').text();
			$('#slideshow p').append('<strong>'+txt+'</strong>');
		}
		
		slideShow();
		setInterval( "slideShow()", 5000 );
	}
	
	//=============================== SHADOWBOX
	
	$('.shadowbox').each(function(){
		params = $(this).attr('class').split('_');

		gallery	= (typeof(params[1]) !== 'undefined' && params[1] != '')? '['+params[1]+'];' : ';';
		width	= (typeof(params[2]) !== 'undefined')? 'width='+params[2]+';' : '';
		height	= (typeof(params[3]) !== 'undefined')? 'height='+params[3]+';' : '';
		
		
		$(this).attr('rel', 'shadowbox'+gallery+width+height);
	});
	
	//=============================== GALLERYONE
	var gallery = $('#mask>div');
	var gallery_length = $('#galleryone img').length-2;
	var offset = 0;
	//var offset_width = $('#galleryone img').outerWidth(true);	//commentata a causa di un bug di jquery o chrome relativo a outerWidth che su chrome non rileva la larghezza totale ma solo la larghezza di margin, padding e border
	var offset_width = 190;
	
	$('#next').click(function(){
		if ((offset < gallery_length) && (!gallery.is(':animated'))) {
			gallery.stop(true).animate({left:'+=-'+offset_width},'normal');
			offset++;
		}
	});
	
	$('#prev').click(function(){
		if ((offset > 0) && (!gallery.is(':animated'))) {
			gallery.stop(true).animate({left:'+='+offset_width},'normal');
			offset--;
		}
		
	});
	
	//=============================== SCROLL GUEST REVIEWS
	setInterval( 'scrollGuestReviews()', 4000 );
	
	$('#page_utilities ul').mouseleave(function(){
		$(this).slideUp();
	}).hide();
	$('#page_utilities > li').mouseenter(function(){
		$('ul', $(this)).slideDown();
	});


});
