﻿var placeListPageSize = 6;
var mapdiv; 
var map;
var gEarth = null;
var smallMapArray = new Array(placeListPageSize);



function TextualZoomControl() 
{
}
TextualZoomControl.prototype = new GControl();

TextualZoomControl.prototype.initialize = function(m) 
{
  var container = document.createElement("div");

  var t1 = document.createElement("div");
  this.setButtonStyle_(t1);
  container.appendChild(t1);
  t1.appendChild(document.createTextNode("Térkép"));
  GEvent.addDomListener(t1, "click", function() 
  {
    m.setMapType(G_NORMAL_MAP);
  });
  
  var t2 = document.createElement("div");
  this.setButtonStyle_(t2);
  container.appendChild(t2);
  t2.appendChild(document.createTextNode("Műhold"));
  GEvent.addDomListener(t2, "click", function() 
  {
    m.setMapType(G_SATELLITE_MAP);
  });

  var t3 = document.createElement("div");
  this.setButtonStyle_(t3);
  container.appendChild(t3);
  t3.appendChild(document.createTextNode("Hibrid"));
  GEvent.addDomListener(t3, "click", function() 
  {
    m.setMapType(G_HYBRID_MAP);
  });

  var t4 = document.createElement("div");
  this.setButtonStyle_(t4);
  container.appendChild(t4);
  t4.appendChild(document.createTextNode("Domborzat"));
  GEvent.addDomListener(t4, "click", function() {
    map.enableScrollWheelZoom();
    m.setMapType(G_PHYSICAL_MAP);
  });

  m.getContainer().appendChild(container);
  return container;
}

TextualZoomControl.prototype.getDefaultPosition = function() 
{
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

TextualZoomControl.prototype.setButtonStyle_ = function(button) 
{
  button.style.color = "#ffffff";
  button.style.backgroundColor = "#001080";
  button.style.border = "solid 1px #afafdf";
  button.style.padding = "4px";
  button.style.marginBottom = "6px";
  button.style.textAlign = "center";
  button.style.cursor = "pointer";
  button.style.backgroundImage = "url('http://i.ittvoltam.hu/mapbutton.jpg')";
}







function TextualZoomControlEarth() 
{
}
TextualZoomControlEarth.prototype = new GControl();

TextualZoomControlEarth.prototype.initialize = function(m) 
{
  var container = document.createElement("div");

  var t1 = document.createElement("div");
  this.setButtonStyle_(t1);
  container.appendChild(t1);
  t1.appendChild(document.createTextNode("Térkép"));
  GEvent.addDomListener(t1, "click", function() 
  {
    map.enableScrollWheelZoom();
    m.setMapType(G_NORMAL_MAP);
  });
  
  
  var t4 = document.createElement("div");
  this.setButtonStyle_(t4);
  container.appendChild(t4);
  t4.appendChild(document.createTextNode("3D Föld"));
  GEvent.addDomListener(t4, "click", function() 
  {
    map.disableScrollWheelZoom();
    var mec = $get('mec');
    if (mec != null)
    {
      mec.style.display = 'block';
    }
    m.setMapType(G_SATELLITE_3D_MAP);
    map.getEarthInstance(getEarthInstanceCB);
  });
  

  var t2 = document.createElement("div");
  this.setButtonStyle_(t2);
  container.appendChild(t2);
  t2.appendChild(document.createTextNode("Műhold"));
  GEvent.addDomListener(t2, "click", function() 
  {
    map.enableScrollWheelZoom();
    m.setMapType(G_SATELLITE_MAP);
  });

  var t3 = document.createElement("div");
  this.setButtonStyle_(t3);
  container.appendChild(t3);
  t3.appendChild(document.createTextNode("Hibrid"));
  GEvent.addDomListener(t3, "click", function() {
    map.enableScrollWheelZoom();
    m.setMapType(G_HYBRID_MAP);
  });

  var t4 = document.createElement("div");
  this.setButtonStyle_(t4);
  container.appendChild(t4);
  t4.appendChild(document.createTextNode("Domborzat"));
  GEvent.addDomListener(t4, "click", function() {
    map.enableScrollWheelZoom();
    m.setMapType(G_PHYSICAL_MAP);
  });

  m.getContainer().appendChild(container);
  return container;
}

  
function getEarthInstanceCB(object) 
{
  var mecGoto = $get('mecGoto');
  var mecSetup = $get('mecSetup');

  gEarth = object;
  if (gEarth != null)
  {
    var opt = gEarth.getOptions();
    opt.setStatusBarVisibility(true);

    if (mecSetup != null) mecSetup.style.display = 'none';
    if (mecGoto != null) mecGoto.style.display = 'block';
  }
  else
  {
    if (mecSetup != null) mecSetup.style.display = 'block';
    if (mecGoto != null) mecGoto.style.display = 'none';
  }
}

TextualZoomControlEarth.prototype.getDefaultPosition = function() 
{
  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));
}

TextualZoomControlEarth.prototype.setButtonStyle_ = function(button) 
{
  button.style.color = "#ffffff";
  button.style.backgroundColor = "#001080";
  button.style.border = "solid 1px #afafdf";
  button.style.padding = "4px";
  button.style.marginBottom = "6px";
  button.style.textAlign = "center";
  button.style.cursor = "pointer";
  button.style.backgroundImage = "url('http://i.ittvoltam.hu/mapbutton.jpg')";
}





 
GMap2.prototype.wheelZoom = function(event) { 
  if (window.event) { 
    event.returnValue = false; // IE 
  } 
  if (event.cancelable) { 
    event.preventDefault();  // DOM-Standard 
  } 
    return false; 
} 


function updateSmallMap()
{
  if (GBrowserIsCompatible()) {
    var lat;
    var lng;
    var zoom, mapType;
    var smap, smapDiv;
    for (i=0; i<placeListPageSize; i++)
    {
      if ($get('sMap'+i))
      {
        lat = parseFloat($get('sLat'+i).value);
        lng = parseFloat($get('sLng'+i).value);
        zoom = parseFloat($get('sZoom'+i).value);
        mapType = parseInt($get('sType'+i).value);
        smapDiv = $get('sMap'+i);
        smap = new GMap2(smapDiv);
        smallMapArray[i] = smap;
        switch (mapType)
        {
          case 2:
            smap.setCenter(new GLatLng(lat, lng), zoom, G_SATELLITE_MAP);
            break;
          case 3:
            smap.setCenter(new GLatLng(lat, lng), zoom, G_HYBRID_MAP);
            break;
          case 4:
            smap.setCenter(new GLatLng(lat, lng), zoom, G_PHYSICAL_MAP);
            break; 
          default:
            smap.setCenter(new GLatLng(lat, lng), zoom, G_NORMAL_MAP);
            break;
        }
        //smap.enableContinuousZoom();
        smap.enableScrollWheelZoom();
        
        GEvent.addDomListener(smapDiv, "DOMMouseScroll", smap.wheelZoom); // Firefox 
        GEvent.addDomListener(smapDiv, "mousewheel", smap.wheelZoom); // IE 
        smap.addOverlay(createMarkerSM(new GLatLng(lat, lng)));
      } 
    }
  }
}  

function createMarkerSM(point) 
{  
  var icon = new GIcon();
  icon.image = "http://i.ittvoltam.hu/icon/crossW.png";
  icon.iconSize = new GSize(11, 11);
  icon.iconAnchor = new GPoint(5, 5);
  icon.infoWindowAnchor = new GPoint(5, 0);
  return new GMarker(point, icon);
} 



function subGPoints(a,b) { 
  return new GPoint(a.x-b.x, a.y-b.y); 
} 
