/**
 * Parses data in the html. The data must be in the form:
 * <code>
 *  <ins class="data"> 
 * 		<ins class="key1">value1</ins>
 * 		<ins class="key2">value2</ins>
 *  </ins>
 * </code>
 * 
 * @constructor
 */
function DataMap() {
	
	var _dataMap = {};
	
	this.parseRaw = function (rawHtml) {
		// add a root element
		var $data = $(rawHtml);
		var $cont = $("<div></div>");
		$cont.html($data);
		return this.parse($cont);
	};
	
	this.parse = function($container) {
		var dataPairs = $("ins.data ins", $container);
		for(var i = 0; i < dataPairs.length; i++){
			var $pair = $(dataPairs[i]);
			
			var key = $pair.attr("class");
			var value = $pair.html();
			_dataMap[key] = value;
		};
 
		return _dataMap;
	};
	
	this.clear = function() {
		_dataMap = {};
	};
	
	this.getRaw = function(key) {
		this._checkKey(key);
		return _dataMap[key];
	};
	
	this.getInt = function(key) {
		this._checkKey(key);
		return parseInt(_dataMap[key]);
	};
	
	this.getFloat = function(key) {
		this._checkKey(key);
		return parseFloat(_dataMap[key]);
	};
	
	this.getBool = function(key) {
		this._checkKey(key);
		var val = _dataMap[key];
		return val == "1" || val == "true";
	};
 
	this._checkKey = function(key) {
		if (_dataMap[key] === undefined) {
			throw ("The key "+key+" does not exist!");
		}
	};
};
