function formatNumber(str) {
  var regex = /(-?[0-9]+)([0-9]{3})/;
  str += '';
  while (regex.test(str)) {
    str = str.replace(regex, '$1.$2');
  }
  return str;
}

(function ($) {
  $.fn.vAlign = function() {
    return this.each(function(i) {
      var ah = $(this).height();
      var ph = $(this).parent().outerHeight();
      var mh = (ph - ah) / 2;
      $(this).css('margin-top', mh);
    });
  };
  $.fn.hoverButton = function() {
    return this.each(function(i) {
      var self = $(this);
      if(self.is('img, input:image')) {
        self.data('s:normal', self.attr('src'));
        self.data('s:hover', self.attr('src').replace(/\.(?=(gif|png|jpe?g))/, '_hover.'));
        self.hover(function() {
          self.attr('src', self.data('s:hover'));
        }, function() {
          self.attr('src', self.data('s:normal'));
        });
        $('<img />').attr('src', self.data('s:hover')).error(function() {
          self.unbind('mouseenter mouseleave');
        });
      }
    });
  };
})(jQuery);

jQuery(function($) {
  $('.hover-button').hoverButton();
});

