var $CE = function(tagName, attributes, styles){ //short for create element
      var el = document.createElement(tagName);
      if (attributes)
            $H(attributes).each(function(pair){
                  eval("el." + pair.key + "='" + pair.value + "'");
            });
      if (styles)
            $H(styles).each(function(pair){
                  el.style[pair.key] = pair.value;
            });

      return $(el);
};

//adding he new methods
Element.addMethods({
	//removes any child noes from the element
	//example: <div id="myDiv"><b>hello</b></div>
	//         $('myDiv').clearChildren();
	//     ==> <div id="myDiv"></div>
	clearChildren: function(element) {
		element = $(element);
		$A(element.childNodes).each(function(e){
			  e.parentNode.removeChild(e);
		});
		return element;
	},
	//method that creates a new element and appends to the current element
	// example: <div id="myDiv">Please</div>
	//          $('myDiv').append('A',{href:'otherpage.html', className:'red'}).update('Continue...');
	//     ==>  <div id="myDiv">Please<a href="otherpage.html" class="red">Continue...</a></div>
	append: function(element, tagName, attributes, styles) {
		element = $(element);
		var newEl = $CE(tagName, attributes, styles);
		element.appendChild(newEl);
		return newEl;//<-- this one returns the new element
	},
	//appends a text node to the element
	// example: <div id="myDiv"><b>hello</b></div>
	//          $('myDiv').appendText(', John');
	//      ==> <div id="myDiv"><b>hello</b>, John</div>
	appendText: function(element, text){
		element = $(element);
		var t = document.createTextNode(text);
		element.appendChild(t);
		return element;
	  }
});