var map;
var nonstaticAncestors = new Array();



function createButtons(where) {
  if (fsVars.show) {
    var fsDiv = document.createElement('A');
    fsDiv.className = "gmap_button";
    fsDiv.id = 'fullscreenButton';
    fsDiv.appendChild(document.createTextNode((!fsVars.showing) ? fsVars.fullscreenText : fsVars.normalscreenText));
    if (!fsVars.showing) {fsDiv.href=fsVars.urlToFullScreen +'?'+fsVars.suffix;}
    else { fsDiv.href="javascript: history.back(1);"; }

    where.appendChild(fsDiv);
  }
}

function toggleApis() {
  var apis_checkboxes = $('apis_checkboxes');
  if (apis_checkboxes.hasClassName('closed')) {
    Effect.SlideDown(apis_checkboxes, {duration: 0.5});
    apis_checkboxes.removeClassName('closed');
  }
  else {
  Effect.SwitchOff(apis_checkboxes);
  apis_checkboxes.addClassName('closed');
  }
}

function createCheckboxes(whatArray, where) {
  var objs = new Array();
  var container = document.createElement('div');
  var container2 = document.createElement('div');
  var button = document.createElement('A');
  button.href = 'javascript:void(0);';
  button.onclick = function() {};
  button.className = 'gmap_button';
  button.appendChild(document.createTextNode('Mehr ...'));


  container2.className = "gmap_checkboxes";
  container2.id = "apis_checkboxes";
  container2.style.display = "none";
  container2.className = "closed";
  container.className = "gmap_buttons";
  whatArray.each(function(what){
      objs[what + 'Input'] = document.createElement ("input");
      objs[what + 'Input'] .type = "checkbox";
      objs[what + 'Input'] .name = what;
      objs[what + 'Input'] .id = what+"Control";
      objs[what + 'Label']  = document.createElement ("label");
      objs[what + 'Label'].htmlFor = what + "Control";
      if (what == 'panoramio') {
        objs[what + 'Label'].appendChild(document.createTextNode(Panoramio.menuName));
      }
      else {
        objs[what + 'Label'].appendChild(document.createTextNode(what.capitalize()));
      }
      objs[what + 'Loading'] = document.createElement ("DIV");
      objs[what + 'Loading'].className = "loading hided";
      objs[what + 'Loading'].id = what + 'Loading';

      var div = document.createElement('div');
      div.appendChild(objs[what + 'Loading']);
      div.appendChild(objs[what + 'Input']);
      div.appendChild(objs[what + 'Label']);

      container2.appendChild(div);
      obj = objs[what + 'Input'];
      Event.observe(obj,'change', function() {
        if (this.checked==true) {
          this.dragListener = GEvent.bind(map, "dragend", eval(this.name.capitalize()), eval(this.name.capitalize()+'.show'));eval(this.name.capitalize()+'.show()');
          this.zoomListener = GEvent.bind(map, "zoomend", eval(this.name.capitalize()), eval(this.name.capitalize()+'.show'));
        }
        else {
          GEvent.removeListener(this.dragListener);
          GEvent.removeListener(this.zoomListener);
          eval(this.name.capitalize()+".hide()");}
      })
  })
  container.appendChild(button);
  Event.observe(button, 'click', toggleApis);
  container.appendChild(container2);
  where.appendChild(container);

}

function getNonstaticAncestors (name) {
  var ancestors = $(name).ancestors;
  ancestors.each(function(el){
    if (el.getStyle('position')!="static") {
      nonstaticAncestors.push(el);
    }
  })
}

function apisInit() {
      map.addControl(new OtherApisControl());
    }

function OtherApisControl() {} //Class contructor

OtherApisControl.prototype = new GControl();
OtherApisControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  fsContainer = document.createElement("div");
  fsContainer.className = "gmap_buttons";
  createButtons(fsContainer);

  map.getContainer().appendChild(container);
  container.appendChild(fsContainer);
  createCheckboxes(['panoramio', 'webcams', 'wikipedia'], container)

  return container;
}

OtherApisControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(70, 7));
}

