Ext.BLANK_IMAGE_URL = root + 'ext/docs/resources/s.gif';
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());

Docs = {};
mainPanel = {}; //luor, changed to global for access in gohome()

ApiPanel = function () {
    ApiPanel.superclass.constructor.call(this, {
        id: 'api-tree',
        border: false,
        rootVisible: false,
        lines: false,
        autoScroll: true,
        animCollapse: false,
        animate: false,
        collapseMode: 'mini',
        height: Ext.getBody().getViewSize().height - 70,
        xtype: 'panel',
        loader: new Ext.tree.TreeLoader({
            preloadChildren: true,
            clearOnLoad: true
        }),
        root: new Ext.tree.AsyncTreeNode({
            text: 'Ext JS',
            id: 'root',
            expanded: true,
            children: [Docs.classData]
        }),
        collapseFirst: false
    });
    // no longer needed!
    //new Ext.tree.TreeSorter(this, {folderSort:true,leafAttr:'isClass'});

    this.getSelectionModel().on('beforeselect', function (sm, node) {
        return node.isLeaf();
    });
};

Ext.extend(ApiPanel, Ext.tree.TreePanel, {
    initComponent: function(){
        this.hiddenPkgs = [];       
        // auto filter
        Ext.apply(this, {
            tbar: [        
		    new Ext.form.TextField({
				    width: 200,
				    emptyText:'Find Documents by Title',
				    enableKeyEvents: true,
				    listeners:{
					    render: function(f){
						    this.filter = new Ext.tree.TreeFilter(this, {
						    clearBlank: true,
						    autoClear: true
						    });
					    },
					    keydown: {
						    fn: this.filterTree,
						    buffer: 350,
						    scope: this
					    },
				    scope: this
				    }
		    }),            	    
            {
                iconCls: 'icon-expand-all',
				tooltip: 'Expand All',
                handler: function(){ this.root.expand(true); },
                scope: this
            },              	    
            '-', 
            {
                iconCls: 'icon-collapse-all',
                tooltip: 'Collapse All',
                handler: function(){ this.root.collapse(true); },
                scope: this
            }
        ]
        }) 
        ApiPanel.superclass.initComponent.call(this);
    },
	filterTree: function(t, e){
		var text = t.getValue();
		Ext.each(this.hiddenPkgs, function(n){
			n.ui.show();
		});
		if(!text){
			//alert(text);
			this.filter.clear();
			return;
		}
		this.expandAll();
		
		//var re = new RegExp('^' + Ext.escapeRe(text), 'i');
		var re = new RegExp(Ext.escapeRe(text), 'i');
		this.filter.filterBy(function(n){
			return !n.attributes.isClass || re.test(n.text);
		});
		
		// hide empty packages that weren't filtered
		/*
		this.hiddenPkgs = [];
		this.root.cascade(function(n){
			if(!n.attributes.isClass && n.ui.ctNode.offsetHeight < 3){
				n.ui.hide();
				this.hiddenPkgs.push(n);
			}
		});
		*/
	},
    selectClass : function(cls){
        if(cls){
            var parts = cls.split('.');
            var last = parts.length-1;
            var res = [];
            var pkg = [];
            for(var i = 0; i < last; i++){ // things get nasty - static classes can have .
                var p = parts[i];
                var fc = p.charAt(0);
                var staticCls = fc.toUpperCase() == fc;
                if(p == 'Ext' || !staticCls){
                    pkg.push(p);
                    res[i] = 'pkg-'+pkg.join('.');
                }else if(staticCls){
                    --last;
                    res.splice(i, 1);
                }
            }
            res[last] = cls;

            this.selectPath('/root/apidocs/'+res.join('/'));
        }
    }
});

