/**
 * Mapix CMS API
 * @author IRCF
 * @version 1.0.0
 */

// Instances
// TODO Remove this horrible global variable !
var mapix = null;

// Classes
var Mapix = Ext.extend(Ext.Viewport,{
	// Mapix view
	layout: 'border',
	initComponent: function(arguments){
		this.items = [
			this.header = new Mapix.Header(),
			this.explorer = new Mapix.Explorer(),
			this.editor = new Mapix.Editor()
		];
		this.superclass().initComponent.apply(this, arguments);
	},
	// Mapix model
	// TODO Debug
	// TODO Implement application detection depending on file type
	load: function(file,app){
		if (typeof file == 'undefined') file = '';
		if (typeof app == 'undefined') app = new Mapix.App.File();
		app.load({file:file});
	}
});

// Header panel
Mapix.Header = Ext.extend(Ext.Panel,{
	id: 'header',
	region: 'north',
	autoHeight: true,
	autoLoad: {
		url: 'header',
		callback: function(){
			mapix.doLayout()
		}
	},
	initComponent: function(arguments){
		this.superclass().initComponent.apply(this, arguments);
	}
});

// Explorer panel
Mapix.Explorer = Ext.extend(Ext.TabPanel,{
	id: 'explorer',
	xtype: 'tabpanel',
	region: 'west',
	width: '20%',
	split: true,
	collapsible: true,
	collapsed: true,
	initComponent: function(arguments){
		this.superclass().initComponent.apply(this, arguments);
	}
});

// Editor panel
Mapix.Editor = Ext.extend(Ext.TabPanel,{
	id: 'editor',
	xtype: 'tabpanel',
	region: 'center',
	initComponent: function(arguments){
		this.superclass().initComponent.apply(this, arguments);
	}
});

// Application model
Mapix.App = Ext.extend(Object,{
	constructor: function(){
	}
});

// Application manager
// TODO Implement as a singleton to manage apps (load/unload/...)
Mapix.AppMgr = Ext.extend(Object,{
	constructor: function(){
	}
});

// Initialization
Ext.onReady(function(){
	mapix = new Mapix();
	mapix.load();
});

/*
// Initialization
Ext.onReady(function(){
	new Ext.Viewport({
		id: 'viewport',
		layout: 'border',
		items: [{
			id: 'header',
			region: 'north',
			autoHeight: true,
			autoLoad: {
				url: 'header',
				callback: function(){Ext.getCmp('viewport').doLayout()}
			}
		},{
			id: 'explorer',
			xtype: 'tabpanel',
			region: 'west',
			width: '20%',
			split: true,
			collapsible: true,
			collapsed: true
		},{
			id: 'editor',
			xtype: 'tabpanel',
			region: 'center'
		}]
	});
	var files = new Mapix.App.File.Store();
	Ext.getCmp('editor').add(new Mapix.App.File.Icons({store:files})).show();
});
*/
