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

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

	getModules : function(){
		return [
			new MyDesktop.NewsWindow(),
			new MyDesktop.BioWindow(),
			new MyDesktop.PicturesWindow(),
            new MyDesktop.DiscoWindow(),
			new MyDesktop.ContactWindow(),
			new MyDesktop.LastfmWindow(),
			new MyDesktop.TwitterWindow(),
			new MyDesktop.YoutubeWindow(),
			new MyDesktop.PlayerWindow()
		];
	}
});


MyDesktop.NewsWindow = Ext.extend(Ext.app.Module, {
	id:'news',
    init : function(){
        this.launcher = {
            text: '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: 'news-win',
                title:'News',
                width:760,
                height:500,
                iconCls: 'icon-news',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				autoScroll:true
            });
        }
        win.show();
		updater = win.getUpdater();
		updater.loadScripts = true;
		updater.update({
			url: "/news/?layout=ext"
		});
    }
});

MyDesktop.BioWindow = Ext.extend(Ext.app.Module, {
	id:'biography',
    init : function(){
        this.launcher = {
            text: 'Biography',
            iconCls:'icon-biography',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('bio-win');
        if(!win){
            win = desktop.createWindow({
                id: 'bio-win',
                title:'Biography',
                width:550,
                height:400,
                iconCls: 'icon-biography',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				autoScroll:true
            });
        }
        win.show();
		updater = win.getUpdater();
		updater.update({
			url: "/biography/?layout=ext"
		});
    }
});

MyDesktop.DiscoWindow = Ext.extend(Ext.app.Module, {
    id:'disco',
    init : function(){
        this.launcher = {
            text: 'Tab Window',
            iconCls:'icon-disco',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('disco-win');
		//var sm = new Ext.grid.RowSelectionModel();
		
        if(!win){
            win = desktop.createWindow({
                id: 'disco-win',
                title:'Discography',
                width:500,
                height:300,
                iconCls: 'icon-disco',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				autoHeight:false,
				autoScroll:false,
				maximizable:false,
				resizable:false,
                layout: 'fit'
            });
        }
        win.show();
		updater = win.getUpdater();
		updater.loadScripts = true;
		updater.update({
			url: "/discography/?layout=ext"
		});
    }
});


MyDesktop.ContactWindow = Ext.extend(Ext.app.Module, {
	id:'contact',
    init : function(){
        this.launcher = {
            text: 'Contact',
            iconCls:'icon-contact',
            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',
                width:430,
                height:300,
                iconCls: 'icon-contact',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				autoScroll:false,
				maximizable:false,
				resizable:false
            });
        }
        win.show();
		updater = win.getUpdater();
		updater.update({
			url: "/contact/?layout=ext"
		});
    }
});

MyDesktop.LastfmWindow = Ext.extend(Ext.app.Module, {
	id:'lastfm',
    init : function(){
        this.launcher = {
            text: 'Last.fm',
            iconCls:'icon-lastfm',
            handler : this.createWindow,
            scope: this
        }
    },
	createWindow : function(){
        lastfm("/lastfm/index/?layout=ext")
    }
});

MyDesktop.PlayerWindow = Ext.extend(Ext.app.Module, {
	id:'player',
    init : function(){
        this.launcher = {
            text: 'Music Player',
            iconCls:'icon-disco',
            handler : this.createWindow,
            scope: this
        }
    },
	createWindow : function(){
        lastfm("/player/index/?layout=ext")
    }
});

MyDesktop.YoutubeWindow = Ext.extend(Ext.app.Module, {
	id:'youtube',
    init : function(){
        this.launcher = {
            text: 'Youtube',
            iconCls:'icon-youtube',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('youtube-win');
        if(!win){
            win = desktop.createWindow({
                id: 'youtube-win',
                title:'Youtube',
                width:1040,
                height:600,
                iconCls: 'icon-youtube',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				autoScroll:false,
				resizable:true,
				maximizable:true
            });
        }
		win.show();
		updater = win.getUpdater();
		updater.update({
			url: "/youtube/index/?layout=ext"
		});
    }
});

MyDesktop.TwitterWindow = Ext.extend(Ext.app.Module, {
	id:'twitter',
    init : function(){
        this.launcher = {
            text: 'Twitter',
            iconCls:'icon-twitter',
            handler : this.createWindow,
            scope: this
        }
    },

    createWindow : function(){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('twitter-win');
        if(!win){
            win = desktop.createWindow({
                id: 'twitter-win',
                title:'Twitter',
                width:500,
                height:400,
                iconCls: 'icon-twitter',
                shim:false,
                animCollapse:false,
                constrainHeader:true,
				autoScroll:true,
				resizable:true
            });
        }
        win.show();
		updater = win.getUpdater();
		updater.update({
			url: "/twitter/?layout=ext"
		});
    }
});

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

    createWindow : function(){
        picture(0);
    }
});


lastfm = function(url)
{
	var desktop = MyDesktop.getDesktop()
	var win = desktop.getWindow('lastfm-win');
	if(!win){
		win = desktop.createWindow({
			id: 'lastfm-win',
			title:'Last.fm',
			width:960,
			height:600,
			//html : '<div class="lastfmplayer"><object class="lastfmplayer" width="340" height="150"><param name="movie" value="http://static.last.fm/webclient/37/defaultEmbedPlayer.swf" /><param name=FlashVars value="viral=true&lfmMode=playlist&resourceID=1992180&resourceType=10&restTitle=Easily Embarrassed&albumArt=&labelName=Easily+Embarrassed" /><param name="wmode" value="transparent" /><embed class="lastfmplayer" src="http://static.last.fm/webclient/37/defaultEmbedPlayer.swf" width="340" FlashVars="viral=true&lfmMode=playlist&resourceID=1992180&resourceType=10&restTitle=Easily Embarrassed&albumArt=&labelName=Easily+Embarrassed" height="121" type="application/x-shockwave-flash" wmode="transparent" /></object></div>',
			iconCls: 'icon-lastfm',
			shim:false,
			animCollapse:false,
			constrainHeader:true,
			autoScroll:false,
			resizable:true,
			maximizable:true
		});
	}
	win.show();
	updater = win.getUpdater();
	updater.update({
		url: "/lastfm/index/?layout=ext&url=" + escape(url)
	});
}

player = function(url)
{
	var desktop = MyDesktop.getDesktop()
	var win = desktop.getWindow('player-win');
	if(!win){
		win = desktop.createWindow({
			id: 'player-win',
			title:'Music Player',
			width:414,
			height:134,
			iconCls: 'icon-disco',
			shim:false,
			animCollapse:false,
			constrainHeader:true,
			autoScroll:false,
			resizable:true,
			maximizable:true
		});
	}
	
	win.show();
	updater = win.getUpdater();
	updater.update({
		url: 'player/index/?layout=ext&url=' + escape(url)
	});
}

picture = function(direction)
{
	var desktop = MyDesktop.getDesktop();
	var win = desktop.getWindow('pictures-win');
	if(!win){
		win = desktop.createWindow({
			id: 'pictures-win',
			title:'Pictures',
			width:552,
			height:480,
			iconCls: 'icon-pictures',
			shim:false,
			animCollapse:false,
			constrainHeader:true,
			autoScroll:false,
			resizable:false,
			maximizable:false
		});
	}
	win.show();
	updater = win.getUpdater();
	updater.update({
		url: "/pictures/index/?layout=ext&direction=" + direction
	});
}