         var map = null;
             var pinID = 1;
			 var routeSteps = new Array();
		  var routeInfo = new Array();
		  
         function GetMap()
         {
            map = new VEMap('myMap');
			map.onLoadMap = function(){addPushPins(); };//AddPin();
			
            map.LoadMap(new VELatLong(-40.429313, 175.859709), 6); 
			map.AttachEvent("onclick", PixelClick);
         }
		 
		  function PixelClick(e)
         {
            var x = e.mapX;
            var y = e.mapY;
            pixel = new VEPixel(x, y);
            var LL = map.PixelToLatLong(pixel);
			//Pixel X: " + x + " | Pixel Y: " + y + "<br /> LatLong: " + 
          // Element.update('showpoints', $('showpoints').text+'<br>'+LL);
         }

		 
		 function showRoute(loc){
		 map.GetRoute(loc+',New Zealand',
                     'Mangatainoka,New Zealand',
                  VEDistanceUnit.Kilometers, 
				  VERouteType.Quickest,
				  onGotRoute2);
			
		 
		 }
		 
		 function FindLoc(loc){
		 try {
		 Element.update('showpoints', "Finding ...");
		if (loc == "tui stash"){
		 map.Find(null, "Matata, New Zealand", null, null, null, null, true, true, null, true, Found);
		}else{
			map.Find(null, loc+", New Zealand", null, null, null, null, true, true, null, true, Found);
			}
		 }
		 catch(e){alert(e.message);
		 }
		 }
		 
		 function Found(){
		 Element.update('showpoints', "<a href='javascript:ResetMap();'>Reset Map</a>");
		 }
		 
		 function ResetMap(){
		 map.SetZoomLevel(6);
		 }
		 
         function onGotRoute(route)
         {
		 routeInfo = new Array();
		 routeI = 1
           var routeinfo="";
		   
            routeinfo+="You are ";
            routeinfo+=   route.Itinerary.Distance+" ";
            routeinfo+=   route.Itinerary.DistanceUnit+" from the Tui Brewery by road<br>";
            
            var steps="";
            var len = route.Itinerary.Segments.length;
               for(var i = 0; i < len ;i++)
               {
			   routeSteps.push(route.Itinerary.Segments[i].LatLong)
                  steps+=route.Itinerary.Segments[i].Instruction+" -- (";
                  steps+=route.Itinerary.Segments[i].Distance+") ";
                  steps+=route.Itinerary.DistanceUnit+"<br>";
				  routeInfo.push(steps)
				  steps = "";
               }
           // routeinfo+="Steps:\n"+steps;
           // document.getElementById('routeinfo').innerHTML = routeinfo;
			//alert(route.EndLocation.LatLong); 
			//map.SetCenterAndZoom(route.StartLocation.LatLong, 12);
			//PanMap(route.StartLocation.LatLong);
		//	alert(routeSteps.join());
		//	followRoute();
		//Element.show('follow')
		//Element.update('routeinfo', routeinfo)
         }
		 
		 var routeI = 1
		 
		 function followRoute(){
		 
		 //for (var i = 0;i < routeSteps.length;i++){
		 if (routeI < routeSteps.length){
		 map.PanToLatLong(routeSteps[routeI]);
		 Element.update('routeinfo', routeInfo[routeI])
		 $('followButt').value = 'Step '+routeI+' of '+routeSteps.length+'.'
		 routeI++
		 }else{
		  Element.update('routeinfo', 'YAY your here!')
		 }
		// }
		 }
		 
		  function onGotRoute2(route)        
		   { 
		
		    var routeinfo='<div style="float:right"><a href="javascript:void[0];" onclick="Element.hide(\'mapOverlay\')">CLOSE INFO</a></div> Route info:<br /><br />';
			routeinfo+="You are "; 
			routeinfo+=   route.Itinerary.Distance+" "; 
			 routeinfo+=   route.Itinerary.DistanceUnit+" from the Tui Brewery<br/>"; 
			 
			    var steps="";
				var len = route.Itinerary.Segments.length;
				for(var i = 0; i < len ;i++){ 
				 steps+=route.Itinerary.Segments[i].Instruction+" -- (";
				 steps+=route.Itinerary.Segments[i].Distance+") ";
				 steps+=route.Itinerary.DistanceUnit+"<br />"; 
				 } 
		  routeinfo+="Steps:\n"+steps; 
		 Element.show('routeinfo')
		  Element.update('mapOverlay',routeinfo); 
		  Element.show('mapOverlay')        }
		 
		 
		    function AddPin()        {              
			var pin = new VEPushpin(
			 pinID, new VELatLong(-40.429313, 175.859709), 'upimg/yr_pin.png', '','<div style=tui_yr><img src=\"upimg/yr_pin_bg.jpg\"><div  id=\"tui_yr_l1\">Where is this</div><div  id=\"tui_yr_l2\">Billboard</div></div>','iconStyle',               'titleSytle',               'detailsStyle' );            
			 map.AddPushpin(pin);           
			  pinID++;        
			   }
			   
			   function PanMap(x,y,latlong)         {
			               if (x!=null & y!=null)        
						       {              
							    map.Pan(x,y);            }            
								else if (latlong!=null)           
								 {  
								  map.PanToLatLong(latlong);
								   } 
					 }
			   
			   function addPushPins(){
	data = [
{lat: -36.7500260203929,long: 174.728879928588, locationtxt: 'Pass\'n Punt- Mairangi Bay ', yr1: 'You gotta give those Aussies credit.', yr2:''},

{lat: -36.945333,long: 174.844803, locationtxt: '392 Great South Road, Otahuhu', yr1: 'There\'s room for two under my umbrella bro.', yr2:''},


{lat: -36.8958902985926,long: 174.807243347168, locationtxt: 'Southern Motorway', yr1: 'Leak is fixed, back to BP now.', yr2:''},
{lat: -36.9581053058405,long: 174.853119850158, locationtxt: 'Waitemata Brewery- Otahuhu ', yr1: 'You gotta give those Aussies credit.', yr2:''},






{lat: -39.4735041741752,long: 176.876578330993, locationtxt: 'Liquorland Napier- From Airport ', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -39.4735041741752,long: 176.876578330993, locationtxt: 'Liquorland Napier- To Airport ', yr1: 'There\'s room for two under my umbrella bro.', yr2:''},
{lat: -39.5830686236587,long: 176.916532516479, locationtxt: 'Clive Glass, Napier ', yr1: 'That de Villers guy has a point.', yr2:''},
{lat: -39.6401324250234,long: 176.847610473632, locationtxt: 'Hastings ', yr1: 'You gotta give those Aussies credit.', yr2:''},

{lat: -39.9504113893152,long: 175.055294036865, locationtxt: 'The Mill - Wanganui ', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -39.6757486392744,long: 175.797386169433, locationtxt: 'Taihape (Woolsheds)  ', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -39.0274521323745,long: 177.418899536132, locationtxt: 'Wairoa ', yr1: 'You gotta give those Aussies credit.', yr2:''},





{lat: -41.5118552328428,long: 173.952884674072, locationtxt: 'Blenheim', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -43.9020978786627,long: 171.749267578125, locationtxt: 'Ashburton', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -43.5583763785345,long: 172.709627151489, locationtxt: 'Ferrymead (Private) ', yr1: 'Leak is fixed, back to BP now.', yr2:''},


{lat: -43.5095302609166,long: 172.722244262695, locationtxt: 'New Brighton, Beresford Street', yr1: 'That de Villers guy has a point.', yr2:''},

{lat: -44.3556460271974,long: 171.238162302935, locationtxt: 'Doncaster Tavern, Timaru ', yr1: 'That de Villers guy has a point.', yr2:''},

{lat: -45.8677500206891,long: 170.513756275177, locationtxt: 'Leith Street Liquor #1', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -45.8677500206891,long: 170.513756275177, locationtxt: 'Leith Street Liquor #2  ', yr1: 'There\'s room for two under my umbrella bro.', yr2:''},


{lat: -46.1396417745279,long: 168.325653076171, locationtxt: 'Winton ', yr1: 'That de Villers guy has a point ', yr2:''},
{lat: -37.8856927181834,long: 176.745300292968, locationtxt: 'Hi Way Liquor Matata', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -41.282991,long: 173.247372, locationtxt: '20 Muritai Street, Tahunanui, Nelson', yr1: 'That de Villers guy has a point.', yr2:''},
{lat: -40.952411,long: 175.642258, locationtxt: 'Cornwall Street Masterton', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -40.952016,long: 175.655921, locationtxt: 'Chapel Street Masterton', yr1: 'There\'s room for two under my umbrella bro.', yr2:''},
{lat: -40.422558,long: 175.865541, locationtxt: 'Tui Brewery 1', yr1: 'You gotta give those Aussies credit.', yr2:''},
{lat: -40.422558,long: 175.86554, locationtxt: 'Tui Brewery 2', yr1: 'There\'s room for two under my umbrella bro.', yr2:''},
{lat: -40.422558,long: 175.865545, locationtxt: 'Tui Brewery 3', yr1: 'That de Villers guy has a point.', yr2:''}
];
			 
			  for (var i = 0; i < data.length; i++){
			  addCustomInfo(data[i].lat, data[i].long, data[i].locationtxt, data[i].yr1,data[i].yr2);
			  }
			  
			//addJimmy();
			   }

