/* (C) 2006-7 Ken Garson. All rights reserved. v2/17/07 */
MapFunctions.prototype.addCopyrightInfo=function(thisMap)
{
  var info=document.createElement('div');
  info.id='mapid';
  info.style.position='absolute';
  info.style.right='1px';
  info.style.bottom='25px';
  info.style.backgroundColor='transparent';
  info.style.zIndex=25500;
  info.innerHTML='<span id="MapCopyright" style="font: 10px verdana; text-decoration: none; padding: 2px; color: #FFFFFF;">WFMU map generated by <b><a href="http://counterfolk.com/ken/extrav/" style="color: #FFFFFF" id="MapCopyrightURL1">KenzoDB, &copy; 2006-7 Ken Garson</a></b>.</span>';
  thisMap.getContainer().appendChild(info);
}

MapFunctions.prototype.registerMapEvent=function(thisMap)
{
  GEvent.addListener(thisMap, "maptypechanged", function() {
     setCreatedColor(thisMap);
  });
}

GMap2.prototype.addMapFunctions=function(thisMap)
{
  thisMap.initialize(this);
}

function setCreatedColor(thisMap)
{
   var info=thisMap.getContainer().ownerDocument.getElementById('MapCopyright');
   infoURL1=thisMap.getContainer().ownerDocument.getElementById('MapCopyrightURL1');
   //infoURL2=thisMap.getContainer().ownerDocument.getElementById('MapCopyrightURL2');
   currmaptype = getCurrentMapTypeNumber(thisMap);
   if (currmaptype == 0)  //Map
   {
      info.style.color='#000000';
      infoURL1.style.color='#000000';
      //infoURL2.style.color='#000000';
   }
   else  //Hybrid, sat
   {
      info.style.color='#FFFFFF';
      infoURL1.style.color='#FFFFFF';
      //infoURL2.style.color='#FFFFFF';
   }
}

//determins map type from getMapTypes array
function getCurrentMapTypeNumber(thisMap)
{
  var type=-1;
  for (var ix=0; ix<thisMap.getMapTypes().length; ix++)
  {
    if(thisMap.getMapTypes()[ix]==thisMap.getCurrentMapType())
      type=ix;
  }
  return type;
} 

function createMarker(point, html, icon)
{
  var marker = new GMarker(point, icon);

  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(html);
  });

  return marker;
}

function ZoomMapTo(num)
{
   currentZoom = map.getZoom();
   map.checkResize();

   newzoom = (currentZoom < 6) ? 6 : ((currentZoom == 17) ? 17 : (currentZoom + 1));
   map.setCenter(mappoints[num], newzoom);
}

function MapFunctions(){}
MapFunctions.prototype.initialize=function(thisMap){
  // Show info
  this.addCopyrightInfo(thisMap);
  // On maptype change, to change color
  this.registerMapEvent(thisMap);
  // Set text color based on current maptype
  setCreatedColor(thisMap);
}

function jumpToMapCoords(thisLong,thisLat)
{
   currentZoom = map.getZoom();
   jumpPoint = new GLatLng(thisLat, thisLong);
   forceUpdate = 1;  //force redraw in this case, since beyond-center test seems to fail
   if (currentZoom < 6)
      map.setCenter(jumpPoint, 6);
   else
      map.panTo(jumpPoint);
}

    function myOpener(i,level)
    {
       // First adjust zoom a bit
       //currentZoom = map.getZoomLevel();
       //if (currentZoom > 15)
       //   map.centerAndZoom(mappoints[i], 15);
       //else
          map.panTo(mappoints[i]);

       mapmarkers[i].openInfoWindowHtml(maphtml[i]);
    }
	  
    function makeOpenerCaller(i,level)
    {
       return function() { myOpener(i,level); };
    }


    function getMapSize()
    {
      if( window.innerHeight )
      {
       mapWidth = (window.innerWidth - 290) * .9 ;
       mapHeight = window.innerHeight - 140 ; 
      } else
      {
       mapWidth = (document.body.clientWidth - 340) * .9 ;
       mapHeight = document.body.clientHeight - 160 ; 
      }
      mapDiv = document.getElementById("MarathonMap");
      //mapDiv.style.width=mapWidth;
      mapDiv.style.height=mapHeight;  //mapWidth * 3/4
      //map.onResize();
    }
