 var map = null;

 /**
  *This initializes the map component
  */
function Init()
{
	GetMap();
	CreateLayers();
}

 /**
  *This method creates a map and loads the default pins
  */
 function GetMap()
 {
    map = new VEMap('myMap');

		MapControl.Features.ScaleBarKilometers = true;
    map.LoadMap(new VELatLong(53.28780778733046,-6.370482444763168), 15 ,'r' ,false);

		map.ShowMiniMap(418,1);
		//map.ClearInfoBoxStyles();

 }

 /**
  *This method creates 3 layers.  Parking,
  *Info and Access.
  */
  function CreateLayers()
  {
	

	var infoTitle = "Info";
	CreateLayer(infoTitle);
	AddInfo(infoTitle);
	
	var parkingTitle = "Parking";
	CreateLayer(parkingTitle);
	AddParking(parkingTitle);

	var accessTitle = "Access";
	CreateLayer(accessTitle);
	AddAccess(accessTitle);



 }

  /**
  *This method creates a layer.
  *@param {String} title Title of the layer
  */
  function CreateLayer(title)
  {

	var layer = new VEShapeLayer();
	layer.SetTitle(title);
	map.AddShapeLayer(layer);
	return layer;

  }

 /**
  *This method shows the layer with
  *the given title
  *@param {String} title Title of the layer
  *@param {Boolean} state Optional flag to
  * 	show or hide layer.
  *		True will show layer, False will hide.
	  */
 function ToggleLayer(title,state)
 {

	var layer = GetLayer(title);

	if(layer != null)
	{
		var hideLayer = layer.IsVisible();
		if(state != null && state != 'undefined')
		{
			hideLayer = !state;
		}

		if(hideLayer)
		{
			layer.Hide();
		}
		else
		{
			layer.Show();
		}


	}

 }

 /**
  *This method gets a layer with
  *the given title
  *@param {String} title Title of the layer
  *@return VEShapeLayer
  */
 function GetLayer(title)
 {
	var layerCount = map.GetShapeLayerCount();
	for(var i = 0; i < layerCount; i++)
	{
		var layer = map.GetShapeLayerByIndex(i);

		if(layer != null && layer.GetTitle() == title)
		{
			return layer;
		}
	}
	return null;
 }



/**
  *This method adds
  *an array of pins.
  *@param title Title of the layer
  */
 function AddParking(title)
{
	var layer = GetLayer(title);


	var pin4 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28705096962522,-6.373915672302261));
	pin4.SetDescription("For more info<br />Click <a href='http://www.thesquaretallaght.com/pages/getting_here.html#' target='_blank'>here</a>" );
	pin4.SetTitle("Square Shopping Centre Parking");
	pin4.SetCustomIcon("<img src='parking.png' />");

	layer.AddShape(pin4);

	var pin5 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28805791904825,-6.368411779403689));
	pin5.SetDescription("For more info<br />Click <a href='http://www.thesquaretallaght.com/pages/getting_here.html#' target='_blank'>here</a>" );
	pin5.SetTitle("Tallaght Parking");
	pin5.SetCustomIcon("<img src='parking.png' />");

	layer.AddShape(pin5);

	

	var pin8 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28780778733046, -6.37031078338624));
	pin8.SetDescription("For more info<br />Click <a href='http://www.thesquaretallaght.com/pages/getting_here.html#' target='_blank'>here</a>" );
	pin8.SetTitle("Square Shopping Centre Parking");
	pin8.SetCustomIcon("<img src='parking.png' />");

	layer.AddShape(pin8);

	var pin9 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28570405750035, -6.369634866714471));
	pin9.SetDescription("For more info<br />Click <a href='http://www.thesquaretallaght.com/pages/getting_here.html#' target='_blank'>here</a>" );
	pin9.SetTitle("Square Shopping Centre Parking");
	pin9.SetCustomIcon("<img src='parking.png' />");

	layer.AddShape(pin9);
	
	var pin22 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28807715988897,-6.3661801815032915));
	pin22.SetDescription("For more info<br />Click <a href='http://www.thesquaretallaght.com/pages/getting_here.html#' target='_blank'>here</a>" );
	pin22.SetTitle("Tallaght Shopping Centre Parking");
	pin22.SetCustomIcon("<img src='parking.png' />");

	layer.AddShape(pin22);
	
	var pin23 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28743579386242,-6.359635591506975));
	pin23.SetDescription("For more info<br />Click <a href='http://www.thesquaretallaght.com/pages/getting_here.html#' target='_blank'>here</a>" );
	pin23.SetTitle("Tallaght Shopping Centre Parking");
	pin23.SetCustomIcon("<img src='parking.png' />");

	layer.AddShape(pin23);



}

