e['function1'] = function () {
	//all functions are private unless included in return statement
// 'abstract' method implementations (for api)
	function getInterface() {
		var out = "<ul>";
		// title
		out += "<li><h1>Polynomials</h1></li>";
		// input #1
		out += "<li><label for='degree'>Degree</label></li>";
		out += "<li class='input'><input type='text' id='degree' value='5'/></li>";
		// input #2
		out += "<li><label for='coefficients'>Coefficients</label></li>";
		out += "<li class='input'><input type='text' id='coefficients' value='1 -2 -21 38 80 -96'/></li>";
		//submit button
		out += "<li>&nbsp;</li>";
		out += "<li class='input'><input id='submit' onclick=\"e['function1'].getHTML(document.getElementById('returnValue'))\" type='submit' value='Calculate'/></li>";

		out += "</ul>";
		return out;
	}

	function getHTML(returnNode) {
		if (validateInput()) {
			// grab input vals
			var coeffs = document.getElementById('coefficients').value.split(" ");

			//format for output and create html
			var out = "<ul>";
			out += "<li><h1>Results</h1></li>";
			out += getNumOfRoots(coeffs);
			out += getRootsInRange(coeffs);
			out += getRootCount(coeffs);
			out += "</ul>";
			returnNode.innerHTML = out;
		}
	}

	function validateInput() {
		coeffs = document.getElementById('coefficients');
		while (coeffs.value.split(" ")[0] == 0) {
			coeffs.value = coeffs.value.substr(2);
		}
		document.getElementById('degree').value = coeffs.value.split(" ").length-1;
		return true;
	}

// Program & Presentation Functions
	function getNumOfRoots(coeffs) {
		var num = countSignChanges(coeffs,false) + countSignChanges(coeffs, true); // Is this incorrect? (pos + neg)

		var out = "<li><span>Number of Roots</span></li>";
		return out + "<li class='output'><span id='results_numRoots'>" + (typeof num == "object" ? num.length : num) + "</span></li>";

	}
	function getRootsInRange(coeffs) {
		var range = newtonsRelation(coeffs);

		var out = "<li><span>Roots in the Range</span></li>";
		return out + "<li class='output'><span id='results_rootsRange'>" + (range == "" ? "" :  Math.abs(parseInt(range)+1) * -1 + " < roots < " +  Math.abs(parseInt(range)+1)) + "</span></li>";
	}
	function getRootCount(coeffs) {
		var out = "<li><span>Positive Roots</span></li>";
		out += "<li class='output'><span id='results_numPos'>" + countSignChanges(coeffs, false) + "</span></li>";

		out += "<li><span>Negative Roots</span></li>";
		return out + "<li class='output'><span id='results_numNeg'>" + countSignChanges(coeffs, true) + "</span></li>";

	}

// Math Functions
	function newtonsRelation(a) {
		return Math.sqrt( Math.pow((parseFloat(a[1]) / parseFloat(a[0])), 2) - 2 * (parseFloat(a[2]) / parseFloat(a[0])) );
	}
	function countSignChanges(coeffs, doSwap) {
		var count = 0;
		var blnSign;

		blnSign = ( (doSwap == true && (coeffs.length-1)%2==1 ? coeffs[coeffs.length-1] * -1 : coeffs[coeffs.length-1]) > 0 ? true : false);

		for (var i = coeffs.length-1; i >= 0; i--) {
			if (((doSwap == true && i%2==1 ? coeffs[i] * -1 : coeffs[i]) > 0 && blnSign == false) ||
				((doSwap == true && i%2==1 ? coeffs[i] * -1 : coeffs[i]) < 0 && blnSign == true)) {
				blnSign = !blnSign;
				count++;
			}
		}
		return count;
	}
	function countRoots(maxRoots) {
		var out = maxRoots % 2;
		for (var i = (maxRoots%2) + 2; i <= maxRoots; i = i + 2) {
			out += (" or " + i);
		}
		return out;
	}

// return public pointers to the private methods
	return {
		getInterface:getInterface,
		getHTML:getHTML,
		validateInput:validateInput,

		getNumOfRoots:getNumOfRoots,
		getRootsInRange:getRootsInRange,
		getRootCount:getRootCount,
		countSignChanges:countSignChanges,
		newtonsRelation:newtonsRelation
	}

}();

