function setRoom(nrooms, label_adults, label_children, label_children_age, label_room){
	var myResults = "";
	myResults = myResults + '<ul>\n';
	for (var i=1; i<=nrooms; i++){
		if ( nrooms > 1){
			myResults = myResults + '	<li class="titleRoom"><strong>'+ label_room +' '+ i +'</strong></li>\n';
		}
		myResults = myResults + '	<li>\n'+
		'		<span class="quarta">\n'+
		'			<label>'+ label_adults +'</label>\n'+
		'			<select name="bform[reqRooms]['+ i +'][adults]">\n'+
		'			'+ createSelect(6, 1, label_adults, "", 2) + 
		'			</select>\n'+
		'		</span>\n'+
		'		<span class="quarta">\n'+
		'			<label>'+ label_children +'</label>\n'+
		'			<select name="bform[reqRooms]['+ i +'][child]" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\');">\n'+
		'			'+ createSelect(4, 0, label_children, "", 0) + 
		'			</select>\n'+
		'		</span>\n'+
		'		<span class="childAge" id="chdAge_'+ i +'"></span>\n'+
		'	</li>\n';
	}
	myResults = myResults + '</ul>\n';
	if (document.getElementById('contOption')){
		document.getElementById('contOption').innerHTML = myResults;
	} else {
		alert("blocco non valido");
	}
}

function setRoomHome(nrooms, label_adults, label_children, label_children_age, label_room) {
	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 +'">'+
										'<label>'+ label_adults +'</label>'+
										'<select name="bform[reqRooms]['+ i +'][adults]">'+
											createSelect(6, 1, label_adults, "", 2)+
										'</select>'+
									'</li>'+
									'<li class="room'+ i +'">'+
										'<label>'+ label_children +'</label>'+
										'<select name="bform[reqRooms]['+ i +'][child]" onchange="setChildAge(this.value,\'chdAge_'+ i +'\', '+ i +',\''+ label_children_age +'\');">'+
											createSelect(4, 0, label_children, "", 0)+
										'</select>'+
									'</li>'+
									'<li class="room'+ i +'" id="chdAge_'+ i +'"></li>';
		}
		
		$('li.room1.roomTitle').remove();				// rimuovo il titolo della camera 1 (per evitare duplicazioni nel caso sia gią presente: vedi istruzione successiva)
		$('li.room1:first').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').nextAll().remove();			// rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1
		$('li.room1:last').after(myResults);			// aggiungo dopo l'ultimo elemento della camera 1, la stringa preparata in precedenza
		$('#booking').animate({height: '275px'});
		$('#boxes').animate({height: '305px'});
		$('#home_wrapper').animate({height: '333px'});
	}
	else			// se viene scelta una sola camera...
	{
		$('li.room1.roomTitle').remove();				// rimuovo il titolo della camera 1
		$('li.room1:last').nextAll().remove();			// rimuovo tutti gli elementi dopo l'ultimo elemento della camera 1
		$('#booking').animate({height: '158px'});
		$('#boxes').animate({height: '188px'});
		$('#home_wrapper').animate({height: '216px'});
	}
}


function setChildAge(nchild, chdid, roomn, label_children_age){
	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 + ']" class="select_small">' +
                '<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(document.getElementById(chdid)){
		document.getElementById(chdid).innerHTML = 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>';
		} else {
			mySel = mySel + "\n" + '<option value="'+ k +'">'+ k + label +'</option>';
		}
	}
	return mySel;
}

function slideShow() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');


	// 3 linee che servono per far comparire le immagini in ordine casuale
	var $sibs  = $active.siblings();
    var rndNum = Math.floor(Math.random() * $sibs.length );
    var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

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

$(document).ready(function(){

	// tooltip per il dettaglio Hotel
	 var hideDelay = 300;
	 var hideTimerHotel = null;
	 var containerHotel = $('<div class="hotel_details"></div>');
	
	 $('body').append(containerHotel);
	
	 $('.hotel_name').live('mouseover', function(){
		 link = $(this).attr('rel');
	
		 if (hideTimerHotel)
			 clearTimeout(hideTimerHotel);
	
		 var pos = $(this).offset();
		 var width = $(this).width();
	
		 containerHotel.css({
			 left: (pos.left + width - 100) + 'px',
			 top: pos.top - 40 +'px',
			 width: 328
		 });
	
		 $.ajax({
			 type: 'GET',
			 url: link,
			 success: function(data){
				 var text = $(data).html();
				 $('.hotel_details').html(text);
				 $('.hotel_details').bgiframe();
			 }
		 });
	
		 containerHotel.fadeIn("slow");;
	 });
	
	 $('.hotel_name').live('mouseout', function(){
		 if (hideTimerHotel)
			 clearTimeout(hideTimerHotel);
			 hideTimerHotel = setTimeout(function(){
			 containerHotel.css('display', 'none');
		 }, hideDelay);
	 });
	
	 $('.hotel_details').mouseover(function(){
		 if (hideTimerHotel)
			 clearTimeout(hideTimerHotel);
	 });
	
	 $('.hotel_details').mouseout(function(){
		 if (hideTimerHotel)
			 clearTimeout(hideTimerHotel);
			 hideTimerHotel = setTimeout(function(){
			 containerHotel.css('display', 'none');
		 }, hideDelay);
	 });
	 
	$('.offer_description').toggle(
		function(){  // funzione per il dettaglio dell'offerta
			var short_description = $(this).parent('.short_description');
			var long_description = $(this).parent().siblings('.long_description'); 	
			short_description.fadeOut();
			long_description.fadeIn('slow');
		},
		function(){  // funzione per il dettaglio dell'offerta
			var short_description = $(this).parent().siblings('.short_description');
			var long_description = $(this).parent('.long_description'); 	
			long_description.fadeOut();
			short_description.fadeIn('slow');
		}
	);

});