DocPanel = Ext.extend(Ext.Panel, {
    closable: true,
    autoScroll: true,

    initComponent: function () {
        var ps = this.cclass.split('.');
        this.title = ps[ps.length - 1];
        // toolbar, short cuts
        Ext.apply(this, {
            tbar: ['->',
			{
			    text: 'Home',
			    handler: this.gohome,
			    scope: this,
			    iconCls: 'icon-event'
			}, '-',
			{
			    text: 'Print',
			    handler: this.printdoco,
			    scope: this,
			    iconCls: 'icon-event'
			}, '-',
            /*{
            text: 'Config Options',
            handler: this.scrollToMember.createDelegate(this, ['configs']),
            iconCls: 'icon-config'
            },'-',{
            text: 'Properties',
            handler: this.scrollToMember.createDelegate(this, ['props']),
            iconCls: 'icon-prop'
            }, '-',{
            text: 'Methods',
            handler: this.scrollToMember.createDelegate(this, ['methods']),
            iconCls: 'icon-method'
            }, '-',{
            text: 'Events',
            handler: this.scrollToMember.createDelegate(this, ['events']),
            iconCls: 'icon-event'
            }, '-',*/{
            text: 'Direct Link',
            handler: this.directLink,
            scope: this,
            iconCls: 'icon-fav'
        }/*, '-',{
                tooltip:'Hide Inherited Members',
                iconCls: 'icon-hide-inherited',
                enableToggle: true,
                scope: this,
                toggleHandler : function(b, pressed){
                     this.body[pressed ? 'addClass' : 'removeClass']('hide-inherited');
                }
            }, '-', {
                tooltip:'Expand All Members',
                iconCls: 'icon-expand-members',
                enableToggle: true,
                scope: this,
                toggleHandler : function(b, pressed){
                    this.body[pressed ? 'addClass' : 'removeClass']('full-details');
                }
            }*/]
    });
    DocPanel.superclass.initComponent.call(this);
},

directLink: function () {

    /*
    var link = String.format(
    "<a href=\"{0}\" target=\"_blank\">{0}</a>",
    document.location.href.split('?')[0] +'?class='+this.cclass
    );
    Ext.Msg.alert('Direct Link to ' + this.cclass,link);
    */


    var t = {};
    t.cclass = this.cclass;

    var c = Ext.urlEncode(t);
    var version = Ext.getCmp("cmbVersion").getValue();

    var link = String.format(
            "<a href=\"{0}\" target=\"_blank\">{0}</a>",
            document.location.href.split('?')[0] + '?class=' + c.split('=')[1] + "," + version
		);
    Ext.Msg.alert('Direct Link to ' + this.cclass, link);

},

printdoco: function () {
    //this only replace first space :(
    //var t = Ext.isIE ? this.cclass.replace(' ', '_') : this.cclass;
    //printw = window.open('/Text/' + this.cclass, t, 'width=600, height=800, scrollbars=1');
    var version = Ext.getCmp("cmbVersion").getValue();
    printw = window.open(root + 'Text/' + this.cclass + "," + version, '', 'width=600, height=800, scrollbars=1');
    if (printw) {
        printw.focus();

        //if (! Ext.isGecko )
        //w.print();
        setTimeout('printw.print()', 100);
    }
},

gohome: function () {

    //mainPanel.loadClass('Text/welcome', 'Help Home');
    mainPanel.setActiveTab(0);
},

scrollToMember: function (member) {
    var el = Ext.fly(this.cclass + '-' + member);
    if (el) {
        var top = (el.getOffsetsTo(this.body)[1]) + this.body.dom.scrollTop;
        this.body.scrollTo('top', top - 25, { duration: 0.75, callback: this.hlMember.createDelegate(this, [member]) });
    }
},

scrollToSection: function (id) {
    var el = Ext.getDom(id);
    if (el) {
        var top = (Ext.fly(el).getOffsetsTo(this.body)[1]) + this.body.dom.scrollTop;
        this.body.scrollTo('top', top - 25, { duration: 0.5, callback: function () {
            if (!Ext.isEmpty(Ext.fly(el).next('h2')))
                Ext.fly(el).next('h2').pause(0.2).highlight('#8DB2E3', { attr: 'color' });
        }
        });
    }
},

hlMember: function (member) {
    var el = Ext.fly(this.cclass + '-' + member);
    if (el) {
        if (tr = el.up('tr')) {
            tr.highlight('#cadaf9');
        }
    }
}
});

// get data for menu versions
//var versionConn = new Ext.data.Connection();
//var versionData;

//versionConn.request({
//    url: root + "Home/GetMenuVersion",
//    method: 'GET',
//    scope: this,

//    callback: function (options, success, response) {
//        if (success) {
//            data = Ext.decode(response.responseText);

