/* jQuery Headers Replacement plugin
 * Version:  0.1 
 * Author: Karol Janyst
 *
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <karol@janyst.pl> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Karol Janyst
 * ----------------------------------------------------------------------------
 */

  jQuery.replaceElements = function (data) {
    var param = eval(data);
    $.each($(param.elements), function () {
      var text = $(this).text();
      if (text != null) { 
        var insert = $.create("span", {"id" : text}, [text]);
        $(insert).hide();
        $(this).text("");
        $(this).append($(insert));

        var words = $(this).text().split(" ");
        $.each(words, function () {
          var time = new Date().getTime()
          var word_img = new Image();
          $(word_img).attr("id", this + time);
          var query = $.query
            .set("text", this + " ")
            .set("font", param.font)
            .set("color", param.color)
            .set("size", param.size)
            .set("border", param.border ? "true" : "false")
            .set("border_size", $.query.get(param.border_size))
            .set("border_color", $.query.get(param.border_color)).toString();
          $(word_img).attr("src", param.image + query);
          $(insert).parent().append($(word_img));
        })
      }
    });
  };
