
// controlScript.js
// defines a GControls that allows the user to zoom on certain regions of the USA : AreaZoomControl
// and another GControl that counts the new events : newJottsControl

var previousButton = "NorthAmerica";

function AreaZoomControl() {
}

AreaZoomControl.prototype = new GControl();
 
AreaZoomControl.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var ResetDefault = document.createElement("div");
  ResetDefault.id = "NorthAmerica";
  this.setButtonStyle_(ResetDefault);
  ResetDefault.style.color = "white";
  ResetDefault.style.border = "2px solid #F97E00";
  ResetDefault.style.background = "#f1a020";
  container.appendChild(ResetDefault);
  ResetDefault.appendChild(document.createTextNode("North America"));
  GEvent.addDomListener(ResetDefault, "click", function(map){                                                       
                             primaryMap.returnToSavedPosition();
                             currentZoom = 4;
                             SelectButton(previousButton, ResetDefault.id);
                             HideBadMarkers();                             
                             }); 
  
  var SEArea = AreaZoomControl.prototype.createButton(container, "Seattle", "Seattle, Jott Headquarters", new GLatLng(47.92097541515849, -122.3492431640625), 8 );
  var WesstCoastArea = AreaZoomControl.prototype.createButton(container, "WestCoast", "West Coast", new GLatLng(40.343824581185686, -111.29296875), 5);                            
  var EastCoastArea = AreaZoomControl.prototype.createButton(container, "EastCoast", "East Coast", new GLatLng(36.10237644873644, -80.771484375), 5);
  
  map.getContainer().appendChild(container);
  return container;
}

AreaZoomControl.prototype.createButton = function(container, id, newAreaName, LatLng, ZoomLevel)
 {
    var newArea = document.createElement("div");
    newArea.id = id;
    this.setButtonStyle_(newArea);    
    container.appendChild(newArea);
    newArea.appendChild(document.createTextNode(newAreaName));
    GEvent.addDomListener(newArea, "click", function(map){
                                        if (previousButton != newArea.id)
                                        {                                        
                                        SelectButton(previousButton, newArea.id);
                                        primaryMap.setZoom(11);
                                        currentZoom = 11;
                                        primaryMap.panTo(LatLng);
                                        SetZoomLevel(ZoomLevel);
                                        HideBadMarkers();
                                        }                                                                                
                                        });
    return newArea;
 }
 
AreaZoomControl.prototype.getDefaultPosition = function() {
     return new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(7, 33)); 
}

AreaZoomControl.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "none";
  button.style.backgroundColor = "#FAF8CC";
  button.style.color = "#463E3F";
  button.style.border = "1px solid #504A4B";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";
  button.style.width = "6em";
  button.style.cursor = "pointer";
}

function SetZoomLevel(zoom)
 {
    if (primaryMap.getZoom() != zoom)
        primaryMap.setZoom(zoom);
        
    currentZoom = zoom;    
 }
 
function SelectButton(pButton, selectedButton)
 {
    if (pButton != selectedButton)
    {
        document.getElementById(pButton).style.color = "#463E3F";
        document.getElementById(pButton).style.border = "1px solid #504A4B";
        document.getElementById(pButton).style.background = "#ECE5B6";
        document.getElementById(selectedButton).style.border = "2px solid #F97E00";
        document.getElementById(selectedButton).style.background = "#f1a020";
        document.getElementById(selectedButton).style.color = "#FFFFFF";
        previousButton = selectedButton;
        MapDisplayCtrl(selectedButton);
    }
 }

function MapDisplayCtrl(selectedButton)
{
    if(selectedButton == "Seattle" && primaryMap.getCurrentMapType().getName() == "Map")
        document.getElementById("adr").style.visibility = "visible";
    if(selectedButton != "Seattle")
        document.getElementById("adr").style.visibility = "hidden";
    if(selectedButton == "NorthAmerica" && primaryMap.getCurrentMapType().getName() == "Map")
        document.getElementById("eE").style.visibility = "visible";        
    if(selectedButton != "NorthAmerica")        
        document.getElementById("eE").style.visibility = "hidden";
}