//             display data from object
//            versionData = new Ext.data.JsonStore({
//                data: data,
//                root: '',
//                fields: [
//                    { name: 'Key' },
//                    { name: 'Name' }
//                ]
//            });
//        }
//    }
//});

var versionData = new Ext.data.Store({
    reader: new Ext.data.JsonReader({
        fields: ['Key', 'Name', 'DefaultVersion']
    }),
    proxy: new Ext.data.HttpProxy({
        url: root + 'Home/GetMenuVersion'
    }),
    autoLoad: false,
    sortInfo: { field: 'Name', direction: 'DESC' }
});

MainPanel = function () {

    this.searchStore = new Ext.data.Store({
        /*
        proxy: new Ext.data.ScriptTagProxy({
        //url: 'http://extjs.com/playpen/api.php'
        }),
        reader: new Ext.data.JsonReader({
        root: 'data'
        }, 
        ['cls', 'member', 'type', 'doc']
        ),
        */
        proxy: new Ext.data.HttpProxy({
            url: root + 'Home/JSONSearch'
        }),
        reader: new Ext.data.JsonReader({
            root: ''
        },
			['cls', 'member', 'type', 'doc', 'ver']
		),
        baseParams: {},
        listeners: {
            'beforeload': function () {
                this.baseParams.qt = Ext.getCmp('search-type').getValue();
                this.baseParams.ver = Ext.getCmp('cmbVersion').getValue();
            }
        }
    });

    MainPanel.superclass.constructor.call(this, {
        id: 'doc-body',
        region: 'center',
        margins: '0 5 5 0',
        resizeTabs: true,
        minTabWidth: 135,
        tabWidth: 135,
        plugins: new Ext.ux.TabCloseMenu(),
        enableTabScroll: true,
        activeTab: 0,
        items: {
            id: 'welcome-panel',
            title: 'Help Home',
            closable: false,
            //autoLoad: {url: 'welcome.html', callback: this.initSearch, scope: this},
            autoLoad: { url: root + 'Text/welcome', callback: this.initSearch, scope: this},
            iconCls: 'icon-docs',
            autoScroll: true,
            tbar: [
				'Search: ', ' ',
            /*				
            new Ext.ux.SelectBox({
            listClass:'x-combo-list-small',
            width:90,
            value:'Starts with',
            id:'search-type',
            store: new Ext.data.SimpleStore({
            fields: ['text'],
            expandData: true,
            data : ['Starts with', 'Ends with', 'Any match']
            }),
            displayField: 'text'
            }) , 
            */
                new Ext.ux.SelectBox({
                    listClass: 'x-combo-list-small',
                    width: 90,
                    value: 'Starts with',
                    id: 'search-type',
                    hidden: true,
                    store: new Ext.data.SimpleStore({
                        fields: ['text'],
                        expandData: true,
                        data: ['Starts with', 'Ends with', 'Any match']
                    }),
                    displayField: 'text'
                }),
                ' ',
                new Ext.app.SearchField({
                    width: 240,
                    store: this.searchStore,
                    paramName: 'id'
                })
            ]
        }
    });
};