/**
  *This method adds
  *an array of pins.
  *@param title Title of the layer
  */
 function AddInfo(title)
{

var layer = GetLayer(title);
	var pin1 = new VEShape(VEShapeType.Pushpin,  new VELatLong(53.28572971336606,-6.373840570449824));


	pin1.SetTitle("Buses serving The Square");
	pin1.SetCustomIcon("<img src=' http://freeflow.ie/bus.png' />");
	pin1.SetDescription("<br />Buses  <a href='http://www.dublinbus.ie/your_journey/viewer.asp?placeName=Tallaght%20Hospital' target='_blank'>More information</a> <br />Check Dublin Bus Website<br />" );
	layer.AddShape(pin1);
	
	var pindual = new VEShape(VEShapeType.Pushpin,  new VELatLong(53.28546674001226,-6.3731056451797325));
	
	pindual.SetTitle("Buses serving The Square");
	pindual.SetCustomIcon("<img src=' http://freeflow.ie/dualway.png' />");
	pindual.SetDescription("<br />Buses  <a href='http://www.dualway.com/311groute.htm'>More information</a> <br />Check Dualway Website<br />" );
	layer.AddShape(pindual);
	
	var pin10 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.29037317133547,-6.3779711723327725));

	pin10.SetDescription("For more info<br />Click <a href='http://www.amnch.ie/' target='_blank'>here</a>" );
	pin10.SetTitle("Adelaide & Meath Hospital");
	pin10.SetCustomIcon("<img src='images/hosp.png' />");

	layer.AddShape(pin10);

	var pin2 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28581950877473,-6.367135047912589));
	pin2.SetDescription("The Tallaght Plaza Hotel.<br />Click <a href='http://www.tallaghtplazahotel.com/' target='_blank'>here</a>" );
	pin2.SetTitle("The Plaza Hotel Tallaght");
	pin2.SetCustomIcon("<img src='images/Plaza.png' />");

	layer.AddShape(pin2);

	var pin3 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.2869291078942, -6.372928619384767));
	pin3.SetDescription("The Square Shopping Centre<br />Click <a href='http://www.thesquaretallaght.com/index2.html' target='_blank'>here</a>" );
	pin3.SetTitle("Shopping at The Square");
	pin3.SetCustomIcon("<img src='images/square.png' />");

	layer.AddShape(pin3);


	var pin6 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.2941680537992,-6.133726537227637));
	pin6.SetDescription("For what is on<br />Click <a href='http://www.paviliontheatre.ie/' target='_blank'>here</a>" );
	pin6.SetTitle("Pavilion Theatre");
	pin6.SetCustomIcon("<img src='pt.png' />");

	layer.AddShape(pin6);
	
	var pin7 = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28805150543276,-6.372263431549075));
	pin7.SetDescription("For more info<br />Click <a href='http://www.luas.ie/red-line.php' target='_blank'>here</a>" );
	pin7.SetTitle("LUAS Tallaght Stop");
	pin7.SetCustomIcon("<img src='LUAS.png' />");

	layer.AddShape(pin7);
	
	var pin7x = new VEShape(VEShapeType.Pushpin,new VELatLong(53.28956509199285,-6.3789153099059925));
	pin7x.SetDescription("For more info<br />Click <a href='http://www.luas.ie/red-line.php' target='_blank'>here</a>" );
	pin7x.SetTitle("LUAS Hospital Stop");
	pin7x.SetCustomIcon("<img src='LUAS.png' />");

	layer.AddShape(pin7x);
}
/**
*This method adds
*an array of pins.
*@param title Title of the layer
*/
function AddAccess(title)
{
	var layer = GetLayer(title);
	var line = new VEShape(VEShapeType.Polyline, [new VELatLong(53.287993782849966, -6.372140049934392),
new VELatLong( 53.28754482676616,-6.3739103078842225),
new VELatLong(53.2872722439851, -6.375101208686843),
new VELatLong(53.287275450851446, -6.376238465309145),
new VELatLong(53.287499930898306,-6.377236247062682),
new VELatLong(53.28824712027229, -6.377885341644292),
new VELatLong(53.28927969523941, -6.3788026571273875),
new VELatLong(53.289985166892,-6.379569768905641),
new VELatLong(53.29093432855303,-6.380621194839463),
new VELatLong(53.29192515387088, -6.3820803165435675),
new VELatLong(53.29499047437155, -6.386189460754396)

]);

	var lineColor = new VEColor(191,0,0,0.6);
	line.SetLineColor(lineColor);

	//Set the line width
	var lineWidth = 6;
	line.SetLineWidth(lineWidth);

	line.HideIcon();

	layer.AddShape(line);
	
	var line1 = new VEShape(VEShapeType.Polyline, [new VELatLong(53.293041007297255,-6.140971183776845),
new VELatLong(53.293053833029276, -6.141647100448615)
]);

	var lineColor = new VEColor(0,0,255,0.6);
	line1.SetLineColor(lineColor);

	//Set the line width
	var lineWidth = 6;
	line1.SetLineWidth(lineWidth);

	line1.HideIcon();

	layer.AddShape(line1);
	
	var line2 = new VEShape(VEShapeType.Polyline, [new VELatLong(53.292316347183174,-6.136068105697637),
new VELatLong(53.293159645171464, -6.135118603706346),
new VELatLong(53.2944486084055, -6.133847236633317),
new VELatLong(53.2943908944656,-6.133434176444995),
new VELatLong(53.2937367976969,-6.131969690322887)
]);

	var lineColor = new VEColor(0,0,255,0.6);
	line2.SetLineColor(lineColor);

	//Set the line width
	var lineWidth = 6;
	line2.SetLineWidth(lineWidth);

	line2.HideIcon();

	layer.AddShape(line2);


}
