 	@DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 32
 
 	constructor: (name, value = null, type = 1, ownerDocument = null) ->
-		@_private = {
+		@_private =
 			nodeName: null
 			parentNode: null
 			childIndex: -1
 			classes: []
-		}
-		@__defineGetter__ 'nodeName', () => @_private.nodeName
-		@__defineSetter__ 'nodeName', (v) => @_private.nodeName = v?.toUpperCase()
 		@nodeName = name
 		@nodeValue = value
 		@nodeType = type
 		@ownerDocument = ownerDocument
 		@childNodes = []
 		@attributes = {}
-		@__defineGetter__ 'previousSibling', () => @parentNode?.childNodes[@_private.childIndex-1]
-		@__defineSetter__ 'nextSibling', () => @parentNode?.childNodes[@_private.childIndex+1]
-		@__defineGetter__ 'parentNode', () => @_private.parentNode
-		@__defineSetter__ 'parentNode', (v) =>
-			if v isnt null
-				throw Error "Must use one of appendChild, insertBefore, etc. to give a Node a new parent."
-			@_private.parentNode?.removeChild @
-			@_private.parentNode = null
-			@_private.childIndex = -1
-		@__defineGetter__ 'firstChild', () => @childNodes[0]
-		@__defineGetter__ 'lastChild', () => @childNodes[-1]
-		@__defineGetter__ 'id', () => @attributes['id']
-		@__defineSetter__ 'id', (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
-		@__defineGetter__ 'className', () => @attributes['class']
-		@__defineSetter__ 'className', (value) =>
-			### getElementsByClassName optimization for the future
-			if @ownerDocument? # un-map old class values
-				for cls in (@attributes['class'] ? "").split(/ +/)
-					a = (@ownerDocument._private.classMap[cls] ?= [])
-					i = a.indexOf @
-					if i > -1
-						a.splice(i, 1)
-				# map the new class values
-				for cls in value.split(/ +/)
-					(@ownerDocument._private.classMap[cls] ?= []).push(@)
-			###
-			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(' ')
-
-		@listeners = {
+		@listeners =
 			true: {}
 			false: {}
-		}
+
 	# compareDocumentPosition: NotSupported
 	# isDefaultNamespace: NotSupported
 	# isEqualNode: NotSupported

class DocumentFragment extends Node
	constructor: (owner) ->
		super "#document-fragment", null, Node.DOCUMENT_FRAGMENT_NODE, owner
		@__defineSetter__ 'parentNode', (v) =>
			throw Error "DocumentFragment cannot have a parentNode"
	toString: (pretty=false, deep=true) ->
		ret = []
		r = 0
		for c in @childNodes
			ret[r++] = c.toString pretty, deep
		return ret.join('')

class Document extends Element
	constructor: (a...) ->

			ret[r++] = indent + "</#{name}>" + newline
		ret.join('')

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
Element::__defineGetter__ 'innerText', () ->
	t = []
	for c in @childNodes
		if c.nodeType in [Node.TEXT_NODE, Node.CDATA_SECTION_NODE]
			t.push c.toString(false, false)
		else if c.nodeType isnt Node.COMMENT_NODE
			t.push c.innerText
	return t.join('')

class Attr extends Node
	constructor: (name, value) ->
		super name, value, Node.ATTRIBUTE_NODE, null
