var hotelsListBookingEngine;

var hotelsList = {
	
	_init : function(){
		
		ajaxRequest._executeByUrl(
			"/bean/getViewBeans.action?beans=GeographicResultHotelsViewBean|CurrenciesViewBean|HotelListSearchCriteriaViewBean|OriginViewBean|InterHotelsViewBean",
			"tAjaxError", 
			"hotelsList._success(errors, response)"
		);
	},

	_success : function(errors, json){
			if(errors && errors.length > 0){
				ajaxRequest.showErrors(errors, "tAjaxError");
			}
			else if (json.viewBeans && json.viewBeans.GeographicResultHotelsViewBean && json.viewBeans.CurrenciesViewBean && json.viewBeans.HotelListSearchCriteriaViewBean && json.viewBeans.OriginViewBean){
				json.viewBeans["SearchCriteriaViewBean"] = json.viewBeans.HotelListSearchCriteriaViewBean; 
				if(json.viewBeans.InterHotelsViewBean && json.viewBeans.InterHotelsViewBean != null) Interhotels._init(json.viewBeans.InterHotelsViewBean);
				hotelsListBookingEngine = new BookingEngine("newbookingEngine", "hotelsListBookingEngine", true);
				hotelsListBookingEngine.success(errors, json);
				$myObjects._init();
				hotelsUtils._init(json.viewBeans.GeographicResultHotelsViewBean, json.viewBeans.CurrenciesViewBean, json.viewBeans.SearchCriteriaViewBean, json.viewBeans.OriginViewBean);
				utils.manageCallcenterDatas(json.viewBeans.OriginViewBean.accorhotels);
				
				// Criteo : périmètre accorhotels grand public uniquement + restriction sur certains marchés géré dans le script criteo.js
				if (json.viewBeans.OriginViewBean.accorhotels) {
					var criteoTop3 = new Array();
					var dateIn = null;
					var dateOut = null;
					for(i=0; i<3; i++){
						if(hotelsUtils.mainList[i] && hotelsUtils.mainList[i].datas.tarsCode) criteoTop3.push(hotelsUtils.mainList[i].datas.tarsCode);
					}
					if (json.viewBeans.SearchCriteriaViewBean.period) {
						dateIn = new Date(json.viewBeans.SearchCriteriaViewBean.period.yearIn, json.viewBeans.SearchCriteriaViewBean.period.monthIn-1, json.viewBeans.SearchCriteriaViewBean.period.dayIn);
						dateOut = new Date(json.viewBeans.SearchCriteriaViewBean.period.yearOut, json.viewBeans.SearchCriteriaViewBean.period.monthOut-1, json.viewBeans.SearchCriteriaViewBean.period.dayOut);
					}
					Criteo.triggerProductListHit(criteoTop3, dateIn, dateOut);
				}
				// Fin Criteo
				
				// AdExchange : accorhotels grand public uniquement + restriction sur certains marchés et certaines destinations, géré côté dynamique
				if (json.viewBeans.OriginViewBean.accorhotels && json.viewBeans.GeographicResultHotelsViewBean.adexchangeCampaignId!=null &&json.viewBeans.GeographicResultHotelsViewBean.adexchangeCampaignId!='') {
					AdExchange.triggerProductListHit(json.viewBeans.GeographicResultHotelsViewBean.adexchangeCampaignId);
				}
				// Fin AdExchange
				
			}
			// supprime le loader puis affiche le contenu
			jQuery("#hotelsList .contentContainer").css("background", "none");
			jQuery("#hotelsList .middleContent").css("visibility", "visible");
	}
}

jQuery(document).ready(function(){
	utils.rewriteTitle();
	popins.init();
	utils.tooltips.init();
	$myObjects._init();
	hotelsList._init();
});