function newJottsControl() {
}

newJottsControl.prototype = new GControl();

newJottsControl.prototype.initialize = function(map) {
  var container = document.createElement("div");
  
  var newJotts = document.createElement("div");
  newJotts.id = "nJButton";
  container.appendChild(newJotts);
  
  var pNJ = document.createElement("p");
  this.setButtonStyle_(pNJ);
  pNJ.id = "pNJ";   
  newJotts.appendChild(pNJ);  
  pNJ.innerHTML = eventCount + ' new events';
  
    
  map.getContainer().appendChild(container);
  return container;
}  
  
  
newJottsControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}

newJottsControl.prototype.setButtonStyle_ = function(button) {
  button.style.textDecoration = "none";
  button.style.color = "#F97E00";
  button.style.backgroundColor = "#FAF8CC";
  button.style.font = "small Arial";
  button.style.border = "1px outset black";
  button.style.padding = "2px";
  button.style.marginBottom = "3px";
  button.style.textAlign = "center";  
  button.style.width = "10em";
  button.style.cursor = "default";
   
}

function HideBadMarkers()
{    
    for (i = 0 ; i < myOldGMarker.length ; i++)
    {
        if (myOldGMarker[i])
        {
            if (myOldGMarker[i].typeID != 0 && myOldGMarker[i].typeID < currentZoom)
                if (!myOldGMarker[i].marker.isHidden())
                    myOldGMarker[i].marker.hide();
            
            else if (myOldGMarker[i].typeID == currentZoom && myOldGMarker[i].marker.isHidden())
                myOldGMarker[i].marker.show();
        }
    }
}

function ADRControl() {
}

ADRControl.prototype = new GControl();

ADRControl.prototype.initialize = function(map) {
  
  var container = document.createElement("div");
                                                              
  var eEbutton = document.createElement("div");
  eEbutton.id = "eE";
  eEbutton.style.font = "10px Arial";
  eEbutton.style.color = "black";
  eEbutton.style.cursor = "default";
  eEbutton.style.width = "8px";
  eEbutton.style.height = "8px";  
  GEvent.addDomListener(eEbutton, "click", function(map){
                                      primaryMap.openInfoWindowHtml(primaryMap.getCenter(), '<p>Sarebbe stato a facile Mark...</p>')
                                      var timeOut = setTimeout(function() {
                                                                primaryMap.getInfoWindow().hide();
                                                                }, 3000);
                                      });
                                      
  container.appendChild(eEbutton);
   
  
  map.getContainer().appendChild(container);
  return container;  
 }
 
ADRControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(58, 140));
}

function MapControl() {
}

MapControl.prototype = new GControl();

MapControl.prototype.initialize = function(map) {
  
  var container = document.createElement("div");
                                                              
  var mapCtrl = document.createElement("div");
  mapCtrl.id = "adr";
  mapCtrl.style.font = "10px Arial";
  mapCtrl.style.color = "white";
  mapCtrl.style.cursor = "default";
  mapCtrl.style.width = "8px";
  mapCtrl.style.height = "8px";  
  GEvent.addDomListener(mapCtrl, "click", function(map){
                                      primaryMap.openInfoWindowHtml(primaryMap.getCenter(), '<p><img src="Images/anim_JTV2.png" alt="me!"/><q style="color:red;">"I did this!"</q> Adrien favre-Bully, 8/8/2008 11:47AM, Seattle, WA</p>')
                                      var timeOut = setTimeout(function() {
                                                                primaryMap.getInfoWindow().hide();
                                                                }, 3000);
                                      });
                                      
  container.appendChild(mapCtrl);
   
  
  map.getContainer().appendChild(container);
  return container;  
 }
 
MapControl.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(206, 139));
}    
