
var Rates = {
  items: [],
	
	currencyFormats: $H({
    AUD: 'AU$?',
		USD: 'US$?',
		GBP: '£?',
		EUR: '€?',
		RUB: '? руб',
		CHF: 'CHF ?',
		DKK: 'kr ?',
		NOK: 'kr ?',
		SEK: 'kr ?',
		CAD: 'C$?',
		JPY: '¥?',
		INR: 'Rs. ?',
		CNY: '元?'
	}),

  add: function(name, price)
	{
    this.items.push({
      name: name, 
			price: price
	  });
  },
	
	convertAll: function()
	{
    $('rates-converting').show();
		
		var currencyCode = $F('currency-select');
		
    sendAjaxMessage(
		  'currency',
			'getRate',
			{
        currency_code: currencyCode
      },
			this.getRateCallback.bind(this)
		);
  },
	
	getRateCallback: function(results)
	{
    $('rates-converting').hide();
		if (results.rate_available)
		  this.displayRates(results.currency_code, results.rate);
  },
	
	displayRates: function(currencyCode, rate)
	{
    this.items.each(function(item){
      $('rate-' + item.name).innerHTML = this.formatCurrency(currencyCode, item.price * rate);
    }, this);
  },
	
	formatCurrency: function(currencyCode, amount)
	{
    var format = this.currencyFormats.get(currencyCode);
		return format.replace(/\?/, amount.toFixed(0));  
  }
	
	
	

}
