

var PriceCalculator = new Class({
	

	initialize: function() {
		
		this.actualchange = "CHF";
		this.changes = $ES('.change');
		this.switchers = $ES('.switcher');
		this.calculates = $ES('.calculate');
		
		
		this.confavecrepas = $('confavecrepas');  //170 Frs (110€)	
		this.confsansrepas = $('confsansrepas');  //140 Frs (90€)
		this.prixsoiree = $('prixsoiree');  
		this.prixsoiree2 = $('prixsoiree2');      //180 Frs (115€)
		this.nperssoiree = $('nperssoiree');      
		this.total = $('total');
		this.totalsent = $('totalsent');
		this.devise = $('devise');
		
		this.switchers.each(function(sw){
			
			sw.addEvent('click', function() {
							this._switchPrice();
							this._switchChange();
						}.bind(this));

		}.bind(this));
		
		
		
		this.soiree = $('soiree'); 
		
		
		
		this.nperssoiree.addEvent('change', function() {
				//console.log("this.nperssoiree: +"+this.nperssoiree.value)
				if(this.nperssoiree.value!= "") this.soiree.setProperty('checked', 'true');
;				
		}.bind(this));
		
		// RULES -------------------------------------------------
		
		this.conference = $('conference'); 
		
		
		
		$('conferenceavecrepas').addEvent('click', function(e) {
				this.conference.setProperty('checked', 'true');
				this._calculatePrice();
		}.bind(this));
		
		$('conferencesansrepas').addEvent('click', function(e) {
				this.conference.setProperty('checked', 'true');
				this._calculatePrice();
		}.bind(this));

		this.conference.addEvent('click', function() {
			//console.log("click: "+this.conference.getProperty('checked'));
			if (this.conference.getProperty('checked') != true){
				$('conferenceavecrepas').setProperty('disabled', true);
				$('conferencesansrepas').setProperty('disabled', true);
				$('conferenceavecrepas').setProperty('checked', false);
				$('conferencesansrepas').setProperty('checked', false);
			}else{
				$('conferenceavecrepas').setProperty('disabled', false);
				$('conferencesansrepas').setProperty('disabled', false);
			}
			this._calculatePrice();
		}.bind(this));
		
		
		this.gouter = $('gouter');
		
		$('nadultegouter').addEvent('click', function(e) {
				this.gouter.setProperty('checked', 'true');
				this._calculatePrice();
		}.bind(this));
		
		
		//this.nperssoiree.addEvent('change', 	function(e) {this._calculatePrice();}.bind(this));
		this.nperssoiree.addEvent('blur', 	function(e) {this._calculatePrice();}.bind(this));
		this.soiree.addEvent('click', 		function(e) {
				if (this.nperssoiree.value == "") this.nperssoiree.value = 1;
				this._calculatePrice();
		}.bind(this));
		this.conference.addEvent('click',	function(e) {
				$('conferencesansrepas').setProperty('checked', true);	
				this._calculatePrice();		
		}.bind(this));
		
		// ____________
		
		/*this.calculates.each(function(c){
			
			c.addEvent('change', function() {
							this._calculatePrice();
						}.bind(this));

		}.bind(this));
		*/
		
	},
	
	_calculatePrice: function() {
			
			var prepas, psoiree, npers;
			
			if ($('conferenceavecrepas').getProperty('disabled') == false){
				if ($('conferenceavecrepas').getProperty('checked') == true){
					prepas  = this.confavecrepas.getText().toInt();
				}
				if ($('conferencesansrepas').getProperty('checked') == true){
				 	prepas  = this.confsansrepas.getText().toInt();
				}
				
				if (($('conferencesansrepas').getProperty('checked') == false) && ($('conferenceavecrepas').getProperty('checked') == false)){
				prepas = 0;	
			}
			}else{
				prepas = 0;	
			}
			
			if (this.soiree.getProperty('checked') == true){
				psoiree = this.prixsoiree.getText().toInt();
				npers   = this.nperssoiree.value;
				if (npers =="") npers = 0;
			}else{
				psoiree= 0;	
				npers= 0;	
			}
			
			var t = prepas.toInt()+psoiree.toInt()*npers.toInt(); 
			this.total.setText(t);
			this.totalsent.value = t;
	},
	
	
	
	_switchPrice: function() {
			
		if (this.actualchange == "CHF"){
			
			this.confavecrepas.setText('110');
			this.confsansrepas.setText('90');
			this.prixsoiree.setText('115');
			this.prixsoiree2.setText('115');
						
		}else{
			this.confavecrepas.setText('170');
			this.confsansrepas.setText('140');
			this.prixsoiree.setText('180');
			this.prixsoiree2.setText('180');
		}	
		
		this._calculatePrice();
			
	},
	
	
	_switchChange: function() {
			
		if (this.actualchange == "CHF"){
			this.changes.each(function(ch){
				ch.setText("EUR");
			});
			this.switchers.each(function(ch){
				ch.setText("je désire payer en Francs suisses");
			});
			this.actualchange = "EUR";
			this.devise.value = "EUR";
		}else{
			this.changes.each(function(ch){
				ch.setText("CHF");
			});
			this.switchers.each(function(ch){
				ch.setText("je désire payer en Euros");
			});

			this.actualchange = "CHF";
			this.devise.value = "CHF";
		}	
		
		
	}
	
	
});



