function Bubble(code, results, func){
    this.code = code;
    this.results = results;
    this.mathML = null;
    this.equation = null;
    this.func = func;
}

Bubble.prototype.evaluateCode = function() {
    this.results = eval(this.code);
};

Bubble.prototype.drawPlot = function(options) {
    $.plot($('#bubblePlot'), this.results, options);
};

Bubble.prototype.setMathML = function(mathML) {
    this.mathML = mathML;
};

Bubble.prototype.setupEquation = function() {
    this.setMathML(editor.getMathML());
    this.func = this.parseMathML();
    return this.func;
};

function getDOM(xmlstring) {
    parser=new DOMParser();
    return parser.parseFromString(xmlstring, "text/xml");
}

function remove_tags(node) {
    var result = "";
    var nodes = node.childNodes;
    var tagName = node.tagName;
    if (!nodes.length) {
        if (node.nodeValue == "π") result = "pi";
        else if (node.nodeValue == " ") result = "";
        else result = node.nodeValue;
    } else if (tagName == "mfrac") {
        result = "("+remove_tags(nodes[0])+")/("+remove_tags(nodes[1])+")";
    } else if (tagName == "msup") {
        result = "Math.pow(("+remove_tags(nodes[0])+"),("+remove_tags(nodes[1])+"))";
    } else for (var i = 0; i < nodes.length; ++i) {
        result += remove_tags(nodes[i]);
    }

    if (tagName == "mfenced") result = "("+result+")";
    if (tagName == "msqrt") result = "Math.sqrt("+result+")";

    return result;
}

function stringifyMathML(mml) {
    xmlDoc = getDOM(mml);
    return remove_tags(xmlDoc.documentElement);
}

Bubble.prototype.parseMathML = function() {
    this.equation = stringifyMathML(this.mathML);
    return this.equation;
};
@@ -13,34 +13,17 @@
 ble(
-code, results, func
 )%7B%0A    
+//
 this
@@ -36,24 +36,26 @@
 = code;%0A    
+//
 this.results
@@ -116,24 +116,26 @@
 = null;%0A    
+//
 this.func = 
@@ -1136,17 +1136,19 @@
 h.pow((%22
-+
+ + 
 remove_t
@@ -1164,15 +1164,19 @@
 %5B0%5D)
-+
+ + 
 %22),(%22
-+
+ + 
 remo
@@ -1192,17 +1192,153 @@
 odes%5B1%5D)
-+
+ + %22))%22;%0A    %7D else if (tagName == %22msub%22) %7B%0A        result = %22digitConvert((%22 + remove_tags(nodes%5B0%5D) + %22),(%22 + remove_tags(nodes%5B1%5D) + 
 %22))%22;%0A  

digit convert