﻿var map;
var markers = new Array();

function initialize(latitude, longitude) {
  if (GBrowserIsCompatible()) {
    map = new GMap2($("map"));
    map.setMapType(G_HYBRID_MAP);
    map.setCenter(new GLatLng(latitude, longitude), 4);
    map.setUIToDefault();
    map.disableScrollWheelZoom();
    GEvent.addListener(map, "click", function() {
      map.enableScrollWheelZoom();
    });
    GEvent.addListener(map, "mouseout", function() {
      map.disableScrollWheelZoom();
    });
  }
}

function createMarker(newLat, newLong, order) {
    var point = new GLatLng(newLat, newLong);
    var infoWindowNumber = "infoWindow" + order;
    var baseIcon = new GIcon();
	    baseIcon.image = "/images/markers/default.png";
	    baseIcon.iconSize = new GSize(24, 35);
	    baseIcon.iconAnchor = new GPoint(9, 34);
	    baseIcon.infoWindowAnchor = new GPoint(9, 2);
	    baseIcon.infoShadowAnchor = new GPoint(18, 25);
		
  var marker = new GMarker(point, baseIcon);
	
  GEvent.addListener(marker, 'click', function() {
  //code inside parent funciton
  
  map.panTo(new GLatLng(newLat, newLong));
  //map.setCenter(new GLatLng(newLat, newLong));
  window.setTimeout(function() {
  map.setZoom(4);
  },1600);
	
	     window.setTimeout(function() {
	    marker.openInfoWindowHtml($(infoWindowNumber).innerHTML);
	     }, 1700);
	
  
  //code below ends parent function
  });	
  return marker;
}

function panToLocation(newLat, newLong, order) {
    var infoWindowNumber = "infoWindow" + order;
      map.panTo(new GLatLng(newLat, newLong));
      window.setTimeout(function() {
      map.setZoom(4);
      },1600);
      //window.location.hash = "#content";
      map.closeInfoWindow();
     
      window.setTimeout(function() {
	        markers[order - 1].openInfoWindowHtml($(infoWindowNumber).innerHTML);
	         }, 1700);
}

function panToPrevPort(zoomLat, zoomLong, order) {
    var infoWindowNumber = "infoWindow" + order;
        map.closeInfoWindow();
        map.panTo(new GLatLng(zoomLat, zoomLong));
        window.setTimeout(function() {
        map.setZoom(4);
        }, 500);
        window.setTimeout(function() {
        markers[order - 1].openInfoWindowHtml($(infoWindowNumber).innerHTML);
        }, 600);
}

function zoomOut() {
    map.closeInfoWindow();
    map.setZoom(3);
}
