$(function() {
  $.ajaxSetup({
    cache: true
  });
  var selected_cats = [];
  $('#selected_categories a').each(function() {
    selected_cats.push($(this).text());
  });
  $('#categories li a').each(function() {
    var slug = $(this).attr('href').match(/\/([^/]+)\/$/)[1];
    if ($.inArray(slug, selected_cats) != -1) {
      $(this).addClass('selected');
    }
  });
  $('h3, #navlist').corner();
  var updatePrices = function(event) {
    event.stopPropagation();
    var selectedCurrency = currencies[$('#currency').val()];
    var price = $(event.target);
    var price_data = price.data('price');
    if (!price_data) {
      price_data = price.text().match(/[^\d\s]*([\d,]+[\.,]\d+)\b/)[1].replace(/,/g, '');
    }
    var f = parseFloat(price_data);
    var v = parseFloat(selectedCurrency.value);
    price.data('price', f).text(price.text().replace(/[^\d\s]*[\d,]+[\.,]\d+\b/, selectedCurrency.symbol_left + (f * v).formatMoney()));
  };
  $('#currency').change(function() {
    $('.price').trigger('pricesChanged');
    $.cookie('currency', $('#currency').val(), {path: '/', expires: 7});
  });
  $('.price').live('pricesChanged', updatePrices);
  var currency = $.cookie('currency');
  if (currency) {
    $('#currency').val(currency);
  }
  $('#currency').change();
});