Ext.extend(MainPanel, Ext.TabPanel, {

    initEvents: function () {
        MainPanel.superclass.initEvents.call(this);
        this.body.on('click', this.onClick, this);
    },

    onClick: function (e, target) {
        //alert('MainPanel.onClick');
        //alert(target.href);

        if (Ext.isEmpty(target.href) == false
			&& target.href.toLowerCase().indexOf('mailto:') != -1) {
            // web browser handles these events
            return;
        }

        //alert(0);

        if (target = e.getTarget('a:not(.exi)', 3)) {
            var cls = Ext.fly(target).getAttributeNS('ext', 'cls');
            e.stopEvent();
            if (cls) {
                //alert('loading a class');
                var member = Ext.fly(target).getAttributeNS('ext', 'member');
                this.loadClass(target.href, cls, member);
            } else if (target.className == 'load-class') {
                cls = target.href.substring(target.href.lastIndexOf('/') + 1, target.href.length);
                member = "";
                this.loadClass(target.href, cls, member);
            } else if (target.className == 'inner-link') {
                //alert('inner-link scroll');
                this.getActiveTab().scrollToSection(target.href.split('#')[1]);
            } else {
                // only open valid href - fixed by luor
                if (!Ext.isEmpty(target.href)) {
                    window.open(target.href);
                }
            }
        } else if (target = e.getTarget('.micon', 2)) {
            e.stopEvent();
            var tr = Ext.fly(target.parentNode);
            if (tr.hasClass('expandable')) {
                tr.toggleClass('expanded');
            }
        }
    },

    loadClass: function (href, cls, member) {
        //alert('MainPanel.loadClass');
        var id = 'docs-' + cls;
        var tab = this.getComponent(id);
        if (tab) {
            this.setActiveTab(tab);
            if (member) {
                tab.scrollToMember(member);
            }
        } else {
            //alert(href);
            var autoLoad = { url: href };
            if (member) {
                autoLoad.callback = function () {
                    Ext.getCmp(id).scrollToMember(member);
                }
            }
            var p = this.add(new DocPanel({
                id: id,
                cclass: cls,
                autoLoad: autoLoad,
                iconCls: Docs.icons[cls]
            }));
            this.setActiveTab(p);
        }
    },

    initSearch: function () {
        // Custom rendering Template for the View
        var resultTpl = new Ext.XTemplate(
	        '<tpl for=".">',
	        '<div class="search-item">',
	            '<a class="member" ext:cls="{cls}" ext:member="{member}" href="' + root + 'Text/{cls},{ver}">',
				'<img src="' + root + 'ext/docs/resources/images/default/s.gif" class="item-icon icon-{type}"/>{member}',
				'</a> ',
				'',
	            '<p>{doc}</p>',
	        '</div></tpl>'
	    );

        if (this.searchStore != undefined) {
            var p = new Ext.DataView({
                applyTo: 'search',
                tpl: resultTpl,
                loadingText: 'Searching...',
                store: this.searchStore,
                itemSelector: 'div.search-item',
                emptyText: '<h3>Use the search field above to search all help documents.</h3>'
            });
        };
    },

    doSearch: function (e) {
        var k = e.getKey();
        if (!e.isSpecialKey()) {
            var text = e.target.value;
            if (!text) {
                this.searchStore.baseParams.q = '';
                this.searchStore.removeAll();
            } else {
                this.searchStore.baseParams.q = text;
                this.searchStore.url = root + 'Home/JSONSearch/' + text;
                //alert(this.searchStore.url);
                this.searchStore.reload();
            }
        }
    }
});

OnLoadMenuSuccess = function () {

    Ext.QuickTips.init();

    var api = new ApiPanel();
    mainPanel = new MainPanel();

    api.on('click', function (node, e) {
        //alert('click');
        if (node.isLeaf()) {
            e.stopEvent();
            mainPanel.loadClass(node.attributes.href, node.id);
        } else {
            // we load parent category as well
            if (!Ext.isEmpty(node.attributes.href)) {
                e.stopEvent();
                mainPanel.loadClass(node.attributes.href, node.id);
            }
        }
    });

    mainPanel.on('tabchange', function (tp, tab) {
        api.selectClass(tab.cclass);
    });    

    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [
            {
                id: 'rs-header',
                cls: 'docs-header',
                height: 36, 
                region: 'north',
                xtype: 'box',
                el: 'header',
                border: false,
                margins: '0 0 5 0'
            },
            {
                region: 'west',
			    layout: 'ux.row',
			    split: true,
			    width: 280,
			    minSize: 175,
			    maxSize: 500,
			    collapsible: true,
			    margins: '0 0 5 5',
			    cmargins: '0 0 0 0',
			    rootVisible: false,
			    lines: false,
			    style: 'background-color:#D0DEF0;',
			    animCollapse: false,
			    animate: false,
			    collapseMode: 'mini', 
			    items: [
                    {
                        id: 'pnlVersion',
                        xtype: 'panel',
                        layout: 'form',
                        labelWidth: 50,
                        cls: 'version-cmb',
                        border: false,                        
                        items: [
                            {
                                xtype: 'combo',
                                width: 100,
                                fieldLabel: 'Version',
                                id: 'cmbVersion',
                                store: versionData,
                                valueField: 'Key',
                                displayField: 'Name',
                                mode: 'local',
                                triggerAction: 'all',
                                autoComplete: 'on',
                                //style: 'margin:3 3 3 3;',
                                //emptyText: '-- Version --',
                                listeners: {
                                    'select': function (combo, value) {
                                        LoadMenu(combo.value);
                                        var mainPanel = Ext.getCmp('doc-body');
                                        mainPanel.items.each(function (item) {
                                            if (item.closable) {
                                                mainPanel.remove(item);
                                            }
                                        });
                                    }
                                }
                            }
                        ]
				    }, api
                ]
			}, mainPanel
        ]
        //api, mainPanel]
    });   

    api.expandPath('/root/apidocs');

    Ext.EventManager.onWindowResize(function () {
        //Ext.getCmp('api-tree').setHeight(Ext.getBody().getViewSize().height - (Ext.getCmp('rs-header').getHeight() + Ext.getCmp('pnlVersion').getHeight()));
        Ext.getCmp('api-tree').setHeight(Ext.getBody().getViewSize().height - 70);
    });

    // allow for link in
    var page = window.location.href.split('?')[1];
    if (page) {
        var ps = Ext.urlDecode(page);
        var cls = ps['class'];
        mainPanel.loadClass(root + 'Text/' + cls, cls.split(',')[0], ps.member);
    }

    viewport.doLayout();

    setTimeout(function () {
        //Ext.get(document.body).unmask();
        Ext.get('loading').remove();
        Ext.get('loading-mask').fadeOut({ remove: true });
    }, 250);


    //alert(Ext.util.JSON.encode(location));
    //alert(location.hash);
    //alert(location.search);
    /*
    if (! Ext.isEmpty(location.hash))
    {
    var args = location.hash.split('#');
    if (! Ext.isEmpty(args[1]))
    {
    //alert(args[1]);
    mainPanel.loadClass('/Text/'+args[1], args[1], '');
    }
    }
    */


}


