
/**
 * Searcher
 *
 * @category	
 * @package		
 * @version		1.0.1
 * @author		Javier Seixas
 * @copyright	
 * @license		
 */
 
var Navigation = new Class({
	
	getOptions: function() {
		return {
			deleting_controller: '/uploader/index/delete_process/'
		};
	},
	
	initialize: function(currencyId,options) {
		
		this.setOptions(this.getOptions(), options);
		
		if ( $('orden_por') ) {
			$('orden_por').addEvent('change', function () {
				$('sort').submit();
			}.bind(this));
		}
		
		
		$A($$('.historyback')).each(function(el) {
			
			//	### Codi del lightbox
			el.addEvent('click',function() {
				history.back(-1);
				return false;
			});
			
		}, this);
		
		if ( $('search_button') ) {
		
			$('search_button').addEvent('click',function() {
				this.overlay = new Overlay({container: document.body, colour: '#ffffff'});
				this.overlay.show();
				
				if ( $('searching_message') )
					$('searching_message').style.display = '';
					
					

				if (Browser.Engine.name == 'trident') {
					$$("select").each(function(item) {
						item.style.display = 'none';
					});
				}
					
			}.bind(this));
		}
		
		this.setCurrency(currencyId);
		
	},
	
	setCurrency: function(currencyId) {
		
		if ( $('moneda') ) {
			
			var prices = $$('span.hotelPrice');
												   
			this.changePrices(prices);
			
			$('moneda').addEvent('change',function() {
				var id = $('moneda').getSelected().getProperty('value');
												   
				this.changePrices(prices);
				
				this.changeCurrency(id);
				
			}.bind(this));
			
		}
		
	},
	
	changePrices: function(prices) {
				
		var change = $('moneda').getSelected().getProperty('class');
		var currencyCode = $('moneda').getSelected().getProperty('code');
		
		prices.each(function(item) {
			var newPrice = Math.round((item.getProperty('alt') * change)*100)/100;
			newPrice = newPrice.toFixed(2);
			item.innerHTML = newPrice + ' ' + currencyCode;					 
		});
		
	},
	
	changeCurrency: function(currencyId) {
		
		this.request = new Request.HTML($merge({
			'url': '/public/ajax/changeCurrency/'+currencyId,
			'method': 'post'
		}, this.options.ajaxOptions));
		
		
		// esborrable els atributs de send per la versió standard
		this.request.send();
		
	}
	
	
	
		
});


// Without this the object does not execute
Navigation.implement(new Options);
Navigation.implement(new Events);
