MyDesktop.Web150 = Ext.extend(Ext.app.Module, {

	appType : 'documentation',
	id : 'web150-win',

	// Link/Button actions
	actions : null,
	// Content panel
	cPanel : null,
	// Current component loaded into the content panel
	cComp : null,

    init : function(){
        this.launcher = {
        	menuText: 'WEB150 Docs',
            text: 'WEB150 Docs',
            iconCls: 'book',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
    	var desktop = this.app.getDesktop();
        var win = desktop.getWindow('web150-win');

        if(!win){
        	var winWidth = desktop.getWinWidth() / 1.1;
			var winHeight = desktop.getWinHeight() / 1.1;

			var west = new Ext.Panel({
				border: false,
				collapsible: true,
				collapseMode: 'mini',
				html: '<ul id="pref-nav-panel"> \
<li> \
    <b>Getting Started</b> \
</li> \
<li> \
    <img src="resources/images/icons/fam/report.png"/> \
    <a id="Syllabus" href="#">Syllabus</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/calendar.png"/> \
    <a id="Schedule" href="#">Schedule</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/calendar.png"/> \
    <a id="Calendar_Eivy" href="#">Calendar</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="AssignmentTemplate" target="_blank" href="/source/modules/web150/downloads/AssignmentsPage.zip">Assignment Page</a> \
</li> \
<li> \
    <br /><b>Lecture Notes</b> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_01" href="#">Lecture 1: History</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_02" href="#">Lecture 2: Intro A</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_03" href="#">Lecture 3: Intro B</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_04" href="#">Lecture 4: Debugging</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_05" href="#">Lecture 5: Events</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_06" href="#">Lecture 6: Forms</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_07" href="#">Lecture 7: DOM</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_08" href="#">Lecture 8: Menu</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_09" href="#">Lecture 9: Unobtrusive</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="lecture_10" href="#">Lecture 10: Libraries</a> \
</li> \
<li> \
    <br /><b>Assignments</b> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_01" href="#">Week 1: Project Page</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_02" href="#">Week 2: Write 1-10</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_03" href="#">Week 3: Functions</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_04" href="#">Week 4: Debugging</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_05" href="#">Week 5: Events</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_06" href="#">Week 6: Form Validation</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_07" href="#">Week 7: Gallery</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_08" href="#">Week 8: Menu</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_09" href="#">Week 9: Unobtrusive</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page.png"/> \
    <a id="assignment_10" href="#">Final Project</a> \
</li> \
<li> \
    <br /><b>Extra Resources</b> \
</li> \
<li> \
    <img src="resources/images/icons/fam/xhtml_valid.png"/> \
    <a id="templates_html" href="#">HTML Template</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/information.png" /> \
    <a id="Introduction" href="#">Introduction</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/vcard.png" /> \
    <a id="ValuesVariables" href="#">Values & Variables</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/emoticon_tongue.png" /> \
    <a id="Expressions" href="#">Expressions</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/controller.png"/> \
    <a id="ControlStatements" href="#">Control Statements</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/control_repeat_blue.png" /> \
    <a id="Functions" href="#">Functions</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/asterisk_orange.png" /> \
    <a id="Arrays" href="#">Arrays</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/brick.png" /> \
    <a id="Objects" href="#">Objects</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/bug.png"/> \
    <a id="Debugging" href="#">Debugging</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/arrow_branch.png" /> \
    <a id="EventHandlers" href="#">Event Handlers</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/layers.png" /> \
    <a id="Rollovers" href="#">Rollovers</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/text_dropcaps.png" /> \
    <a id="Strings" href="#">Strings</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/application_form.png" /> \
    <a id="Forms" href="#">Forms</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/application_cascade.png" /> \
    <a id="BOM" href="#">Windows & BOM</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/page_code.png" /> \
    <a id="Cookies" href="#">Cookies</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/application_tile_vertical.png" /> \
    <a id="DOM" href="#">DOM</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/application_view_columns.png" /> \
    <a id="DOMScripting" href="#">DOM Scripting</a> \
</li> \
<li> \
    <img src="resources/images/icons/fam/database_table.png" /> \
    <a id="AJAX" href="#">AJAX</a> \
</li> \
</ul>',
				id: 'web150-nav',
				region: 'west',
				split: true,
				width: 180
			});

			this.cPanel = new Ext.Panel({
				autoScroll: true,
				border: false,
				id: 'web150-content',
				layout: 'fit',
				region: 'center'
			});

            win = desktop.createWindow({
                animCollapse: false,
                constrainHeader: true,
                id: 'web150-win',
                height: winHeight,
                iconCls: 'bogus',
                items: [
                	west,
                	this.cPanel
                ],
                layout: 'border',
                shim: false,
                title: 'WEB150 Docs',
                width: winWidth
            });

            this.initActions();
            this.doAction(null,{id:'Syllabus'});

	        // listeners
	        var w = west.body;
			w.on('mousedown', this.doAction, this, {delegate:'a'});
			w.on('click', Ext.emptyFn, null, {delegate:'a', preventDefault:true});
        }

        win.show();
    },
    runWindow : function(id){
    	if(id){
            var m = this.getModule(id);
            if(m){
                m.createWindow();
            }
		}
    },
    formatExternalLinks : function(el) {
        var links = el.down('a');
        for(var link in links){
            var mywin = new MyDesktop.WebWindow({
                id:'forum-win',
                url:'http://min3.net/forum/index.php',
                name:'Forum',
                iconCls:'forum',
                width:740,
                height:480
            });
            links[link].on('click',this,this.runWindow,{id:mywin});
        }
        for(var i = 0; i < links.length; i++) {
            if(links[i].href.indexOf(hostName) == -1) {
                var curTitle = (links[i].getAttribute("title")) ? links[i].getAttribute("title") + " - ": "";
                links[i].setAttribute("target", "_blank");
                links[i].setAttribute("title",  curTitle + "opens in new window");
            }
        }
    },
    initActions : function(){
		this.actions = {/*
	    	'Calendar_Andrus' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Calendar_Andrus.html'});
	    	},*/
	    	'Calendar_Eivy' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Calendar_Eivy.html'});
	    	},
	    	'templates_html' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/templates_html.html'});
	    	},
	    	'Syllabus' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Syllabus.html'});
	    	},
	    	'Schedule' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Schedule.html'});
	    	},
	    	'AJAX' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/AJAX.html'});
	    	},
            'Arrays' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Arrays.html'});
	    	},
            'BOM' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/BOM.html'});
	    	},
            'ControlStatements' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/ControlStatements.html'});
	    	},
            'Cookies' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Cookies.html'});
	    	},
            'Debugging' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Debugging.html'});
	    	},
            'DOM' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/DOM.html'});
	    	},
            'DOMScripting' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/DOMScripting.html'});
	    	},
            'EventHandlers' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/EventHandlers.html'});
	    	},
            'Expressions' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Expressions.html'});
	    	},
            'Forms' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Forms.html'});
	    	},
            'Functions' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Functions.html'});
	    	},
            'Introduction' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Introduction.html'});
                //this.formatExternalLinks(app.cPanel);
            },
            'Objects' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Objects.html'});
	    	},
            'Resources' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Resources.html'});
	    	},
            'Rollovers' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Rollovers.html'});
	    	},
            'Strings' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/Strings.html'});
	    	},
            'ValuesVariables' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/ValuesVariables.html'});
	    	},
            'lecture_01' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_01.html'});
	    	},
            'lecture_02' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_02.html'});
	    	},
            'lecture_03' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_03.html'});
	    	},
            'lecture_04' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_04.html'});
	    	},
            'lecture_05' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_05.html'});
	    	},
            'lecture_06' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_06.html'});
	    	},
            'lecture_07' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_07.html'});
	    	},
            'lecture_08' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_08.html'});
	    	},
            'lecture_09' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_09.html'});
	    	},
            'lecture_10' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_10.html'});
	    	},
            'lecture_11' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/lecture_11.html'});
	    	},
            'assignment_01' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_01.html'});
	    	},
            'assignment_02' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_02.html'});
	    	},
            'assignment_03' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_03.html'});
	    	},
            'assignment_04' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_04.html'});
	    	},
            'assignment_05' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_05.html'});
	    	},
            'assignment_06' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_06.html'});
	    	},
            'assignment_07' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_07.html'});
	    	},
            'assignment_08' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_08.html'});
	    	},
            'assignment_09' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_09.html'});
	    	},
            'assignment_10' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_10.html'});
	    	},
            'assignment_11' : function(app){
	    		app.cPanel.load({url: 'source/modules/web150/html/assignment_11.html'});
	    	}
	    }
    },

	doAction : function(e, t){
    	if(e)   e.stopEvent();
    	this.actions[t.id](this);  // pass this app for scope
    }
});