Ext.onReady(function(){
	LoadMenu();			
});


Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
    initComponent : function(){
        if(!this.store.baseParams){
			this.store.baseParams = {};
		}
		Ext.app.SearchField.superclass.initComponent.call(this);
		this.on('specialkey', function(f, e){
            if(e.getKey() == e.ENTER){
                this.onTrigger2Click();
            }
        }, this);
    },

    validationEvent:false,
    validateOnBlur:false,
    trigger1Class:'x-form-clear-trigger',
    trigger2Class:'x-form-search-trigger',
    hideTrigger1:true,
    width:180,
    hasSearch : false,
    paramName : 'query',

    onTrigger1Click : function(){
        if(this.hasSearch){
            this.store.baseParams[this.paramName] = '';
			this.store.removeAll();
			this.el.dom.value = '';
            this.triggers[0].hide();
            this.hasSearch = false;
			this.focus();
        }
    },

    onTrigger2Click : function(){
        var v = this.getRawValue();
        if(v.length < 1){
            this.onTrigger1Click();
            return;
        }
		if(v.length < 2){
			Ext.Msg.alert('Invalid Search', 'You must enter a minimum of 2 characters to search');
			return;
		}
		this.store.baseParams[this.paramName] = v;
        var o = {start: 0};
        this.store.reload({params:o});
        this.hasSearch = true;
        this.triggers[0].show();
		this.focus();
    }
});


/**
 * Makes a ComboBox more closely mimic an HTML SELECT.  Supports clicking and dragging
 * through the list, with item selection occurring when the mouse button is released.
 * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
 * on inner elements.  Re-enabling editable after calling this will NOT work.
 *
 * @author Corey Gilmore
 * http://extjs.com/forum/showthread.php?t=6392
 *
 * @history 2007-07-08 jvs
 * Slight mods for Ext 2.0
 */
Ext.ux.SelectBox = function(config){
	this.searchResetDelay = 1000;
	config = config || {};
	config = Ext.apply(config || {}, {
		editable: false,
		forceSelection: true,
		rowHeight: false,
		lastSearchTerm: false,
        triggerAction: 'all',
        mode: 'local'
    });

	Ext.ux.SelectBox.superclass.constructor.apply(this, arguments);

	this.lastSelectedIndex = this.selectedIndex || 0;
};

