//Start: Button More ===========================================================

function MoreControl() {}
MoreControl.prototype = new GControl();
MoreControl.prototype.initialize = function( map ) {
    var container = document.createElement( "div" );
    container.style.border = "2px solid black";
    container.style.fontSize = "12px";
    container.style.fontFamily = "Arial, sans-serif";
    container.style.width=(  getCurLang()=='chi'  ?  "80px" : "120px"  );
    container.style.backgroundColor = "#ffffff";
    container.style.textAlign = "center";
    //container.innerHTML = "<b>更多...<\/b>";
    container.innerHTML = "<b>"  +  (getCurLang()=='chi'?"巴士站顯示":"Bus Stop Display")  +  "<\/b>";
  
    map.getContainer().appendChild( container );
    
    GEvent.addDomListener( container, "click", function() {
        map.addControl( morebtn_layerControl );
    } );
 
    return container;
}
MoreControl.prototype.getDefaultPosition = function() {
    return new GControlPosition( G_ANCHOR_TOP_RIGHT, new GSize( 72, 7 ) );
}

function LayerControl(opts_eng, opts_chi) {
    this.opts_eng = opts_eng;
    this.opts_chi = opts_chi;
}

LayerControl.prototype = new GControl();
LayerControl.prototype.initialize = function( map  ) {
    var container = document.createElement( "div" );
    container.style.border = "2px solid black";
    container.style.fontSize = "12px";
    container.style.fontFamily = "Arial, sans-serif";
    container.style.width=(  getCurLang()=='chi'  ?  "120px" : "160px"  );
    container.style.backgroundColor = "#ffffff";
    //container.innerHTML = '<center><b>更多...<\/b><\/center>';
    container.innerHTML = '<center>'  +  (getCurLang()=='chi'?"巴士站顯示":"Bus Stop Display")  + '<\/center>';
    
    for ( var i = 0; i < this.opts_eng.length; i++ ) 
    {
        var c;
        if ( morebtn_layers[i].Visible ) c = 'checked';
        else c = '';
        container.innerHTML += '<input type="checkbox" onclick="morebtn_toggleLayer('+i+')" ' +c+ ' /> '+(getCurLang()=='chi'?this.opts_chi[i]:this.opts_eng[i])+'<br>';
    }
    map.getContainer().appendChild( container );
 
    //GEvent.addDomListener(container, "mouseout", function() {
    //    //map.removeControl(morebtn_layerControl);
    //    setTimeout( "map.removeControl(morebtn_layerControl)", 3000 );
    //});

    setTimeout( "map.removeControl(morebtn_layerControl)", 3000 );
    return container;
}

LayerControl.prototype.getDefaultPosition = function() {
    return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(70, 7)); 
}

function morebtn_toggleLayer(i) {

    if (morebtn_layers[i].Visible) {
        
        morebtn_toggleLayer_hide(i);
        
    } else {
        
        morebtn_toggleLayer_show(i);
      
    }
}


function morebtn_toggleLayer_show(i) {

      if( morebtn_layers!= null ) 
      {
              ////checkbox is Checked
              //morebtn_layers[i].show();
              //morebtn_layers[i].Visible = true;
              
              
              switch(i) {
                  case 0:
                      morebtn_layers[0].show();
                      morebtn_layers[0].Visible = true;
                      
                      zoomToNearByActiveLevel();      //Zoom to neaby activative level   
                      showNearBy();
                      break;
                      
                  case 1: 
                      hideRouteWithTerminationOnly();
                      break;
              }           
      }
}


function morebtn_toggleLayer_hide(i) {

      if( morebtn_layers!= null ) 
      {
              ////checkbox is Unchecked
              //morebtn_layers[i].hide();
              //morebtn_layers[i].Visible = false;
              
                              
              switch(i) {
                  case 0: 
                      morebtn_layers[0].hide();
                      morebtn_layers[0].Visible = false;
                      
                      hideNearBy();
                      break;
                      
                  case 1: 
                      showRouteWithTerminationOnly();
                      break;
              }
      }
}



// === Create the layerControl, but don't addControl() it ===
// = Pass it an array of names for the checkboxes =
/*
var morebtn_layerControl = new LayerControl(  
                                        ["Show nearby bus stops", "Show bus route"] ,
                                        ["顯示鄰近的巴士站", "顯示巴士路線"] 
                                    );
*/
var morebtn_layerControl = new LayerControl(  
                                        ["Show nearby bus stops"] ,
                                        ["顯示鄰近的巴士站"] 
                                    );

var morebtn_layers = [];      
morebtn_layers[0] = new GLayer();
morebtn_layers[0].Visible = false;

//morebtn_layers[1] = new GLayer();
//morebtn_layers[1].Visible = true;

                                     
//End: Button More ============================================================
