 	write: NotSupported
 	writeln: NotSupported
 
-exports.createDocument = () ->
+exports.createDocument = ->
 	new HTMLDocument()
 
 exports.registerGlobals = (g) ->

			super a...
}

Element::__defineGetter__ 'tagName', () -> @nodeName
Element::__defineGetter__ 'innerHTML', () ->
	h = []
	for c in @childNodes
		h.push c.toString()
	return h.join('')
Element::__defineSetter__ 'innerHTML', (v) ->
	fragment = htmlparse(v, @ownerDocument)
	for c in @childNodes
		c._private.parentNode = null
		c._private.childIndex = -1
	@childNodes.length = 0
	@appendChild fragment

getInnerText = () ->
	t = []
	for c in @childNodes
		if c.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]

		# dont shortcut here, since removeChild does some book-keeping for us
		@removeChild(0)
	@appendChild(new Text(text, @))

property Element::, 'innerText',
	get: getInnerText
	set: setInnerText
property Element::, 'textContent',
	get: getInnerText
	set: setInnerText
property Element::, 'id',
	get: -> @attributes['id']
	set: (value) ->
		o = @ownerDocument?
		if o
			if @attributes.id?
				delete @ownerDocument._private.idMap[@attributes.id]
		if value in [null, undefined, "undefined"]
			delete @attributes.id
		else
			if o
				@ownerDocument._private.idMap[value] = @
			@attributes.id = value
property Element::, 'className',
	get: -> @attributes['class'] or ""
	set: (value) ->
		if value in [null, undefined, "undefined"]
			delete @attributes.class
			@_private.classes.length = 0
		else
			@attributes['class'] = value
			# Optimization for getElementsByClassName, cache the split form
			@_private.classes = value.split(' ')

property HTMLInputElement::, 'value',
	get: -> @attributes.value or (if @attributes.type in ['checkbox','radio'] then "on") or ""
	set: (v) -> @setAttribute('value',v)

property HTMLInputElement::, 'checked',
	get: -> @hasAttribute('checked')
	set: (v) ->
		if v? then @setAttribute('checked','checked')
		else @removeAttribute('checked')

property HTMLInputElement::, 'selected',
	get: -> @hasAttribute('selected')
	set: (v) ->
		if v? then @setAttribute('selected','selected')
		else @removeAttribute('selected')

property HTMLSelectElement::, 'selectedIndex',
	get: ->
		if not (@_private.selectedIndex? and @_private.selectedIndex < @childNodes.length)
			for index in [0...@childNodes.length]
				if @childNodes[index].hasAttribute 'selected'
					@_private.selectedIndex = index
		return @_private.selectedIndex or 0
	set: (v) ->
		if v < @childNodes.length
			for index in [0...@childNodes.length]
				if index is v
					@childNodes[index].setAttribute('selected','selected')
				else
					@childNodes[index].removeAttribute('selected')
			@_private.selectedIndex = v
		return @_private.selectedIndex or 0

property HTMLOptionElement::, 'value',
	get: -> if @hasAttribute('value') then @getAttribute('value') else @innerText
	set: (v) -> @setAttribute('value',v)

property HTMLSelectElement::, 'value',
	get: -> @childNodes[@selectedIndex]?.value
	set: (v) ->
		for index in [0...@childNodes.length]
			child = @childNodes[index]
			if child.value is v
				@selectedIndex = index

class Attr extends Node
	constructor: (name, value) ->
