jQuery.fn.createChart = function(settings) {
    this.props = {
        title: ""
    };

    settings = jQuery.extend({
        type: "",
        width: 600,
        height: 320,
        html_title: false,
        tool_tip: "",
        x_col: 1,
        y_col: 2,
        y_max: 100,
        y_steps: 10,
        x_label_orient: 0,
        c_class: ""
    }, settings);
    var xlabels = new Array();
    var values = new Array();

    $(this).find("tbody tr td:nth-child("+settings.x_col+")").each(function() {
        xlabels[xlabels.length] = $(this).text();
    });

    $(this).find("tbody tr td:nth-child("+settings.y_col+")").each(function() {
        values[values.length] = $(this).text();
    });

    var url = "/anim/chart-data.php?";
    this.props.title = $(this).find("caption").text();

    if (!settings.html_title) {
        url += "title="+escape(this.props.title+",{font-size:10px; color:#000000}");
    }

    url += "&x_legend="+escape($(this).find("thead th:nth-child(1)").text()+",10,#AAAAAA");
    url += "&y_legend="+escape($(this).find("thead th:nth-child(2)").text()+",10,#AAAAAA");
    url += "&y_label_size="+escape("15");
    url += "&y_steps="+escape(settings.y_steps);
    url += "&values="+escape(values.join(","));
    url += "&x_labels="+escape(xlabels.join(","));
    url += "&y_max="+escape(settings.y_max);
    url += "&bg_colour="+escape("#FFFFFF");
    url += "&x_axis_colour="+escape("#000000");
    url += "&x_grid_colour="+escape("#AAAAAA");
    url += "&y_axis_colour="+escape("#000000");
    url += "&y_grid_colour="+escape("#AAAAAA");
    url += "&x_label_style="+escape("8,#000000,"+settings.x_label_orient+",1,#000000");
    url += "&type="+escape(settings.type);

    if (settings.tool_tip.length > 0) {
        url += "&tool_tip="+escape(settings.tool_tip);
    }

    var outer = $("<div id=\""+$(this).attr("id")+"_chart\" class=\""+settings.c_class+"\"></div>");
    var inner = $("<div id=\""+$(this).attr("id")+"_chartinner\"></div>");
    outer.append(inner);

    if (settings.html_title) {
        outer.prepend("<p>"+this.props.title+"</p>");
    }

    $(this).after(outer);
    $(inner).flash(
        {
            src: "/anim/open-flash-chart.swf",
            width: settings.width,
            height: settings.height,
            flashvars: {data: url}
        },{version:8}
    );

    return this;
}
