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

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

    // Menus can be prebuilt and passed by reference
    var menuStats = new Ext.menu.Menu({
        id: 'menuStats',
        items: [
            {
                text: 'Server',
                handler: onButtonClick
            },
            {
                text: 'Users',
                handler: onButtonClick
            },
            {
                text: 'Operators',
                handler: onButtonClick
            }
        ]
    });
    
    
    var menuMaps = new Ext.menu.Menu({
        id: 'menuMaps',
        items: [
            {
                text: 'cellular with OpenStreetMap (alpha)',
                handler: onButtonClick
            },
            {
                text: 'cellular with google earth',
                handler: onButtonClick
            },
            {
                text: 'cellular coverage (alpha)',
                handler: onButtonClick
            },

            {
                text: 'wifi with OpenStreetMap (beta)',
                handler: onButtonClick
            }
        ]
    });

    var menuOther = new Ext.menu.Menu({
        id: 'menuOther',
        items: [
            {
                text:'Wiki',
	        handler: onButtonClick
            },
            {
                text:'Forum',
	        handler: onButtonClick
            },
            {
                text: 'Contact',
                handler: onButtonClick
            }
        ]
    });

    
  
    
    var tb = new Ext.Toolbar();
    tb.render('toolbar');

   // tb.addElement('<b>Hello</b>');
    
    tb.add(
    	new Ext.Toolbar.Button({
            text:'Register',
	    handler: onButtonClick
        }),
    	new Ext.Toolbar.Button({
            text:'Usages',
	    handler: onButtonClick
        }),
    	new Ext.Toolbar.Button({
            text:'API',
	    handler: onButtonClick
        }),
	new Ext.Toolbar.Button({
            text:'Screenshots',
	    handler: onButtonClick
        }),
	new Ext.Toolbar.Button({
            text:'Download',
	    handler: onButtonClick
        }),
	{
            text:'Stats',
            menu: menuStats  // assign menu by instance
        },
	{
            text:'Maps',
            menu: menuMaps  // assign menu by instance
        },
	{
            text:'Other',
            menu: menuOther  // assign menu by instance
        }
    );

    // functions to display feedback
    function onButtonClick(btn){
        //Ext.example.msg('Button Click','You clicked the "{0}" button.', btn.text);
	
	if ( btn.text=="Register") {
		    var adresse = "http://openbmap.org/register.php5";
		    window.location.href = adresse;
		    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Screenshots") {
		    var adresse = "http://openbmap.org/screenshots.php5";
		    window.location.href = adresse;
		    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Wiki") {
	    var adresse = "http://myposition.wiki.sourceforge.net/";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Forum") {
	    var adresse = "http://sourceforge.net/projects/myposition/support";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Download") {
	    var adresse = "https://sourceforge.net/project/showfiles.php?group_id=218065";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Usages") {
	    var adresse = "http://openbmap.org/usages.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Contact") {
	    var adresse = "http://openbmap.org/contact.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Server") {
	    var adresse = "http://openbmap.org/server_stats.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Users") {
	    var adresse = "http://openbmap.org/logins_stats.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="Operators") {
	    var adresse = "http://openbmap.org/operators_stats.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="cellular with OpenStreetMap (alpha)") {
	    var adresse = "http://openbmap.org/with_osm6.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="cellular coverage (alpha)") {
	    var adresse = "http://openbmap.org/with_osm5_coverage.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}	
	if ( btn.text=="wifi with OpenStreetMap (beta)") {
	    var adresse = "http://openbmap.org/wifi_with_osm5.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="cellular with google earth") {
	    var adresse = "http://openbmap.org/maps/with_google_earth.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}
	if ( btn.text=="API") {
	    var adresse = "http://openbmap.org/api/openbmap_api.php5";
	    window.location.href = adresse;
	    setTimeout( "window.location.href = adresse", 0 );
	}

    }

    function onItemClick(item){
        Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
    }

    function onItemCheck(item, checked){
        Ext.example.msg('Item Check', 'You {1} the "{0}" menu item.', item.text, checked ? 'checked' : 'unchecked');

    }

    function onItemToggle(item, pressed){
        Ext.example.msg('Button Toggled', 'Button "{0}" was toggled to {1}.', item.text, pressed);
    }

});
