/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

var toArrayFromGeneric = function(iterable) {
    if (!iterable) return [];
    var length = iterable.length || 0, results = new Array(length);
    while (length--) results[length] = iterable[length];
	return results;
};
Function.prototype.bind = function() {
	if (arguments.length < 2 && (typeof arguments[0] == "undefined")) return this;
	var __method = this, args = toArrayFromGeneric(arguments), argsb = toArrayFromGeneric(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat(argsb));
	}
};


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

	getModules : function(){
		return [
			new MyDesktop.HomeWindow(),
			new MyDesktop.eventwindow(),
			new MyDesktop.VillageWindow(),
			new MyDesktop.GridWindow(),
            new MyDesktop.NewsWindow(),
            new MyDesktop.TabWindow(),
            new MyDesktop.AccordionWindow(),
			new MyDesktop.ForumWindow(),
			new MyDesktop.BogusMenuModule(),
            new MyDesktop.BogusModule(),
			new MyDesktop.TellFriendWindow(),
			new MyDesktop.NewsletterWindow(),
            new MyDesktop.ContactWindow(),
			new MyDesktop.WaterWindow(),
			new MyDesktop.adsWindow()
		];
	},

    // config for the start menu
    getStartConfig : function(){
        return {
            title: 'Go Green Daytona!',
            iconCls: 'user',
            toolItems: [{}]
        };
    }
});



/*
 * Example windows
 */
 
MyDesktop.HomeWindow = Ext.extend(Ext.app.Module, {
    id:'home-win',
    init : function(){
        this.launcher = {
            text: 'Home',
            iconCls:'icon-home',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
		var resizeThisWin = function () {
			var el = Ext.getBody();
			var desktop = this.app.getDesktop();

			var win_height = el.dom.clientHeight-170;
			if (win_height > 585) {
				win_height = 585;	
			}
			if (!desktop.getWindow(this.id))
				return win_height;
			else
				desktop.getWindow(this.id).setSize({height: win_height});
		}
		var win_height = resizeThisWin.apply(this);
		Ext.EventManager.onWindowResize(resizeThisWin, this);
		var desktop = this.app.getDesktop();
        var win = desktop.getWindow('home-win');
        if(!win){
            win = desktop.createWindow({
                id: 'home-win',
                title:'Welcome',
                width:640,
				pageX: 10,
				pageY: 10,
                height:win_height,
                iconCls: 'icon-home',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                autoLoad: 'home.html?a='+Math.random(),
				autoScroll: true
            });
        }
        win.show();
    }
});


MyDesktop.adsWindow = Ext.extend(Ext.app.Module, {
    id:'home-ads',
    init : function(){
        this.launcher = {
            text: 'Sponsors',
            iconCls:'icon-sponsor',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
		var resizeThisWin = function () {
			var el = Ext.getBody();
			var desktop = this.app.getDesktop();

			var win_width = el.dom.clientWidth-10;
			if (win_width < 10) win_width = document.body.offsetWidth - 10;
			var win_height = el.dom.clientHeight-40;
			if (!desktop.getWindow(this.id))
				return win_height;
			else {
				var win = desktop.getWindow(this.id);
				win.setSize({height: win_height});
				win.setPagePosition(win_width-win.getSize().width, win.getPosition()[1]);
			}
		}
		var win_height = resizeThisWin.apply(this);
		Ext.EventManager.onWindowResize(resizeThisWin, this);
        var desktop2 = this.app.getDesktop();
        var win2 = desktop2.getWindow('home-ads');
        if(!win2){
            win2 = desktop2.createWindow({
                id: 'home-ads',
                title:'Sponsors',
                width:340,
				pageX: (document.body.offsetWidth - 350),
				pageY: 10,
                height: win_height,
                iconCls: 'icon-sponsor',
                closable : false,
				shim:false,
				resizable: false,
				onEsc: Ext.emptyFn,
				draggable: false,
                animCollapse:false,
                constrainHeader:true,
				collapsible:false,
				maximizable:false,
				minimizable:false,
                //autoLoad: 'ads.php?a='+Math.random(),
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc: 'ads.php'
													 })
            });
        }
        win2.show();
    }
});
 

MyDesktop.eventwindow = Ext.extend(Ext.app.Module, {
    id:'event-win',
    init : function(){
        this.launcher = {
            text: 'Local Events',
            iconCls:'icon-cal',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
		var resizeThisWin = function () {
			var el = Ext.getBody();
			var desktop = this.app.getDesktop();

			var win_height = el.dom.clientHeight-170;
			if (win_height > 500) {
				win_height = 500;	
			}
			if (!desktop.getWindow(this.id))
				return win_height;
		}
		var win_height = resizeThisWin.apply(this);
		var desktop = this.app.getDesktop();
        var win = desktop.getWindow('event-win');
        if(!win){
            win = desktop.createWindow({
                id: 'event-win',
                title:'Local Events',
                width:680,
				height:500,
				pageX: 30,
				pageY: 30,
                height:win_height,
                iconCls: 'icon-cal',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                autoLoad: 'events.php?a='+Math.random(),
				autoScroll: true
            });
        }
        win.show();
    }
}); 


 
MyDesktop.GridWindow = Ext.extend(Ext.app.Module, {
    id:'grid-win',
    init : function(){
        this.launcher = {
            text: 'About Us',
            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:'About Go Green Daytona',
                width:540,
                height:400,
                iconCls: 'icon-grid',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                autoLoad: 'aboutus.html?a='+Math.random(),
				autoScroll: true
            });
        }
        win.show();
    }
});

