function fixTail() {
  $ = jQuery;
  $('.tail').each(function() {
     var length = parseFloat($(this).parents('.views-row').find('.views-field-title').width() + 16);
     $(this).css({
       marginLeft: length + 'px'
     });
   });     
}

(function($) {
  $(document).ready(function() {
    
    $('.views-slideshow-controls-bottom').ready(function() {
      // Center the pager for the front page slideshow
      var pagerItems = $('#widget_pager_bottom_specials-block .views-slideshow-pager-field-item, #widget_pager_bottom_gallery-page .views-slideshow-pager-field-item').length;
      // Calculate how big the pager div is with each button occupying 20px (plus 2 controls buttons)
      var divWidth = 40 + (pagerItems * 20);
      $('.views-slideshow-controls-bottom').css({width: divWidth, marginLeft: divWidth / 2 * -1});
    });
    fixTail();
    $('#quicktabs-menu li a, .ui-accordion-header a').click(fixTail);
    
    // Calculate totals
    $('.view-food-menu select').change(function() {
      
      // sub_total = qty * price;
      sub_total = 0;
      tax = '.0875';
      order = '';
      $('.view-food-menu .views-row').each(function() {
        qty = $(this).find('select').val();
        price_text = $(this).find('.views-field-field-price .field-content').html();
        price = parseFloat(price_text.substr(1));
        
        if (qty > 0) {
          title = $(this).find('.views-field-title .field-content').html();
          order += qty +' - '+ title +"\n";
        }
        
        sub_total += qty * price;
        with_tax = sub_total * tax;
        total = sub_total + with_tax;
        $('#order-sub-total span').html('$'+ sub_total.toFixed(2));
        $('#order-tax span').html('$'+ with_tax.toFixed(2));
        $('#order-total span').html('$'+ total.toFixed(2));
        $('#edit-submitted-total').val('$'+ total.toFixed(2));
        $("#edit-submitted-order").val(order);
      });
    });
    
    // Fix a layout issue on order page
    $(".ui-accordion-content > .views-row >.views-field-body").css('margin-top', 0);
    $(".ui-accordion-content > .views-row > .views-field-nothing").css('top', 0);
    if (jQuery.browser.msie && parseInt(jQuery.browser.version) <= 7) {
      $(".view-food-menu .views-row .lowfat").next().css('margin-left', '-18px');
    }
    
  });
})(jQuery);;
;