//////////////////////////////////////////////////////////////////////////////////////////////////




var RemoveEmptyTitles = new Class({
	

	initialize: function(tags) {
		
		tags.each(function(tag){
			
			if (tag.getText() == "Sans titre") tag.remove();
			
		});
	}
});



//////////////////////////////////////////////////////////////////////////////////////////////////


var RemoveDoubledBox = new Class({
	

	initialize: function(boxes) {
		
		var i = 0;
		
		boxes.each(function(box){
			
			if (i != 0) box.remove();
			i++;
		});
	}
});


//////////////////////////////////////////////////////////////////////////////////////////////////




var AlignImages = new Class({
	

	initialize: function(containers) {
		
		//console.log('start align: '+containers);
		
		containers.each(function(cont){
			
			var table = new Element('table').addClass('triptik').injectInside(cont);
			var tbody = new Element('tbody').injectInside(table);
			var row = new Element('tr').injectInside(tbody);
					
			imgs = $ES('img', cont);
			imgs.each(function(img){
				var col = new Element('td').injectInside(row);
				img.injectInside(col);
			});
			
			$E('p', cont).remove();
		});
	}
});
//////////////////////////////////////////////////////////////////////////////////////////////////




var AjaxForm = new Class({
	

	initialize: function(formid, responsebox) {
		
		$(formid).addEvent('submit', function(e) {			new Event(e).stop();			var log = $(responsebox).empty().addClass('ajax-loading');		 			log.setStyle('left',window.getWidth()/2-150);
			
						this.send({				update: log,				onComplete: function() {
					log.setStyle('display','');					log.removeClass('ajax-loading');
					
					log.fx = log.effect('top', {duration: 1200, transition: Fx.Transitions.quadInOut});
					log.closebtn = new Element('a').setProperty('href','javascript:void(0)').setHTML('fermer').addClass('btn close');
					if (log.closebtn){
						log.closebtn.addEvent('click', function(e) {
							log.fx.start(-1000);
						});
					}
					
					var closebox = $('closebox').empty();
					log.closebtn.injectInside(closebox);
					
					//console.log("closebtn: "+log.closebtn.getParent().getProperty('id'));
					
					var ypos =  window.getScrollTop() + window.getHeight()/2 -150;
					//console.log("ypos: "+ypos);
					log.fx.start(ypos);				}			});		});
	}
});
//////////////////////////////////////////////////////////////////////////////////////////////////





var Menu = new Class({
	
	openmarginright : 6,
	initialize: function(handle) {
		this.mainmenus = $ES('.mainmenu', $('mainmenus'));
		
		this.mainmenus.each(function(mainmenu){
					var menu = $E('.menu', mainmenu);
					if (menu!=null){
						mainmenu.toggler = $E('a', mainmenu);
						mainmenu.toggler.setProperty('href', 'javascript:void(0)');
						mainmenu.menu = menu;
						
						mainmenu.menu.setStyle('overflow', 'hidden');
						mainmenu.menu.fx = mainmenu.menu.effect('height', {duration: 400, transition: Fx.Transitions.quadInOut});
						mainmenu.menu.height0 = mainmenu.menu.getStyle('height');
						
						if (!$E('.on', mainmenu.menu)){
							mainmenu.menu.fx.set(0);
							mainmenu.menu.isopen = false;
						}else{
							mainmenu.menu.isopen = true;
							this.actualmenu = mainmenu.menu;
							if (window.ie6) this.actualmenu.setStyle('border-bottom', '1px solid #cee9e9');
						}
						mainmenu.toggler.addEvent('click', function() {
							//if (menu.isopen != false){ this._close(mainmenu.menu);}
							//else{this._open(mainmenu.menu)}
							this._open(mainmenu.menu);
						}.bind(this));
					};		  
					
		}.bind(this));
		
	
	},
		
	//methods:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

	
	
	
	
	
	_close: function(menu) {
			
		menu.fx.start(0);
			
		menu.isopen = false;	
	},
	



	_open: function(menu) {
			
		menu.fx.start(menu.height0);
		
		if (!this.actualmenu){
			this.actualmenu = menu;
			 return;
		}
		this.actualmenu.fx.start(0);
		this.actualmenu = menu;
		
		menu.isopen = true;
			
	}  //end methods
	
	
	
	
	
}); // end class Menu




//////////////////////////////////////////////////////////////////////////////////////////

