ExplorerView = function() {
    ExplorerView.superclass.constructor.call(this, {
           id:'main-tabs',
           activeTab:0,
           region:'center',
           margins:'0 5 5 0',
           resizeTabs:true,
           tabWidth:150,
           minTabWidth: 120,
           enableTabScroll: true,
           plugins: new Ext.ux.TabCloseMenu(),
           items: [{
               id:'main-view',
               layout:'border',
               title:'Overview',
               hideMode:'offsets',
               items: [{
                  id:'item-preview',
                  region: 'center',
                  layout:'fit',
                  border:false,
                  autoScroll:true,
                  autoLoad: 'overview.htm'
                 }]
               }]
         });
}

Ext.extend(ExplorerView, Ext.TabPanel, {
    openTab : function(term, version) {
        var id = !term ? Ext.id() : term
        id = id.replace(/ /g, '-');	// More normal ID

        var tab;
        if(!(tab = this.getItem(id))) {
            tab = new Ext.Panel({
               id: id,
               cls:'preview single-preview',
               title: term,
               tabTip: term,
               layout: 'anchor',
               closable: true,
               defaults: {bodyStyle: 'padding:15px'},
               listeners: ExplorerApp.LinkInterceptor,
               autoScroll:true,
               border:true,
               term: term,
               version: version
            });

            tab.on('activate', this.loadInfo, tab);
            this.add(tab);

        }
        this.setActiveTab(tab);
    },

    loadInfo : function() {
       this.load({
            url: "http://www.spase-group.org/service/search",
            params: {style: "card", term: this.term, version: this.version}, // or a URL encoded string
            discardUrl: false,
            nocache: false,
            timeout: 30,
            scripts: false
         });
    },
    
    openInfoTab : function(tabTitle, infoUrl, version) {
        var id = !tabTitle ? Ext.id() : tabTitle
        id = id.replace(/ /g, '-');	// More normal ID

        var tab;
        if(!(tab = this.getItem(id))) {
            tab = new Ext.Panel({
               id: id,
               cls:'preview single-preview',
               title: tabTitle,
               tabTip: tabTitle,
               layout: 'anchor',
               closable: true,
               defaults: {bodyStyle: 'padding:15px'},
               listeners: ExplorerApp.LinkInterceptor,
               autoScroll:true,
               border:true,
               infoUrl: infoUrl,
               version: version
            });

            tab.on('activate', this.loadFromUrl, tab);
            this.add(tab);

        }
        this.setActiveTab(tab);
    },

    loadFromUrl : function() {
       this.load({
            url: this.infoUrl,
            params: {version: this.version}, // or a URL encoded string
            discardUrl: false,
            nocache: false,
            timeout: 30,
            scripts: false
         });
    }
});