function addJimmy(){
//	,{lat: -42.7147321853946,long: 170.88134765625003, locationtxt: 'Click here for Jimmy', yr1: 'There\'s a Playboy channel?', yr2:''}
	
	addCustomInfoJimmy(-42.7147321853946, 170.88134765625003, '<a href="http://www.tui.co.nz/tuipop.asp?a=entercomp&compid=79" id="popjim" onclick="openModal(this.id); return false;">Click here</a> or on Jimmy to enter', '','');
	}
	
function addCustomInfoJimmy(lat, long, location, yr1,yr2){

var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,long));
pin.SetTitle(location);

var infobox = '<div style="z-index:90;"></div>';
   
map.ClearInfoBoxStyles();
var icon = "<img src=\"/upimg/yr_pin.png\">";
var spec = new VECustomIconSpecification();
spec.CustomHTML = icon;
pin.SetCustomIcon(spec);
pin.SetDescription(infobox);
map.AddShape(pin);
}
			   
function addCustomInfo(lat, long, location, yr1,yr2){

var pin = new VEShape(VEShapeType.Pushpin, new VELatLong(lat,long));
pin.SetTitle(location);
var infobox = "<div class=tui_yr  style='z-index:90;color:#ffffff;'><div class=\"tui_yr _l1\"  style='z-index:99;width:190px; color:#ffffff; padding-top:60px;padding-left:10px;padding-bottom:5px;height:80px;'>"+yr1+"</div><div  class=\"tui_yr_l2\" style='z-index:99;width:190px; color:#ffffff'>"+yr2+"</div></div>";
map.ClearInfoBoxStyles();
var icon = "<img src=\"/upimg/yr_pin.png\">";
var spec = new VECustomIconSpecification();
spec.CustomHTML = icon;
pin.SetCustomIcon(spec);
pin.SetDescription(infobox);
map.AddShape(pin);

			   }
			   
			   