MyDesktop.NewsWindow = Ext.extend(Ext.app.Module, {
    id:'news-win',
    init : function(){
        this.launcher = {
            text: 'Green News',
            iconCls:'icon-news',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('news-win');
        if(!win){
            win = desktop.createWindow({
                id: 'grid-win',
                title:'Go Green News',
                width:640,
                height:500,
                iconCls: 'icon-news',
                shim:false,
                animCollapse:false,
                constrainHeader:true,

                layout: 'fit',
                autoLoad: 'news.php?a=b',
				autoScroll: true
            });
        }
        win.show();
    }
});




MyDesktop.TabWindow = Ext.extend(Ext.app.Module, {
    id:'tab-win',
    init : function(){
        this.launcher = {
            text: 'Green Links',
            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:'Green Links',
                width:640,
                height:640,
                iconCls: 'tabs',
                shim:false,
                animCollapse:false,
                border:false,
                constrainHeader:true,

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

                        items: [{
                            title: 'Daytona',
                            header:false,
							autoLoad: {url: "links_daytona.html?a="+Math.random()},
                            //html : '<p>Links to local Daytona Beach websites</p>',
                            border:false
                        },{
                            title: 'Florida',
                            header:false,
							autoLoad: {url: "links_florida.html?a="+Math.random()},
                            
                            border:false
                        },{
                            title: 'USA',
                            header:false,
                            autoLoad: {url: "links_usa.html?a="+Math.random()},
                            border:false
                        }]
                    })
            });
        }
        win.show();
    }
});





MyDesktop.ChatWindow = Ext.extend(Ext.app.Module, {
    id:'chat-win',
    init : function(){
        this.launcher = {
            text: 'Green Chat',
            iconCls:'chat',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('chat-win');
        if(!win){
            win = desktop.createWindow({
                id: 'chat-win',
                title: 'Green Chat',
                width:550,
                height:400,
                iconCls: 'chat',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc: 'chat.php'
													 })

            });
        }
        win.show();
    }
});











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

    createWindow : function(changesrc){
        var desktop = this.app.getDesktop();
		var useid = ((typeof changesrc.text == "undefined") && changesrc.id) || 'acc-win'
        var win = desktop.getWindow(useid);
        if(!win){
            win = desktop.createWindow({
                id: useid,
                title: ((typeof changesrc.text == "undefined") && changesrc.title) || 'Green Forum',
                width:770,
                height:450,
                iconCls: 'accordion',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc: ((typeof changesrc.text == "undefined") && changesrc.href) || 'forum/'
													 })

            });
        }
        win.show();
    }
});














MyDesktop.WaterWindow = Ext.extend(Ext.app.Module, {
    id:'water-win',
    init : function(){
        this.launcher = {
            text: 'The cost of Bottled Water',
            iconCls:'icon-water',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('water-win');
        if(!win){
            win = desktop.createWindow({
                id: 'water-win',
                title: 'Bottled Water',
                width:700,
                height:500,
                iconCls: 'icon-water',

                layout: 'fit',
                autoLoad: 'bottled_water.html?a='+Math.random(),
				autoScroll: true
            });
        }
        win.show();
    }
});

MyDesktop.AccordionWindow = Ext.extend(Ext.app.Module, {
    id:'calc-win',
    init : function(){
        this.launcher = {
            text: 'Green Calculators',
            iconCls:'calc',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('calc-win');
        if(!win){
            win = desktop.createWindow({
                id: 'calc-win',
                title: 'Green Calculators',
                width:600,
                height:300,
                iconCls: 'calc',

                layout: 'fit',
                autoLoad: 'calculators.html?a='+Math.random(),
				autoScroll: true
            });
        }
        win.show();
    }
});





MyDesktop.ContactWindow = Ext.extend(Ext.app.Module, {
    id:'contact-win',
    init : function(){
        this.launcher = {
            text: 'Contact Us',
            iconCls:'bogus2',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('contact-win');
        if(!win){
            win = desktop.createWindow({
                id: 'contact-win',
                title:'Contact Go Green Daytona Beach',
                width:440,
                height:268,
                iconCls: 'bogus2',
                shim:false,
				plain:true,
                animCollapse:false,
                constrainHeader:true,
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc:'contactus.php?a='+Math.random()
													 })
            });
        }
        win.show();
    }
});




MyDesktop.TellFriendWindow = Ext.extend(Ext.app.Module, {
    id:'tellfriend-win',
    init : function(){
        this.launcher = {
            text: 'Tell a Friend',
            iconCls:'bogus2',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('tellfriend-win');
        if(!win){
            win = desktop.createWindow({
                id: 'tellfriend-win',
                title:'Tell a Friend',
                width:390,
                height:254,
                iconCls: 'bogus2',
                shim:false,
				plain:true,
                animCollapse:false,
                constrainHeader:true,
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc:'tell_friend.php?a='+Math.random()
													 })
            });
        }
        win.show();
    }
});

