// Temperature Converter 
TemperatureConverter = Class.create();

TemperatureConverter.prototype = {
	initialize : function(unit, value){
		this.uv = new Array(); 
		this.uv = {
			"degC" : 1, // ref unit
			"degF" : 60,
			"degK" : 3600,
			"degR" : 1000
		}
		this.unit = unit; // unit to convert from
		this.value = value; // value to convert
		if (unit == "degC") this.ref = 1 * this.value;
		if (unit == "degF") this.ref = 5/9 * (this.value - 32);
		if (unit == "degK") this.ref = this.value - 273.16;
		if (unit == "degR") this.ref = 5/9 * ((this.value - 459.69) - 32);
	},
	cV : function(unitTo){ // returns value for singel unit
		var cv; 
		if (unitTo == "degC") cv = this.ref;
		if (unitTo == "degF") cv = 9/5 * this.ref + 32;
		if (unitTo == "degK") cv = this.ref + 273.16;
		if (unitTo == "degR") cv = (9/5 * this.ref + 32) + 459.69;
		return cv; 
	},
	cVs : function(){ // returns text formatted values for all units
		var msg = this.value + " " + this.unit + " => \n";
		msg += Conv.rounding(this.ref) + " deg C, \n";
		msg += Conv.rounding(9/5 * this.ref + 32) + " deg F, \n";
		msg += Conv.rounding(this.ref + 273.16) + " K, \n";
		msg += Conv.rounding((9/5 * this.ref + 32) + 459.69)  + " deg R \n";
		return msg;
	},
	cVHTML : function(){ // returns html formatted values for all units
		var msg = "<h2>Temperature Converter</h2>";
		msg += "<p>" + this.value + " " + this.unit + " => </p><br />";
		msg += "<p><ul>";
		msg += "<li>" + Math.round(this.ref * 100)/100 + " deg C</li>";
		msg += "<li>" + Math.round((9/5 * this.ref + 32) * 100)/100 + " deg F</li>";
		msg += "<li>" + Math.round((this.ref + 273.16) * 100)/100 + " K</li>";
		msg += "<li>" + Math.round(((9/5 * this.ref + 32) + 459.69) * 100)/100 + " deg R</li>";
		msg += "</ul></p>";
		return msg;
	}	
}
// Copyright engineeringtoolbox.com