function LavaTi() {
  var path = window.location.pathname;
  $('ul#menuLava li.current').attr('class', '');
  $('ul#menuLava li').each(function() {
    var href = $(this).find('a').attr('href');
    if ((href == path) | ((href == '/shop/') && (path == '/shop/checkout'))) {
      $(this).attr('class', 'current');
    }
  });
}

$(document).ready(function() {
  var path = window.location.pathname;
  LavaTi();
  if (path == '/shop/') {
    $('div.thumb:first').find('a').attr('class', 'active');
    $('div.thumb').bind('click', function(event) {
      $('div#varianti').find('a').each(function() {
        $(this).attr('class', 'none');
      });
      var my_id = $(this).attr('id'),
        a = $(this).find('a');
      a.attr('class', 'active');
      $('div#imageGrande img').attr('src', '/ima/blister/' + my_id + '_g.png');
      $('div#cascoColore img').attr('src', '/ima/blister/' + my_id + '_casco.png');

      $('form input[name=product]').val(my_id);

      return false;
    });
  }

  $.ajax({
    url: '/shop/cart.json',
    type: "GET",
    dataType: 'json',
    success: function(data) {
      $('a#cartLabel p span').html(data.number);
    }
  });

  var t = $('span#totaleAcquisto').html();



  function fixMePlease() {
    var v = $("input:checked").val();
    if (v == 'contrassegno') {
      $('span#contrassegno').html('4,00');
      $('span#totaleAcquisto').html(((t.replace(',', '.') * 1) + 4) + ',00');
    } else {
      $('span#totaleAcquisto').html(t);
      $('span#contrassegno').html('0,00');
    }
  }
  $("input[type=radio]").click(fixMePlease);
  fixMePlease();
});