MyDesktop.VillageWindow = Ext.extend(Ext.app.Module, {
    id:'Village-win',
    init : function(){
        this.launcher = {
            text: 'Village Green',
            iconCls:'bogus2',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('Village-win');
        if(!win){
            win = desktop.createWindow({
                id: 'Village-win',
                title:'Village Green Newsletters',
                width:390,
                height:254,
                iconCls: 'bogus2',
                shim:false,
				plain:true,
                animCollapse:false,
                constrainHeader:true,
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc:'newsletter_archives.php?a='+Math.random()
													 })
            });
        }
        win.show();
    }
});


MyDesktop.NewsletterWindow = Ext.extend(Ext.app.Module, {
    id:'newsletter-win',
    init : function(){
        this.launcher = {
            text: 'Newsletter Signup',
            iconCls:'bogus2',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('newsletter-win');
        if(!win){
            win = desktop.createWindow({
                id: 'newsletter-win',
                title:'Newsletter',
                width:390,
                height:254,
                iconCls: 'bogus2',
                shim:false,
				plain:true,
                animCollapse:false,
                constrainHeader:true,
				defaultType:"iframepanel",

                layout: 'fit',
                //autoLoad: 'contactus.html?a='+Math.random(),
				autoScroll: true,
				items: new Ext.ux.ManagedIframePanel({
													 border: false,
													 bodyBorder: false,
													 defaultSrc:'newsletter.php?a='+Math.random()
													 })
            });
        }
        win.show();
    }
});



MyDesktop.BogusModule = Ext.extend(Ext.app.Module, {
	init: function() {
	},
    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,
                iconCls: 'bogus',
				autoLoad: src.autoLoad,
				autoScroll: true,
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});


MyDesktop.BogusMenuModule = Ext.extend(MyDesktop.BogusModule, {
    init : function(){
        this.launcher = {
            text: 'How to Go Green',
            iconCls: 'bogus',
            handler: function() { return false; },
            menu: {
                items:[{
                    text: 'Basics',
                    iconCls:'bogus',
                    handler : this.createWindow,
                    autoLoad: 'basics.html?a='+Math.random(),
					scope: this,
                    windowId: 1
                    },{
                    text: 'Investing',
                    iconCls:'bogus',
                    handler : this.createWindow,
                    autoLoad: 'investing.html?a='+Math.random(),
					width:640,
                    height:440,
					scope: this,
                    windowId: 2
                    },{
                    text: 'Household',
                    iconCls:'bogus',
                    handler : this.createWindow,
                    autoLoad: 'household.html?a='+Math.random(),
					scope: this,
                    windowId: 3
                    },{
                    text: 'Automotive',
                    iconCls:'bogus',
                    handler : this.createWindow,
                    autoLoad: 'automotive.html?a='+Math.random(),
					scope: this,
                    windowId: 4
                    },{
                    text: 'At Work',
                    iconCls:'bogus',
                    handler : this.createWindow,
                    autoLoad: 'work.html?a='+Math.random(),
					scope: this,
                    windowId: 5
                }]
            }
        }
    }
});


// Array data for the grid
Ext.grid.dummyData = [
    ['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
    ['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
    ['American Express Company',52.55,0.01,0.02,'9/1 12:00am'],
    ['American International Group, Inc.',64.13,0.31,0.49,'9/1 12:00am'],
    ['AT&T Inc.',31.61,-0.48,-1.54,'9/1 12:00am'],
    ['Caterpillar Inc.',67.27,0.92,1.39,'9/1 12:00am'],
    ['Citigroup, Inc.',49.37,0.02,0.04,'9/1 12:00am'],
    ['Exxon Mobil Corp',68.1,-0.43,-0.64,'9/1 12:00am'],
    ['General Electric Company',34.14,-0.08,-0.23,'9/1 12:00am'],
    ['General Motors Corporation',30.27,1.09,3.74,'9/1 12:00am'],
    ['Hewlett-Packard Co.',36.53,-0.03,-0.08,'9/1 12:00am'],
    ['Honeywell Intl Inc',38.77,0.05,0.13,'9/1 12:00am'],
    ['Intel Corporation',19.88,0.31,1.58,'9/1 12:00am'],
    ['Johnson & Johnson',64.72,0.06,0.09,'9/1 12:00am'],
    ['Merck & Co., Inc.',40.96,0.41,1.01,'9/1 12:00am'],
    ['Microsoft Corporation',25.84,0.14,0.54,'9/1 12:00am'],
    ['The Coca-Cola Company',45.07,0.26,0.58,'9/1 12:00am'],
    ['The Procter & Gamble Company',61.91,0.01,0.02,'9/1 12:00am'],
    ['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am'],
    ['Walt Disney Company (The) (Holding Company)',29.89,0.24,0.81,'9/1 12:00am']
];