try{console.log('start')}catch(e){console = {log:function(){}}} var citiesTuples = { curr: 0, forecasts: {}, tuples: [ ['Milano','Londra','New York'], ['Roma','Berlino','Miami'], ['Napoli','Barcellona','Tokyo'], ['Parigi','L\'Avana','Buenos Aires'], ['Ibiza','Sydney','Los Angeles'], ['Amsterdam','Dubai','Honolulu'], ['Mosca','Pechino','Rio De Janeiro'], ['Stoccolma','Madrid','Atene'] ], nextTuple: function(){ if (citiesTuples.curr==citiesTuples.tuples.length-1){ citiesTuples.curr=0; }else{ citiesTuples.curr++; } console.log( '[citiesTuples.nextTuple] tuples: ' + citiesTuples.tuples.length ); console.log( '[citiesTuples.nextTuple] next tuple: ' + citiesTuples.curr ); }, getCurrentTuple: function(){ return citiesTuples.tuples[citiesTuples.curr]; } } function meteoAnimation(){ function change( cityPos, cssPos ){ var tempPre = ''; if (citiesTuples.forecasts.cities[cityPos].tempMax.substr(0,1)!='-') {tempPre='+';} $('div#adv .meteo .citta a:'+cssPos).text( cityPos ); $('div#adv .meteo .citta a:'+cssPos).attr('href', citiesTuples.forecasts.cities[cityPos].link); $('div#adv .meteo .citta .prev img:'+cssPos).attr('src', iconUrl+citiesTuples.forecasts.cities[cityPos].icon); $('div#adv .meteo .citta .prev p:'+cssPos).text(tempPre+citiesTuples.forecasts.cities[cityPos].tempMax+'°'); } var iconUrl = 'http://images.alice.it/meteo2008/icone_alice_client/previsioni/white/'; console.log( '[meteoAnimation] Start' ); var first = citiesTuples.getCurrentTuple()[0]; var second = citiesTuples.getCurrentTuple()[1]; var third = citiesTuples.getCurrentTuple()[2]; console.log( '[meteoAnimation] current tuple: ' + citiesTuples.curr + ' (' + citiesTuples.getCurrentTuple() + ')'); $('div#meteofade').fadeOut( 'slow', function(){ try{ console.log(first); change(first,'first'); } catch(e){console.log('[meteoAnimation] ERRORE ' + first + ' ' + e.description)} try{ console.log(second); change(second,'eq(1)'); } catch(e){console.log('[meteoAnimation] ERRORE ' + second + ' ' + e.description)} try{ console.log(third); change(third,'last'); } catch(e){console.log('[meteoAnimation] ERRORE ' + third + ' ' + e.description)} $('div#meteofade').fadeIn( function(){ citiesTuples.nextTuple(); setTimeout( meteoAnimation, 3000 ); console.log( '[meteoAnimation] End' ); } ); } ); } function setDepartureDateFromHotel(){ var iDate = '' + $('input#form-hotel-date').val(); var oDate = new Date(); var nights = $('select#form-hotel-nights').val(); console.log('[setDepartureDateFromHotel] input#form-hotel-date: '+iDate); oDate.setUTCFullYear(iDate.substring(6,10), parseInt(iDate.substring(3,5))-1, iDate.substring(0,2)); console.log('[setDepartureDateFromHotel]: oDate ' + oDate); oDate.setUTCDate(oDate.getUTCDate()+parseInt(nights)); console.log('[setDepartureDateFromHotel]: nights ' + nights); console.log('[setDepartureDateFromHotel]: oDate ' + oDate + ' ...setting hidden field'); $('input#out-date').attr('value', oDate.getUTCDate() + '/' + (oDate.getUTCMonth()+1) + '/' + oDate.getUTCFullYear()); console.log('[setDepartureDateFromHotel] ...done: ' + $('input#out-date').attr('value')); } function initHP(){ var t = ( new Date() ).getTime(); console.log('[init] Start'); console.log('[init] Getting meteo json...'); $.getJSON("/generated/homepage/meteo.json?"+t, function(response){ citiesTuples.forecasts=response; meteoAnimation(); }); console.log('[document.ready] ...got it!'); console.log('[document.ready] datePicker (calendar) init..'); var d = new Date(); $('input#form-hotel-date').attr('value', d.getUTCDate() + '/' + (d.getUTCMonth()+1) + '/' + d.getUTCFullYear()); $('input#form-vacanze-date1').attr('value', d.getUTCDate() + '/' + (d.getUTCMonth()+1) + '/' + d.getUTCFullYear()); d.setUTCDate( d.getUTCDate()+1 ); $('input#form-vacanze-date2').attr('value', d.getUTCDate() + '/' + (d.getUTCMonth()+1) + '/' + d.getUTCFullYear()); $('input#out-date').attr('value', d.getUTCDate() + '/' + (d.getUTCMonth()+1) + '/' + d.getUTCFullYear()); $('.date-picker').datePicker(); $('input#form-hotel-date').bind('change', setDepartureDateFromHotel ); $('select#form-hotel-nights').bind('change', setDepartureDateFromHotel ); console.log('[document.ready] ...done!'); console.log('[document.ready] adapting lastminute and volilocost boxes...'); try{ var hLastMinute = $('div#offerte .box:first').get(0).offsetHeight - 24; var hVoliLowCost = $('div#offerte .box:last').get(0).offsetHeight - 24; var max; console.log('[document.ready] lastminute-h: ' + hLastMinute + ' - volilocost-h: ' + hVoliLowCost); if (hLastMinute