(function($) {

$.extend({
  
  textwrap: {
    defaults: {
      left_lines: null,
      right_lines: null, 
      left_curve: null,      // curve pairs are [%, px]
      right_curve: null,
      step: 6,
      height: 500
    }
  },
  bez: {// slightly modified... 13thParallel.org Beziér Curve Code by Dan Pupius (www.pupius.net)
    coord: function (x,y) {
      if(!x) var x=0;
      if(!y) var y=0;
      return {x: x, y: y};
    },
    b1: function (t) { return t*t*t },
    b2: function (t) { return 3*t*t*(1-t) },
    b3: function (t) { return 3*t*(1-t)*(1-t) },
    b4: function (t) { return (1-t)*(1-t)*(1-t) },
    getBezier: function (percent, bcp1, bcp2, bcp3, bcp4) {
      var pos = new $.bez.coord();
      pos.x = bcp1.x * $.bez.b1(percent) + bcp2.x * $.bez.b2(percent) + bcp3.x * $.bez.b3(percent) + bcp4.x * $.bez.b4(percent);
      pos.y = bcp1.y * $.bez.b1(percent) + bcp2.y * $.bez.b2(percent) + bcp3.y * $.bez.b3(percent) + bcp4.y * $.bez.b4(percent);
      return pos;
    }
  }
});
$.fn.extend({
  textwrap: function( options ) {

    var options = $.extend({}, $.textwrap.defaults, options);

    return this.each(function() {
      
      if( options.left_curve )
      {
        var c1 = new $.bez.coord(options.left[0][1], options.height*options.left[0][0]);
        var c2 = new $.bez.coord(options.left[1][1], options.height*options.left[1][0]);
        var c3 = new $.bez.coord(options.left[2][1], options.height*options.left[2][0]);
        var c4 = new $.bez.coord(options.left[3][1], options.height*options.left[3][0]);
      }
      else if ( options.left_lines )
      {
        
      }
      if( options.right_curve )
      {
        var c5 = new $.bez.coord(options.right[0][1], options.height*options.right[0][0]);
        var c6 = new $.bez.coord(options.right[1][1], options.height*options.right[1][0]);
        var c7 = new $.bez.coord(options.right[2][1], options.height*options.right[2][0]);
        var c8 = new $.bez.coord(options.right[3][1], options.height*options.right[3][0]);
      }
      else if ( options.right_lines )
      {
        
      }

      var x;
      for(var i = 0; i < options.height; i+= options.step)
      {
        if( options.left_curve )
        {
          x = Math.round($.bez.getBezier((i / options.height), c1, c2, c3, c4).x);
          if( x < 0 )
            x = 0;
          $(this).prepend( $('<div style="float:left;clear:left;width:'+x+'px;height:'+options.step+'px"></div>') );          
        }
        if( options.right_curve )
        {
          x = Math.round($.bez.getBezier((i / options.height), c5, c6, c7, c8).x);
          if( x < 0 )
            x = 0;
          $(this).prepend( $('<div style="float:right;clear:right;width:'+x+'px;height:'+options.step+'px"></div>') );          
        }
      }
    });
  }
});

})(jQuery);