var sav_img = document.createElement("img");
sav_img.src = "http://planpulawy.pl/images/map_viewer/button-print.png";
sav_img.style.border = "0px";
sav_img.style.margin = "0px";

var rut_img = document.createElement("img");
rut_img.src = "http://planpulawy.pl/images/map_viewer/button-show.png";
rut_img.style.border = "0px";
rut_img.style.margin = "0px";

var rut_on_img = document.createElement("img");
rut_on_img.src = "http://planpulawy.pl/images/map_viewer/button-hide.png";
rut_on_img.style.border = "0px";
rut_on_img.style.margin = "0px";

function TextualZoomControl() {
}
TextualZoomControl.prototype = new GControl();
TextualZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  var saveDiv = document.createElement("div");
    this.setButtonStyle_(saveDiv);
    saveDiv.title = lang[25];
    saveDiv.id = "drukujCtl";
    saveDiv.appendChild(sav_img);
    container.appendChild(saveDiv);
    map.parent.buttonSave = saveDiv;
  
    
  var routeDiv = document.createElement("div");
    this.setButtonStyle_(routeDiv);
    routeDiv.title = lang[28];
    routeDiv.id = "routeCtl";
    routeDiv.style.display = "block";
    routeDiv.appendChild(rut_img);
    container.appendChild(routeDiv);
    map.parent.buttonRoute = routeDiv;
    
  var routeOnDiv = document.createElement("div");
    this.setButtonStyle_(routeOnDiv);
    routeOnDiv.title = lang[27];
    routeOnDiv.id = "routeOnCtl";
    routeOnDiv.appendChild(rut_on_img);
    routeOnDiv.style.display = "none";
    container.appendChild(routeOnDiv);
    map.parent.buttonRouteOn = routeOnDiv;

    map.getContainer().appendChild(container);
    return container;
}

TextualZoomControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 40));
}

TextualZoomControl.prototype.setButtonStyle_ = function(button) {
  button.style.font = "small Arial";
  button.style.padding = "2px";
  button.style.margin = "0px";
  button.style.textAlign = "center";
  button.style.width = "";
  button.style.cursor = "pointer";
}

TextualZoomControl.prototype.setContainerStyle_ = function(button) {
  button.style.backgroundColor = "white";
  button.style.font = "small Arial";
  button.style.border = "1px solid black";
  button.style.padding = "2px";
  button.style.margin = "0px";
  button.style.textAlign = "center";
  button.style.width = "";
  button.style.cursor = "pointer";
}



var Map = Class.create();
function WlasneLogo() {}  
WlasneLogo.prototype = new GControl();

WlasneLogo.prototype.initialize = function(mapa)  
  {  
  var logo = document.createElement('div');  
  logo.id = 'logo';  
  logo.onclick = function() { window.location = 'http://ipulawy.pl'; }
  mapa.getContainer().appendChild(logo);    
  return logo;   
  }  
  
  function Reklama() {} 
  Reklama.prototype = new GControl();

Reklama.prototype.initialize = function(mapa)  
  {  
  var reklama = document.createElement('div');  
  reklama.id = 'reklama';  
  reklama.onclick = function() { window.location = 'http://planpulawy.pl/reklama.php'; }
  mapa.getContainer().appendChild(reklama);    
  return reklama;   
  }  
  
Map.prototype = {
    drag: false,
    selected: null,
    initialize: function(mapDiv)
    {
        this.savedPositions = new Array(10);
        this.savePositionIndex = 0;
        this.returnToSavedPositionIndex = 0;
        if (GBrowserIsCompatible()) {
            this.mapDiv = $(mapDiv);
            this.gMap = new GMap2(this.mapDiv);
            this.gMap.parent = this;
            //this.gMap.setCenter(new GLatLng(50.0667261411256, 19.9136209487915), 14);
            this.returnToBounds();
            this.gMap.addControl(new GSmallMapControl());
            this.gMap.addControl(new GMapTypeControl());
            this.gMap.addControl(new TextualZoomControl());
			this.gMap.addControl(new WlasneLogo()); 
this.gMap.addControl(new Reklama()); 
			this.gMap.addControl(new google.maps.LocalSearch());
        }
    },
    setToolBox: function(toolBox)
    {
        this.toolBox = toolBox;
    },
    addPlaces: function(places)
    {
        this.gMap.clearOverlays();
    },
    returnToBounds: function()
    {
      if (starting_bounds == null)
        this.gMap.setCenter(new GLatLng(51.41794394475732, 21.963987350463867), 12);
      else
      {
        this.gMap.setCenter(starting_bounds.getCenter());
        this.gMap.setZoom(this.gMap.getBoundsZoomLevel(starting_bounds));
      }
    }
    /*
    // mocno robocze... w  zastepstwie do funkcji, ktore wywowywane sa z infoWIndow z place.js
    savePosition: function()
    {
      alert(this.savedPositions + " :: " + this.returnToSavedPositionIndex + " " + this.savePositionIndex);
      if ((this.savePositionIndex - this.savedPositions.length+1) < this.returnToSavedPositionIndex)
      {
        this.savedPositions[this.savePositionIndex % this.savedPositions.length] = this.gMap.getBounds();
        this.savePositionIndex++;
      }
      alert(this.savedPositions + " :: " + this.returnToSavedPositionIndex + " " + this.savePositionIndex);      
    },
    returnToSavedPosition: function()
    {
      alert(this.savedPositions + " :: " + this.returnToSavedPositionIndex + " " + this.savePositionIndex);
      if (this.returnToSavedPositionIndex + this.savedPositions.length-1 > this.savePositionIndex)
      {
        var bounds = this.savedPositions[this.returnToSavedPositionIndex % this.savedPositions.length];
        this.gMap.setCenter(bounds.getCenter());
        this.gMap.setZoom(this.gMap.getBoundsZoomLevel(bounds));
        this.returnToSavedPositionIndex++;
      }
      alert(this.savedPositions + " :: " + this.returnToSavedPositionIndex + " " + this.savePositionIndex);
    }
    */
}

