/*
var _hotelsArray=new Array();var headerSelectHotel="<select id='select_hotels' name='select_hotels' class='maximized' >";var closeSelect="</select>";function hotelDescriptor(city,hdescription,iata)
{var _city;var _hdescription;var _iata;this._city=city;this._hdescription=hdescription;this._iata=iata;}
function fillHotelSelect()
{var _hotelSelect=document.getElementById("select_hotels");var _citySelect=document.getElementById("select_city");var _divSelectHotel=document.getElementById("select_hotels_div");var _hotelCount=0;var _innerHtmlHotels="";_divSelectHotel.innerHTML="";_innerHtmlHotels=headerSelectHotel+optionTag(_hotelsArray[0],false);for(j=0;j<_hotelsArray.length;j++)
{if(_hotelsArray[j]._city==_citySelect.value)
{_hotelCount++;}}
if(_hotelCount!=1)
{_hotelCount=0;}
var _tmpCount=1;for(i=0;i<_hotelsArray.length;i++)
{if(_hotelsArray[i]._city==_citySelect.value)
{if(_tmpCount==_hotelCount&&_hotelCount!=0){_innerHtmlHotels=_innerHtmlHotels+optionTag(_hotelsArray[i],true);}
else
{_innerHtmlHotels=_innerHtmlHotels+optionTag(_hotelsArray[i],false);}
_tmpCount++;}
if(_citySelect.value=="-"&&i!=0)
{_innerHtmlHotels=_innerHtmlHotels+optionTag(_hotelsArray[i],false);}}
_divSelectHotel.innerHTML=_innerHtmlHotels+closeSelect;}
function fillDestinationsSelect()
{}
function optionTag(_itemHotel,_isSelected)
{var _item="";if(_isSelected)
{_item="<option value='"+_itemHotel._iata+"' selected>"+_itemHotel._hdescription+"</option>";}
else
{_item="<option value='"+_itemHotel._iata+"'>"+_itemHotel._hdescription+"</option>";}
return _item;}
*/
$(document).ready(function() {



	//aggiunta dei parametri Width ed Height nel title del tag a (per foto e video)
	//utilizzati da PrettyPhoto
	$('ul.profileMenu a, a.ata_map, a.popup').each(function() {
		var t = $(this);
		var foto = t.hasClass('ata_hotel_foto');
		var video = t.hasClass('ata_hotel_video');
		var map = t.hasClass('ata_map');
		var popup = t.hasClass('popup');
		var href = t.attr('href');
		if (foto || video || map)
		{
			var w = 990;
			var h = (video||map) ? '600' : '520';

			t.attr('rel', 'prettyPhoto');
			href += '?iframe=true&width='+w+'&height='+h;
			t.attr('href', href);
		}
		else if (popup)
		{
			var w = 800;
			var h = 600;

			t.attr('rel', 'prettyPhoto');
			href += '?iframe=true&width='+w+'&height='+h;
			t.attr('href', href);
		}
	});

	$('#map').each(function() {
		var t = $(this);
		var w = 800;
		var h = 564;

		t.attr('rel', 'prettyPhoto');
		var href = t.attr('href');
		href += '?iframe=true&width='+w+'&height='+h;
		t.attr('href', href);
	});

	convertToDivs('table.boxRad');

	$("a[rel^='prettyPhoto']").prettyPhoto();

});


function convertToDivs(selector) {
	$(selector).each(function() {
		var initialClass = $(this).attr('class');
		var initialStyle = $(this).attr('style');
		var list = $("<div class='table "+initialClass+"' style='"+initialStyle+"'></div>");

		$(this).find("tr").each(function() {
			var trClass = $(this).attr('class');
			var p = $(this).children().map(function() {
				var tdClass = $(this).attr('class');
				return "<div class='cell "+tdClass+"'>" + $(this).html() + "</div>";
			});

			list.append("<div class='row "+trClass+"'>" + $.makeArray(p).join("") + "</div>");
		});

		$(this).replaceWith(list);
	});
}

function showWait()
{
	/*$('#dialog-wait').fancy({
		modal: true,
		opacity: 80,
		//overlayClose: true,
		//closeClass: "modalClose",
		onComplete: function() {
			startPuntini();
		},
		onClosed: function() {
			//$('#dialog-wait').hide();
			stopPuntini();
		}
	});*/
	$('#dialog-wait').modal({
		containerCss:{
			height:480,
			padding:0,
			width:725
		},
		opacity: 80,
		//overlayClose: true,
		closeClass: "modalClose",
		onShow: function() {
			startPuntini();
		},
		onClose: function() {
			jQuery.modal.close();   //va chiamata per forza!
			$('#dialog-wait').hide();
			stopPuntini();
		}
	});

}

var WAIT_TIMING = 1000;
var counter = 0;
var activePuntini = false;
function startPuntini()
{
	if (!activePuntini)
	{
		clearPuntini();
		activePuntini = true;
		setTimeout('updatePuntini()', WAIT_TIMING);
	}
}

function stopPuntini()
{
	if (activePuntini)
	{
		activePuntini = false;
		clearPuntini();
	}
}

function updatePuntini() {
	if (activePuntini)
	{
		if (counter >= 10)
		{
			clearPuntini();
		}
		else
		{
			$('#puntini').text($('#puntini').text()+'.');
			counter++;
		}

		setTimeout('updatePuntini()', WAIT_TIMING);
	}
}

function clearPuntini() {
	$('#puntini').empty();
	counter = 0;
}



function toogleBoxHotels(){
	$('#searchBox').fadeToggle('slow');
	$('#toggle_appear').slideToggle('slow');
}

$('a.wait').live('click', function(){
	showWait();
});
