Templates = function(elm) {
	var me = this;
	
	me._templates = {};
	
	me.init = function() {
		elm.find('.template[rel]').each(function(k, obj) {
			$obj = $(obj);
			me._templates[$obj.attr('rel')] = $obj.children()
		});
	}
	
	me.destroy = function() {
	}
	
	me.get = function(name, values, callbacks) {
		var tpl = me._templates[name].clone();
		
		if (values != undefined) {
			me.fillValues(tpl, values, callbacks);
		}
		
		return tpl;
	}
	
	me.fillValues = function(tpl, values, callbacks) {
		tpl.find('.val-holder[rel],.val-container[rel],.val-region[rel]').each(function(k, obj) {
			$obj = $(obj);
			rel = $obj.attr('rel')
			
			if (callbacks != undefined && callbacks[rel] != null) {
				callbacks[rel]($obj, values[rel]);
				return;
			}
			
			if (values[rel] == undefined) {
				values[rel] = null;
			}

			if ($obj.hasClass('val-holder')) {
				$obj.text(values[rel]);
			} else if ($obj.hasClass('val-region')) {
				$obj.find('.val-holder').text(values[rel]);
				
				if ($obj.hasClass('val-region-visible-if-not-empty')) {
					if (values[rel] == null) {
						$obj.hide();
					} else if (values[rel].length != undefined && values[rel].length == 0) {
						$obj.hide();
					} else {
						$obj.show();
					}
				}
			} else {
				$obj.find('input:first').val(values[rel]);
			}
		});
	}
	
	me.init();
}