fun = function(m){
                if(m["xui.Module"]){
                    for(var i=0,o;o=m._nodes[i];i++){
                        if(o["xui.Module"]) return fun(o);
                        if(o["xui.UIProfile"] && !o.box.$initRootHidden) return rtnPrf?o:o.getRoot();
                    }
                }
            }
* In IE, click a fake(javascript: or #) href(onclick not return false) will break the current script downloading(SAajx)
                //**** You have to return false here
                if(xui.browser.ie && (href.indexOf('javascript:')==0 || href.indexOf('#')!==-1))return false;
            }
        },'hookA',0);

        var _ieselectstart=function(n,v){
            n=window.event.srcElement;
            while(n&&n.nodeName&&n.nodeName!="BODY"&&n.nodeName!="HTML"){
                if(v=xui.getNodeData(n,"_onxuisel"))
                    return v!='false';
                // check self only
                if(n.nodeName=="INPUT"||n.nodeName=="TEXTAREA")
                    break;
                n=n.parentNode;
            }
            return true;
        };
        if(xui.browser.ie && xui.browser.ver<10 && d.body)
            xui.Event._addEventListener(d.body,"selectstart", _ieselectstart);

        //free memory
        xui.win.afterUnload(xui._destroy = function(){
            var t,
            lowie=xui.browser.ie && xui.browser.ver<=8,
            e=xui.Event,
            _cw=function(w,k){
                w[k]=undefined;
                if(!lowie)
                    delete w[k];
            };

            if(xui.History && xui.History._checker)e._removeEventListener(w, "hashchange", xui.History._checker);
            e._removeEventListener(d.body, "selectstart", _ieselectstart);
            e._removeEventListener(w, "resize", e.$eventhandler);

            e._removeEventListener(w, "mousewheel", e.$eventhandler3);
            e._removeEventListener(d, "mousewheel", e.$eventhandler3);
            // firfox only
            e._removeEventListener(w, "DOMMouseScroll", e.$eventhandler3);
            // for simulation mouse event in touable device
            if(xui.browser.isTouch){
                e._removeEventListener(d,
                    (xui.browser.ie&&w.PointerEvent)?"pointerdown":
                    (xui.browser.ie&&w.MSPointerEvent)?"MSPointerDown":
                    "touchstart", e._simulateMousedown);
                e._removeEventListener(d,
                    (xui.browser.ie&&xui.browser.ver>=11)?"pointerup":
                    (xui.browser.ie&&xui.browser.ver>=10)?"MSPointerUp":
                    "touchend", e._simulateMouseup);
            }

            // xui.win.afterUnload ...
            for(var i in (t=xui.$cache.domPurgeData))
                if(t[i].eHandlers)
                    xui(i).$clearEvent();

            // destroy all widgets and moudles
            // xui('body').empty(true,true);
            for(var i in (t=xui._pool)){
                t[i] && t[i].destroy && t[i].destroy(1,1);
                t[i] && t[i].Instace && t[i].Instace.destroy && t[i].Instace.destroy(1,1);
            }

            // root module ref
            _cw(w,xui.ini.rootModuleName);
            if(w.Raphael && w.Raphael._in_xui){
                _cw(w,'Raphael');
            }

            xui.SC.__gc();
            xui.Thread.__gc();
            xui.Class.__gc();
            if(/xui\.Class\.apply/.test(w.Class)) _cw(w,'Class');
            if((t=xui.Namespace._all))for(var i in t)  _cw(w, t[i]);
            xui.breakO(xui.$cache,2);
            xui.breakO([xui.Class, xui],3);
            _cw(w,'xui_ini');
            _cw(w,'xui');

            w=d=null;
        },"window",-1);
    }
});xui.Class('xui.Template','xui.absProfile',{
    Constructor:function(template,properties,events,domId){
        var upper=arguments.callee.upper, args=xui.toArr(arguments);
        upper.apply(this,args);
        upper=null;

        var self=this;
        self.$domId = self.KEY + ':' + (self.serialId=self._pickSerialId()) + ':';
        self.domId = typeof domId == 'string'?domId:self.$domId;
        self._links={};
        self.template={'root':[['<div></div>'],[]]};
        self.properties={};
        self.events={};
        self.$template={};
        self.link(self.constructor._cache,'self').link(xui._pool,'xui');
        self.Class=self.constructor;
        self.box=self.constructor;
        self.boxing=function(){return this};

        if(template)self.setTemplate(typeof template=='string'?{'root':template}:template);
        if(events)self.setEvents(events);
        if(properties)self.setProperties(properties);
        return self;
    },
    Instance : {
        renderId:null,
        __gc:function(){
            var self=this,
                t=xui.$cache.reclaimId;
            if(!self.$noReclaim)
                (t[self.KEY] || (t[self.KEY]=[])).push(self.serialId);
            else
                delete self.$noReclaim

            delete xui.$cache.profileMap[self.domId];
            delete xui.$cache.profileMap[self.$domId];
            self.unLinkAll();
            xui.breakO([self.properties, self.event, self], 2);
        },
        _reg0:/^\w[\w_-]*$/,
        show:function(parent){
            if(!parent)parent=xui('body');
            parent=xui(parent);
            parent.append(this);
            return this;
        },
        getRootNode:function(){
            return xui.getNodeData(this.renderId, 'element');
        },
        /*
getRoot is the only function that depends on xui.Dom Class