/**
 * HTMLFactory Class
 * A wonderful invention which easy produces valid HTML Objects
 * author: james revillini
 */
function HTMLFactory () {
	while (tag = each(this.elements)) {
		dynofunc = "this[tag] = function (content, attributes) { return (this.tag('" + tag + "', content, attributes)); };";
		eval(dynofunc);
	}
};

HTMLFactory.prototype.elements = ['div', 'blockquote', 'p'];

HTMLFactory.prototype.tag = function (tag, content, attributes) {
	var element = document.createElement(tag);
	var children;
	if (content) {
		switch (typeof(content)) {
			case 'string' : 
				children = [document.createTextNode(content)];
				break;
			case 'object' :
				children = [content];
				break;
			case 'array' :
				children = content;
				break;
		}
		while (child = each(children)) {
			element.appendChild(child);
		}
	}

	if (attributes) {
		for (attribute_key in attributes) {
			attribute_value = attributes[attribute_key];
			if (attribute_key == 'class') {
				element.className = attribute_value;
				continue;
			}
			element.setAttribute(attribute_key, attribute_value);
		}
	}
	
	return (element);
};

HTMLFactory.prototype.constructor = HTMLFactory;

window.HTML = new HTMLFactory();