var AdPushpin = function()
{
  //private members
  var map = null;
  var markersArray = new Array();
  var adicon;
	var pubid;

  //public members
  return {

    // Set the map variable and define the pushpin icon.
    setMap:function(m)
    {
      map = m;
    },

		setPubid:function(id)
		{
			pubid = id;
		},

    //Update the marker info with a title and address
    updateMarker:function(marker,title, address,pinid)
    {
      marker.SetTitle(title);
      marker.SetDescription(address);
			Lat49.trackPinClick(pinid,pubid);
    },

    //Hide all the pushpins
    hidePushPin:function()
    {
      for (var i = 0; i < markersArray.length; i++)
      {
        map.DeleteShape(markersArray[i]);
      }

      markersArray = new Array();
    },

    //Push new markers into the markersArray and display them on the map.
    showPushPin:function(loc)
    {
      var maxpins = 100;

      for (var i=0; i<loc.length;i++)
      {
        if(i<=maxpins)
        {
          var point = new VELatLong(loc[i].lat, loc[i].lon);
          var marker = new VEShape(VEShapeType.Pushpin, point);
					var adicon = new VECustomIconSpecification();
          adicon.Image = loc[i].pinurl;
          adicon.ImageOffset = new VEPixel(-5,-6);

          marker.SetCustomIcon(adicon);

          map.AddShape(marker);

          // add markers to array
          markersArray.push(marker);
          this.updateMarker(marker, loc[i].title, loc[i].address,loc[i].pinid);
        }
      }
    }
  }
}();