var Offres=new Class(
{
	hotel:null,
	etape:1,
	nb_offres_graph:0,
	pos_list_bloc:0,
	offres_hotel:null,
	candena_list:false,
	cible_resav:null,
	choix_chambre:null,
	resav:null,
	
	initialize: function()
	{

	},
	
	start: function(hotel)
	{
		this.hotel=hotel;
		this.charger_data();	
	},
	
	charger_data: function()
	{
		var req = new Request.JSON(
		{
			url: "./index/OFFRES/DATA/offres_"+this.hotel+".json", 
			onComplete: function(obj)
			{
				if(this.hotel=="palm")
					this.offres_hotel=obj.palm;
				else
					this.offres_hotel=obj.iloha;
				this.charger_support();
			}.bind(this)
		}).send();			
	},
	
	charger_support: function()
	{
		var req=new Request.HTML(
		{	
			url:'./index/OFFRES/offres.html',
			method:'post',
			onComplete: function(node)
			{
				$('cadre').adopt(node);
				$('offres').fade('hide');
				this.insertion_data();	
			}.bind(this),
			
			onRequest: function()
			{
				//var image=new Element('img',{'id':'img_load','src':'./index/Logo-Palm.png','style':'position:absolute;margin-left:438px;margin-top:365px;'});
				var fond=new Element('div',{'id':'fond_load','style':'position:absolute; width: 1024px; height:768px;background-color:black;opacity:0.5;filter : alpha(opacity=30);'});
				var text=new Element('p',{'id':'text_load','style':'position:absolute;margin-left:460px;margin-top:280px;color:#ffffff;font-family:baskerville,"times New Roman",Georgia,serif;','text':'Chargement en cours...'});
				var load=new Element('div',{'id':'load'});
				load.adopt(fond,text);
				$('cadre').adopt(load);
			},
			
			onFailure: function() 
			{
				alert('Probl\xe8me de connexion.');
			}
		});
		req.send("hotel="+this.hotel);
	},
	
	insertion_data: function()
	{
		new Asset.images(
			[this.offres_hotel.images[0].src,this.offres_hotel.images[1].src,this.offres_hotel.images[2].src,"./index/OFFRES/header/logo-Iloha.png","./index/OFFRES/offres_fond.png","./index/OFFRES/header/bouton_reserver.png",this.offres_hotel.grand_logo,this.offres_hotel.petit_logo,"./index/OFFRES/middle/offres_du_moment/filet_marron.png"],
			{
				onComplete: function()
				{
					this.insertion_images();
					this.insertion_logos_hotel();
					this.insertion_lien_site();
					this.insertion_liste_offres();
					this.insertion_conditions();
					this.mae_en_savoir_plus();
					this.devoiler_offres();
					this.maj_parametres();
					this.maj_etapes_graph();
					this.mae_boutons_nav();
				}.bind(this)
			});
	},
	
	insertion_images: function()
	{
		var img1=new Element('img',{'src':this.offres_hotel.images[0].src,'alt':this.offres_hotel.images[0].alt,'title':this.offres_hotel.images[0].title});
		var img2=new Element('img',{'src':this.offres_hotel.images[1].src,'alt':this.offres_hotel.images[1].alt,'title':this.offres_hotel.images[1].title});
		var img3=new Element('img',{'src':this.offres_hotel.images[2].src,'alt':this.offres_hotel.images[2].alt,'title':this.offres_hotel.images[2].title});
		$('offres_3_photos').adopt(img1,img2,img3);
	},
	
	insertion_logos_hotel:function()
	{
		$('offres_logo').setStyle('background-image','url('+this.offres_hotel.grand_logo+')');
		$('offres_post_it_logo').setStyle('background-image','url('+this.offres_hotel.petit_logo+')');
		$('offres_post_it_text').setStyle('background-image','url(./index/OFFRES/header/post-it/'+home.langue+'/'+this.offres_hotel.post_it_text+')');
		
	},
	
	insertion_lien_site: function()
	{
		$('offres_visite').setProperties({'href':this.offres_hotel.site,'target':'_blank'});
		$('reserver').setProperties({'href':'http://hotel.reservit.com/reservit/reserhotel.php?lang='+home.langue+'&hotelid='+this.offres_hotel.id_hotel.toInt(8)});
	},
	
	insertion_liste_offres: function()
	{
		this.offres_hotel.offres.each(function(obj,i)
		{
			var li=new Element('li',{'id':obj.nom});
			var img=new Element('img',{'src':'./index/OFFRES/middle/offres_du_moment/fr/'+obj.nom+'.png'});
			var p=new Element('p',{'html':obj.description});
			var div1=new Element('div',{'class':'a_partir','html':'A partir de '+obj.condition});
			var div2=new Element('div',{'class':'prix','html':obj.prix+' &euro;'});
			if (obj.illustration!="")
			{
				var img2=new Element('img',{'class':'illustration','src':'./index/OFFRES/middle/offres_du_moment/illustration/'+obj.illustration+'.png'});
				li.adopt(img,p,div1,div2,img2);
			}
			else
			{
				li.adopt(img,p,div1,div2);
			}
			$('liste_offres').adopt(li);
		}.bind(this));
	},
	
	insertion_conditions: function()
	{
		$('offres_remarque').set('html',this.offres_hotel.offres_remarque);
	},
	
	mae_en_savoir_plus: function()
	{
		$$('a.bouton_en_savoir_plus').each(
			function(elt)
			{
				elt.addEvent('click',function(e)
				{
					this.cible_resav=e.target.parentNode.id;
					this.resav=new Resav('en_savoir_plus');
				}.bind(this));
			})
	},
	
	devoiler_offres: function()
	{
		$('load').destroy();
		if(Browser.Engine.trident)
			$('offres').fade('show');
		else
			$('offres').fade('in');
	},
	
	maj_parametres: function()
	{
		this.nb_offres_graph=$('liste_offres').getElements('li').length;
	},
	
	maj_etapes_graph: function()
	{
		for(i=1;i<=this.etape;i++)
		{
			$('navigation_'+i).setStyles({'background-color':'#4d2714','color':'#ffffff'});
		}
		$('navigation_'+this.etape).setStyles({'background-color':'#4d2714','color':'red'});
	},
	
	mae_boutons_nav: function()
	{
		$('offres_b_up').addEvents({'click':function(e){e.stop();this.deplacer_liste('haut');}.bind(this)});
		$('offres_b_down').addEvents({'click':function(e){e.stop();this.deplacer_liste('bas');}.bind(this)});	
		$('offres_du_moment').addEvent('mousewheel',function(e){this.wheel(e);}.bind(this));
		
		$('offres_visite').addEvents(
		{
			'click':function()
			{
			},
			
			'mouseover':function()
			{
				this.tween('color','#613C2C');
			},
			
			'mouseout':function()
			{
				this.tween('color','#CBBC80');
			}
		});
		$('offres_fermer').addEvent('click',function(){this.fermer_offres()}.bind(this));
		$('reserver').addEvents(
		{	
			'click':function()
			{
				this.setStyle('color','#613C2C');
			},
			'mouseover':function()
			{
				this.tween('color','#72EF4A');
			},			
			'mouseout':function()
			{
				this.tween('color','#ffffff');
			}
		});
	},
	
	wheel: function(event)
	{
        if (event.wheel < 0)
			this.deplacer_liste('bas');
        else
			this.deplacer_liste('haut');
        if (event.preventDefault)
            event.preventDefault();
		event.returnValue = false;
	},
	
	deplacer_liste: function(vers)
	{	
			if(!this.candena_list)
			{
				var reste_bas=(this.nb_offres_graph-4)-this.pos_list_bloc;
				if(vers=="haut")
				{
					if(this.pos_list_bloc>0)
					{
						var pos=$('liste_offres').getStyle('margin-top').toInt();
						$('liste_offres').set('tween',{link:'cancel',onStart: function(){this.candena_list=true}.bind(this),onComplete: function(){this.candena_list=false;this.pos_list_bloc=this.pos_list_bloc-1;}.bind(this)});
						$('liste_offres').tween('margin-top',pos+100);
					}		
				}
					
				if(vers=="bas")
				{
					if(reste_bas>0)
					{
						var pos=$('liste_offres').getStyle('margin-top').toInt();
						$('liste_offres').set('tween',{link:'cancel',onStart: function(){this.candena_list=true}.bind(this),onComplete: function(){this.candena_list=false;this.pos_list_bloc=this.pos_list_bloc+1;}.bind(this)});
						$('liste_offres').tween('margin-top',pos-100);
					}
				}
			}

	},
	
	fermer_offres: function()
	{
		$('offres').destroy();
		this.initialisation();
	},
	
	initialisation: function()
	{
		this.hotel=null;
		this.etape=1;
		this.nb_offres_graph=0;
		this.pos_list_bloc=0;
		this.offres_hotel=null;
		this.candena_list=false;
		this.cible_resav=null;
		this.choix_chambre=null;
		this.resav=null;
	}
});
