Ext.onReady(function(){
	Ext.QuickTips.init();

/* Menu Basics

	File
		New		Start with an empty map
		Open		Upload a file
		Previous	Other files you already have

	Edit
		Undo

	Tools
		Toggle Enable New Points

	Search
		Text entry - maybe predefined - like Point Types

	Help
		Instructions ?
		About		Dialogue with Help Information

*/

// Build the Toolbar
    var tb = new Ext.Toolbar('toolbar');

    // File menu
    tb.add({
            text:'File',
            cls: 'x-btn-text bmenu', // icon and text class
            tooltip: {text:'Useful tools', title:'File'},
            menu: new Ext.menu.Menu({
			id: 'mainMenu',
			items: [
				new Ext.menu.Item({
					text: 'Open',
					handler: function() {
						var dlg = new Ext.BasicDialog("dlg-open", {
							height: 300,
							width: 400,
							minHeight: 100,
							minWidth: 150,
							modal: true,
							proxyDrag: true,
							shadow: true
						});
						dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
						dlg.addButton('OK', dlg.hide, dlg);    // Could call a save function instead of hiding
						dlg.addButton('Cancel', dlg.hide, dlg);
						dlg.show();
					}
				}),
			    new Ext.menu.CheckItem({
				text: 'Todo',
				// checkHandler: onItemCheck,
				checked: true
			    }), '-', {
				text: 'Debug',
				menu: {        // <-- submenu by nested config object
				    items: [
					// stick any markup in a menu
					'<b class="menu-title">Debug Data</b>',
					new Ext.menu.Item({
					    text: 'B in the Title',
					    handler: function() {
						glidermaps.filterMarkers('B');
					    }
					}),
					new Ext.menu.Item({
					    text: 'Bendigo Only',
					    handler: function() {
						glidermaps.filterMarkers('Bendigo');
					    }
					}),
					new Ext.menu.Item({
					    text: 'S in Flag',
					    handler: function() {
						glidermaps.filterMarkers('', 'S');
					    }
					}),
					new Ext.menu.Item({
					    text: 'B in Title and TA in Flag',
					    handler: function() {
						glidermaps.filterMarkers('B', 'TA');
					    }
					}),
					new Ext.menu.Item({
					    text: 'Show All',
					    handler: function() {
						glidermaps.filterMarkers();
					    }
					})
				    ]
				}
			    }
			]
	    })
        });

    // Edit Menu
    tb.add({
            text:'Edit',
            cls: 'x-btn-text bmenu', // icon and text class
            tooltip: {text:'Edit tools', title:'Edit'},
            menu: new Ext.menu.Menu({
			id: 'mainMenu',
			items: [
				new Ext.menu.Item({
					text: 'Undo',
					handler: function() {
						glidermaps.undoUndo();
					}
				})
			]
		})
	});


    // Tool Menu
    tb.add({
            text:'Tools',
            cls: 'x-btn-text bmenu', // icon and text class
            tooltip: {text:'Useful tools', title:'Tools'},
            menu: new Ext.menu.Menu({
            	items: [
			new Ext.menu.CheckItem({
				text: 'Add Waypoints',
				checkHandler: function() {
					glidermaps.toggleNew();
				}
			}),
			{
				text: 'Waypoint Colour', menu: {
					items: [
						new Ext.menu.ColorItem({selectHandler:function(cp, color){
						    Ext.example.msg('Color Selected', 'You chose {0}.', color);
						}}), '-',
						{text:'More Colors...'}
					]
				}
		        }
                ]
        })
});


    // Help Menu
    tb.add({
            text:'Help',
            cls: 'x-btn-text bmenu', // icon and text class
            tooltip: {text:'Useful tools', title:'Help'},
            menu: new Ext.menu.Menu({
            	items: [
			new Ext.menu.Item({
				text: 'General Help',
				handler: function() {
					var dlg = new Ext.BasicDialog("dlg-help", {
						height: 300,
						width: 400,
						minHeight: 100,
						minWidth: 150,
						modal: true,
						proxyDrag: true,
						shadow: true
					});
					dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
					dlg.addButton('OK', dlg.hide, dlg);    // Could call a save function instead of hiding
					dlg.addButton('Cancel', dlg.hide, dlg);
					dlg.show();
				}
			}),
			new Ext.menu.Item({
				text: 'About',
				handler: function() {
					var dlg = new Ext.BasicDialog("dlg-about", {
						height: 200,
						width: 300,
						minHeight: 100,
						minWidth: 150,
						modal: true,
						proxyDrag: true,
						shadow: true
					});
					dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
					dlg.addButton('OK', dlg.hide, dlg);    // Could call a save function instead of hiding
					dlg.addButton('Cancel', dlg.hide, dlg);
					dlg.show();
				}
			})
		]
  	})
    });

    // Search box - XXX Align Right !
    var combo = new Ext.form.TextField({
        displayField:'search',
        emptyText:'Search...',
	validator: function(value) { glidermaps.filterMarkers(value); return true;},
	// onSelect: function(record) { window.alert("Hello onSelect");},
        width:135
    });

	tb.addField(combo);

	tb.addButton({
		text: 'clear',
		cls: 'x-btn-text', 
		handler: function() {
			combo.reset();
			glidermaps.filterMarkers();
		}
	});

});