Ext.extend(Ext.ux.SelectBox, Ext.form.ComboBox, {
    lazyInit: false,
	initEvents : function(){
		Ext.ux.SelectBox.superclass.initEvents.apply(this, arguments);
		// you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
		this.el.on('keydown', this.keySearch, this, true);
		this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
	},

	keySearch : function(e, target, options) {
		var raw = e.getKey();
		var key = String.fromCharCode(raw);
		var startIndex = 0;

		if( !this.store.getCount() ) {
			return;
		}

		switch(raw) {
			case Ext.EventObject.HOME:
				e.stopEvent();
				this.selectFirst();
				return;

			case Ext.EventObject.END:
				e.stopEvent();
				this.selectLast();
				return;

			case Ext.EventObject.PAGEDOWN:
				this.selectNextPage();
				e.stopEvent();
				return;

			case Ext.EventObject.PAGEUP:
				this.selectPrevPage();
				e.stopEvent();
				return;
		}

		// skip special keys other than the shift key
		if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
			return;
		}
		if( this.lastSearchTerm == key ) {
			startIndex = this.lastSelectedIndex;
		}
		this.search(this.displayField, key, startIndex);
		this.cshTask.delay(this.searchResetDelay);
	},

	onRender : function(ct, position) {
		this.store.on('load', this.calcRowsPerPage, this);
		Ext.ux.SelectBox.superclass.onRender.apply(this, arguments);
		if( this.mode == 'local' ) {
			this.calcRowsPerPage();
		}
	},

	onSelect : function(record, index, skipCollapse){
		if(this.fireEvent('beforeselect', this, record, index) !== false){
			this.setValue(record.data[this.valueField || this.displayField]);
			if( !skipCollapse ) {
				this.collapse();
			}
			this.lastSelectedIndex = index + 1;
			this.fireEvent('select', this, record, index);
		}
	},

	render : function(ct) {
		Ext.ux.SelectBox.superclass.render.apply(this, arguments);
		if( Ext.isSafari ) {
			this.el.swallowEvent('mousedown', true);
		}
		this.el.unselectable();
		this.innerList.unselectable();
		this.trigger.unselectable();
		this.innerList.on('mouseup', function(e, target, options) {
			if( target.id && target.id == this.innerList.id ) {
				return;
			}
			this.onViewClick();
		}, this);

		this.innerList.on('mouseover', function(e, target, options) {
			if( target.id && target.id == this.innerList.id ) {
				return;
			}
			this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
			this.cshTask.delay(this.searchResetDelay);
		}, this);

		this.trigger.un('click', this.onTriggerClick, this);
		this.trigger.on('mousedown', function(e, target, options) {
			e.preventDefault();
			this.onTriggerClick();
		}, this);

		this.on('collapse', function(e, target, options) {
			Ext.getDoc().un('mouseup', this.collapseIf, this);
		}, this, true);

		this.on('expand', function(e, target, options) {
			Ext.getDoc().on('mouseup', this.collapseIf, this);
		}, this, true);
	},

	clearSearchHistory : function() {
		this.lastSelectedIndex = 0;
		this.lastSearchTerm = false;
	},

	selectFirst : function() {
		this.focusAndSelect(this.store.data.first());
	},

	selectLast : function() {
		this.focusAndSelect(this.store.data.last());
	},

	selectPrevPage : function() {
		if( !this.rowHeight ) {
			return;
		}
		var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
		this.focusAndSelect(this.store.getAt(index));
	},

	selectNextPage : function() {
		if( !this.rowHeight ) {
			return;
		}
		var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
		this.focusAndSelect(this.store.getAt(index));
	},

	search : function(field, value, startIndex) {
		field = field || this.displayField;
		this.lastSearchTerm = value;
		var index = this.store.find.apply(this.store, arguments);
		if( index !== -1 ) {
			this.focusAndSelect(index);
		}
	},

	focusAndSelect : function(record) {
		var index = typeof record === 'number' ? record : this.store.indexOf(record);
		this.select(index, this.isExpanded());
		this.onSelect(this.store.getAt(record), index, this.isExpanded());
	},

	calcRowsPerPage : function() {
		if( this.store.getCount() ) {
			this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
			this.rowsPerPage = this.maxHeight / this.rowHeight;
		} else {
			this.rowHeight = false;
		}
	}

});

Ext.Ajax.on('requestcomplete', function(ajax, xhr, o){
    if(typeof urchinTracker == 'function' && o && o.url){
        urchinTracker(o.url);
    }
});







