/*!
 * Ext JS Library 3.1.1
 * Copyright(c) 2006-2010 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */

// Sample desktop configuration
MyDesktop = new Ext.app.App({
	init :function(){
		Ext.QuickTips.init();
	},

	getModules : function(){
		return [
			// new MyDesktop.GridWindow(),
          //  new MyDesktop.TabWindow(),
          //  new MyDesktop.AccordionWindow(),
          //  new MyDesktop.BogusMenuModule(),
           // new MyDesktop.BogusModule()
		   new MyDesktop.AboutWindow(),
		   new MyDesktop.BlogWindow(),
   		   new MyDesktop.PicturesWindow(),
		   new MyDesktop.EmailWindow(),		   		   
		   new MyDesktop.LinksWindow()
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'Guest of the Jamesons',
            iconCls: 'user'
            /* toolItems: [{
                text:'Settings',
                iconCls:'settings',
                scope:this
            },'-',{
                text:'Logout',
                iconCls:'logout',
                scope:this
            }]*/
        };
    }
});



/*
 * Example windows
 */

var windowIndex = 0;


MyDesktop.EmailWindow = Ext.extend(Ext.app.Module, {
	id:'email-win',
    init : function(){
        this.launcher = {
            text: 'Send Us Email',
            iconCls:'email',
            handler : this.createWindow,
            scope: this
//            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
		var wid = 0;
		var stext = 'Send Us Email';
		if (src && src.windowId != undefined){
			wid = src.windowId;
			stext = src.text;
			}
//		alert(wid);
	    var win = desktop.getWindow('email'+wid);
		//alert('here!' + wid);
        if(!win){
		//alert('making window!');
            win = desktop.createWindow({
                id: 'email'+wid,
                title:stext,
                width:640,
                height:480,
                html : '<iframe src="mailme.phtml?HIDEBIGIMAGE=1" width=100% height=100%></iframe>',
                iconCls: 'email',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});

MyDesktop.PicturesWindow = Ext.extend(Ext.app.Module, {
	id:'pictures-win',
    init : function(){
        this.launcher = {
            text: 'Pictures',
            iconCls:'pictures',
            handler : this.createWindow,
            scope: this
//            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
		var wid = 0;
		var stext = 'Pictures';
		if (src && src.windowId != undefined){
			wid = src.windowId;
			stext = src.text;
			}
	//	alert(wid);
	    var win = desktop.getWindow('pictures'+wid);
		//alert('here!' + wid);
        if(!win){
		//alert('making window!');
            win = desktop.createWindow({
                id: 'pictures'+wid,
                title:stext,
                width:640,
                height:480,
                html : '<iframe src="pictures.phtml?HIDEBIGIMAGE=1" width=100% height=100%></iframe>',
                iconCls: 'pictures',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});
MyDesktop.BlogWindow = Ext.extend(Ext.app.Module, {
	id:'blog-win',
    init : function(){
        this.launcher = {
            text: 'Our Blog',
            iconCls:'blog',
            handler : this.createWindow,
            scope: this
//            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
		var wid = 0;
		var stext = 'Blog';
		if (src && src.windowId != undefined){
			wid = src.windowId;
			stext = src.text;
			}
		//alert(wid);
	    var win = desktop.getWindow('blog'+wid);
		//alert('here!' + wid);
        if(!win){
		//alert('making window!');
            win = desktop.createWindow({
                id: 'blog'+wid,
                title:stext,
                width:530,
                height:580,
                html : '<iframe src="http://himalayan.us/blog" width=100% height=100%></iframe>',
                iconCls: 'blog',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});

MyDesktop.AboutWindow = Ext.extend(Ext.app.Module, {
	id:'about-win',
    init : function(){
        this.launcher = {
            text: 'About',
            iconCls:'about',
            handler : this.createWindow,
            scope: this
//            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
		var wid = 0;
		var stext = 'About';
		if (src && src.windowId != undefined){
			wid = src.windowId;
			stext = src.text;
			}
		//alert(wid);
	    var win = desktop.getWindow('about'+wid);
		//alert('here!' + wid);
        if(!win){
		//alert('making window!');
            win = desktop.createWindow({
                id: 'about'+wid,
                title:stext,
                width:640,
                height:480,
                html : '<iframe src="aboutme.phtml?HIDEBIGIMAGE=1" width=100% height=100%></iframe>',
                iconCls: 'about',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});

MyDesktop.LinksWindow = Ext.extend(Ext.app.Module, {
	id:'links-win',
    init : function(){
        this.launcher = {
            text: 'Links',
            iconCls:'links',
            handler : this.createWindow,
            scope: this
//            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
		var wid = 0;
		var stext = 'Links';
		if (src && src.windowId != undefined){
			wid = src.windowId;
			stext = src.text;
			}
//		alert(wid);
	    var win = desktop.getWindow('links'+wid);
		//alert('here!' + wid);
        if(!win){
		//alert('making window!');
            win = desktop.createWindow({
                id: 'links'+wid,
                title:stext,
                width:640,
                height:480,
                html : '<iframe src="links.phtml?HIDEBIGIMAGE=1" width=100% height=100%></iframe>',
                iconCls: 'links',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});



MyDesktop.GridWindow = Ext.extend(Ext.app.Module, {
    id:'grid-win',
    init : function(){
        this.launcher = {
            text: 'Grid Window',
            iconCls:'icon-grid',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('grid-win');
        if(!win){
            win = desktop.createWindow({
                id: 'grid-win',
                title:'Grid Window',
                width:740,
                height:480,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.grid.GridPanel({
                        border:false,
                        ds: new Ext.data.Store({
                            reader: new Ext.data.ArrayReader({}, [
                               {name: 'company'},
                               {name: 'price', type: 'float'},
                               {name: 'change', type: 'float'},
                               {name: 'pctChange', type: 'float'}
                            ]),
                            data: Ext.grid.dummyData
                        }),
                        cm: new Ext.grid.ColumnModel([
                            new Ext.grid.RowNumberer(),
                            {header: "Company", width: 120, sortable: true, dataIndex: 'company'},
                            {header: "Price", width: 70, sortable: true, renderer: Ext.util.Format.usMoney, dataIndex: 'price'},
                            {header: "Change", width: 70, sortable: true, dataIndex: 'change'},
                            {header: "% Change", width: 70, sortable: true, dataIndex: 'pctChange'}
                        ]),

                        viewConfig: {
                            forceFit:true
                        },
                        //autoExpandColumn:'company',

                        tbar:[{
                            text:'Add Something',
                            tooltip:'Add a new row',
                            iconCls:'add'
                        }, '-', {
                            text:'Options',
                            tooltip:'Blah blah blah blaht',
                            iconCls:'option'
                        },'-',{
                            text:'Remove Something',
                            tooltip:'Remove the selected item',
                            iconCls:'remove'
                        }]
                    })
            });
        }
        win.show();
    }
});



MyDesktop.TabWindow = Ext.extend(Ext.app.Module, {
    id:'tab-win',
    init : function(){
        this.launcher = {
            text: 'Tab Window',
            iconCls:'tabs',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('tab-win');
        if(!win){
            win = desktop.createWindow({
                id: 'tab-win',
                title:'Tab Window',
                width:740,
                height:480,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,

                layout: 'fit',
                items:
                    new Ext.TabPanel({
                        activeTab:0,

                        items: [{
                            title: 'Tab Text 1',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 2',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 3',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        },{
                            title: 'Tab Text 4',
                            header:false,
                            html : '<p>Something useful would be in here.</p>',
                            border:false
                        }]
                    })
            });
        }
        win.show();
    }
});



MyDesktop.AccordionWindow = Ext.extend(Ext.app.Module, {
    id:'acc-win',
    init : function(){
        this.launcher = {
            text: 'Accordion Window',
            iconCls:'accordion',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('acc-win');
        if(!win){
            win = desktop.createWindow({
                id: 'acc-win',
                title: 'Accordion Window',
                width:250,
                height:400,
                iconCls: 'accordion',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                tbar:[{
                    tooltip:{title:'Rich Tooltips', text:'Let your users know what they can do!'},
                    iconCls:'connect'
                },'-',{
                    tooltip:'Add a new user',
                    iconCls:'user-add'
                },' ',{
                    tooltip:'Remove the selected user',
                    iconCls:'user-delete'
                }],

                layout:'accordion',
                border:false,
                layoutConfig: {
                    animate:false
                },

                items: [
                    new Ext.tree.TreePanel({
                        id:'im-tree',
                        title: 'Online Users',
                        loader: new Ext.tree.TreeLoader(),
                        rootVisible:false,
                        lines:false,
                        autoScroll:true,
                        tools:[{
                            id:'refresh',
                            on:{
                                click: function(){
                                    var tree = Ext.getCmp('im-tree');
                                    tree.body.mask('Loading', 'x-mask-loading');
                                    tree.root.reload();
                                    tree.root.collapse(true, false);
                                    setTimeout(function(){ // mimic a server call
                                        tree.body.unmask();
                                        tree.root.expand(true, true);
                                    }, 1000);
                                }
                            }
                        }],
                        root: new Ext.tree.AsyncTreeNode({
                            text:'Online',
                            children:[{
                                text:'Friends',
                                expanded:true,
                                children:[{
                                    text:'Jack',
                                    iconCls:'user',
                                    leaf:true
                                },{
                                    text:'Brian',
                                    iconCls:'user',
                                    leaf:true
                                }]
                            },{
                                text:'Family',
                                expanded:true,
                                children:[{
                                    text:'Kelly',
                                    iconCls:'user-girl',
                                    leaf:true
                                },{
                                    text:'Sara',
                                    iconCls:'user-girl',
                                    leaf:true
                                }]
                            }]
                        })
                    }), {
                        title: 'Settings',
                        html:'<p>Something useful would be in here.</p>',
                        autoScroll:true
                    },{
                        title: 'Even More Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    },{
                        title: 'My Stuff',
                        html : '<p>Something useful would be in here.</p>'
                    }
                ]
            });
        }
        win.show();
    }
});

// for example purposes


MyDesktop.BogusModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Window '+(++windowIndex),
            iconCls:'bogus',
            handler : this.createWindow,
            scope: this,
            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('bogus'+src.windowId);
        if(!win){
            win = desktop.createWindow({
                id: 'bogus'+src.windowId,
                title:src.text,
                width:640,
                height:480,
                html : '<p>Something useful would be in here.</p>',
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});


MyDesktop.BogusMenuModule = Ext.extend(MyDesktop.BogusModule, {
    init : function(){
        this.launcher = {
            text: 'Bogus Submenu',
            iconCls: 'bogus',
            handler: function() {
				return false;
			},
            menu: {
                items:[{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                    },{
                    text: 'Bogus Window '+(++windowIndex),
                    iconCls:'bogus',
                    handler : this.createWindow,
                    scope: this,
                    windowId: windowIndex
                }]
            }
        }
    }
});


// Array data for the grid
Ext.grid.dummyData = [
    ['VeraciTek',1,2,3,'9/1 12:00am'],
    ['VeraciTek',1,2,3,'9/1 12:00am']
];
