var el = new Array();
var tags = [
		'div', 'table', 'tr', 'td', 'tbody', 'thead', 'img', 'input', 'select', 'option', 'br', 'span', 'form',
    		'h3', 'b', 'a'
	];

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}
function JS2CSS(attribute) {
	var words = attribute.split('-');
	var JSAttribute = words[0];
	for (var i = 1; i < words.length; i++) {
		var word = words[i];
		JSAttribute += word.charAt(0).toUpperCase() + word.substring(1, word.length);
	}
	return JSAttribute;
}

for (var tag in tags) {
        window[tags[tag]] = new Function("content", "attributes", "refId", "\
                var newElement = document.createElement('"+tags[tag]+"');\
                for (var attribute in attributes) {\
			if (attribute == 'style') {\
				var styleAttributes = attributes[attribute].split(';');\
				for (var i = 0; i < styleAttributes.length; i++) {\
					var styleAttribute = styleAttributes[i].split(':');\
					if (trim(styleAttribute[0])) {\
						newElement.style[JS2CSS(trim(styleAttribute[0]))] = trim(styleAttribute[1]);\
					}\
				}\
			}\
			else if (attribute == 'innerHTML') {\
				newElement.innerHTML += attributes[attribute];\
			}\
			else if (attribute == 'class') {\
				newElement.setAttribute('class', attributes[attribute]);\
				newElement.setAttribute('className', attributes[attribute]);\
			}\
			else if (attribute == 'onmouseover') {\
				newElement[attribute] = new Function(attributes[attribute]);\
			}\
			else {\
				newElement.setAttribute(attribute, attributes[attribute]);\
			}\
                }\
                switch (typeof content) {\
                        case 'object':\
                                for (var childElement in content) {\
					if (typeof content[childElement] == 'string') {\
		                                newElement.appendChild(document.createTextNode(content[childElement]));\
					}\
					else {\
	                                        newElement.appendChild(content[childElement]);\
					}\
                                }\
                                break;\
                        case 'string':\
                                newElement.appendChild(document.createTextNode(content));\
                                break;\
                        default:\
                                break;\
                }\
                if (typeof refId != undefined && refId) {\
                        el[refId] = newElement;\
                }\
                return newElement;"
        );
}
