function NWTNodeInstance(a){this._node=a}function NWTNodeList(a){function g(a){return function(){console.log(a,"called",f.nodes);for(var b=0,c;c=f.nodes[b];b++)c[a].apply(c,arguments)}}var b=[];for(var c=0,d;d=a[c];c++)b.push(new NWTNodeInstance(d));this.nodes=b;var e=["remove","addClass","removeClass"],f=this;for(var c=0,h;h=e[c];c++)this[h]=g(h)}function NWTNode(){}NWTNodeInstance.prototype.ancestor=function(a){var b=this._node,c=null;for(;;){var c=Sizzle.matches(a,[b]);if(c.length>0)break;var d=b.parentNode;if(!d)break;b=d}return c[0]?new NWTNodeInstance(c[0]):null},NWTNodeInstance.prototype.hasClass=function(a){return this._node.className&&this._node.className.indexOf(a)!==-1},NWTNodeInstance.prototype.addClass=function(a){return this.hasClass(a)||(this._node.className=this._node.className+" "+a),this},NWTNodeInstance.prototype.removeClass=function(a){return this._node.className=this._node.className.replace(a,""),this},NWTNodeInstance.prototype.data=function(a){return this._node.getAttribute("data-"+a)},NWTNodeInstance.prototype.get=function(a){if(a==="parentNode"){var b=this._node[a];return b?new NWTNodeInstance(b):null}return this._node[a]},NWTNodeInstance.prototype.set=function(a,b){return this._node[a]=b,this},NWTNodeInstance.prototype.getStyle=function(a){if(!this._node.getAttribute("style"))return"";var b=this._node.getAttribute("style").match(new RegExp(a+":([a-zA-Z0-9-.]*);"),"");return b&&b[1]?b[1]:null},NWTNodeInstance.prototype.setStyle=function(a,b){this._node.getAttribute("style")||this._node.setAttribute("style","");var c=this._node.getAttribute("style").replace(new RegExp(a+":[a-zA-Z0-9-]*;"),"");return c+=a+":"+b+";",this._node.setAttribute("style",c),this},NWTNodeInstance.prototype.on=function(a,b){this._node.addEventListener(a,function(a){b(new NWTEventWrapper(a))},!1)},NWTNodeInstance.prototype.serialize=function(){var a="",b=this._node.getElementsByTagName("*");for(var c=0,d;d=b[c];c++)if(!d.disabled&&d.name&&d.name.length>0)switch(d.tagName.toLowerCase()){case"input":switch(d.type){case"checkbox":case"radio":d.checked&&(a.length>0&&(a+="&"),a+=d.name+"="+encodeURIComponent(d.value));break;case"hidden":case"password":case"text":a.length>0&&(a+="&"),a+=d.name+"="+encodeURIComponent(d.value)}break;case"select":case"textarea":a.length>0&&(a+="&"),a+=d.name+"="+encodeURIComponent(d.value)}return a},NWTNodeInstance.prototype.getContent=function(a){return this._node.innerHTML},NWTNodeInstance.prototype.setContent=function(content){this._node.innerHTML=content,this.all("script.event_hooks").each(function(eventBlock){var event=eval(eventBlock.getContent());nwt.event.implement(event),eventBlock.remove()})},NWTNodeInstance.prototype.next=function(){var a=this._node.nextSibling;return new NWTNodeInstance(a)},NWTNodeInstance.prototype.previous=function(){var a=this._node.previousSibling;return new NWTNodeInstance(a)},NWTNodeInstance.prototype.one=function(a){var b=Sizzle(a,this._node);return new NWTNodeInstance(b[0])},NWTNodeInstance.prototype.all=function(a){var b=Sizzle(a,this._node);return new NWTNodeList(b)},NWTNodeInstance.prototype.append=function(a){a instanceof NWTNodeInstance&&(a=a._node),this._node.appendChild(a)},NWTNodeInstance.prototype.remove=function(){this._node.parentNode.removeChild(this._node)},NWTNodeInstance.prototype.insert=function(a,b){b=b||"before",b=="before"?this._node.parentNode.insertBefore(a._node,this._node):b=="after"&&this._node.parentNode.insertBefore(a._node,this.next()._node)},NWTNodeInstance.prototype.click=function(){var a=document.createEvent("HTMLEvents");return a.initEvent("click",!0,!0),!this._node.dispatchEvent(a)},NWTNodeList.prototype.each=function(a){for(var b=0,c;c=this.nodes[b];b++)a(c)},NWTNodeList.prototype.item=function(a){return this.nodes[a]},NWTNodeList.prototype.size=function(){return this.nodes.length},NWTNode.prototype.create=function(a){var b=document.createElement("div");return b.innerHTML=a,new NWTNodeInstance(b.childNodes[0])},NWTNode.prototype.one=function(a){if(typeof a=="string"){var b=Sizzle(a);return b.length==0?null:new NWTNodeInstance(b[0])}return new NWTNodeInstance(a)},NWTNode.prototype.all=function(a){var b=Sizzle(a);return new NWTNodeList(b)},nwt.node=new NWTNode,nwt.one=nwt.node.one,nwt.all=nwt.node.all
