(function($){

  $.fn.textResize = function(options) {

    var opts = jQuery.extend({
      buttonIncrease: '',
      buttonDecrease: '',
      includes: '*',
      number: 2,
      max: 5
    }, options);
    
    var container = $(this);
    
    $(opts.buttonIncrease).each(function () {
      $(this).click(function () {
        if (opts.max <= $.textResize.counter) {
          return false;
        }
          
        container.find(opts.includes).each(function () {
          $.textResize.increase(this, opts.number);
        });
          
        $.textResize.counter += 1;
        
        return false;
      });
    });
    
    $(opts.buttonDecrease).each(function () {
      $(this).click(function () {
        if (0 >= $.textResize.counter) {
          return false;
        }
        
        container.find(opts.includes).each(function () {
          $.textResize.decrease(this, opts.number);          
        });
        
        $.textResize.counter -= 1;
          
        return false;
      });
    });
        
    return this;
  };
  
  $.textResize = {

    increase: function (container, number) {
      container = $(container);
      var fontSize = parseInt(container.css('font-size').replace('px', '')) + number;
      var lineHeight = (parseInt(container.css('line-height').replace('px', '')) + number) + 'px';
            
      container.css('font-size', fontSize).css('line-height', lineHeight);    
    },

    decrease: function (container, number) {
      container = $(container);
      var fontSize = parseInt(container.css('font-size').replace('px', '')) - number;
      var lineHeight = (parseInt(container.css('line-height').replace('px', '')) - number) + 'px';

      container.css('font-size', fontSize).css('line-height', lineHeight);
    },
    
    counter: 0
    
  };
})(jQuery);

