// This file adds a new circle overlay to GMaps2
// it is really a many-pointed polygon, but look smooth enough to be a circle.
var CircleOverlay = function(latLng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity) {
    this.latLng = latLng;
    this.radius = radius;
    this.strokeColor = strokeColor;
    this.strokeWidth = strokeWidth;
    this.strokeOpacity = strokeOpacity;
    this.fillColor = fillColor;
    this.fillOpacity = fillOpacity;
}

// Implements GOverlay interface
CircleOverlay.prototype = new GOverlay;

CircleOverlay.prototype.initialize = function(map) {
    this.map = map;
}

CircleOverlay.prototype.clear = function() {
    if(this.polygon != null && this.map != null) {
        this.map.removeOverlay(this.polygon);
    }
}

// Calculate all the points and draw them
CircleOverlay.prototype.redraw = function(force) {
    var d2r = Math.PI / 180;
    circleLatLngs = new Array();
    var circleLat = this.radius * 0.014483;  // Convert statute miles into degrees latitude
    var circleLng = circleLat / Math.cos(this.latLng.lat() * d2r);
    var numPoints = 40;
    
    // 2PI = 360 degrees, +1 so that the end points meet
    for (var i = 0; i < numPoints + 1; i++) { 
        var theta = Math.PI * (i / (numPoints / 2)); 
        var vertexLat = this.latLng.lat() + (circleLat * Math.sin(theta)); 
        var vertexLng = this.latLng.lng() + (circleLng * Math.cos(theta));
        var vertextLatLng = new GLatLng(vertexLat, vertexLng);
        circleLatLngs.push(vertextLatLng); 
    }
    
    this.clear();
    this.polygon = new GPolygon(circleLatLngs, this.strokeColor, this.strokeWidth, this.strokeOpacity, this.fillColor, this.fillOpacity);
    this.map.addOverlay(this.polygon);
}

CircleOverlay.prototype.remove = function() {
    this.clear();
}

CircleOverlay.prototype.containsLatLng = function(latLng) {
    // Polygon Point in poly 
    if(this.polygon.containsLatLng) {
        return this.polygon.containsLatLng(latLng);
    }
}

CircleOverlay.prototype.setRadius = function(radius) {
    this.radius = radius;
}

CircleOverlay.prototype.setLatLng = function(latLng) {
    this.latLng = latLng;
}

function initialize() {
  var map;
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById("map_canvas"));
    map.addControl(new GLargeMapControl());
    
    map.setCenter(new GLatLng(-45.031303, 168.659899), 14);
    
	var accommIcon = new GIcon(G_DEFAULT_ICON);
	accommIcon.image = "http://www.newzealandtravelinsider.com/images/accomm.png";

	var blackIcon = new GIcon(G_DEFAULT_ICON);
	blackIcon.image = "http://www.newzealandtravelinsider.com/images/black05.png";
	blackIcon.iconSize = new GSize(32, 37);

	var blueIcon = new GIcon(G_DEFAULT_ICON);
	blueIcon.image = "http://www.newzealandtravelinsider.com/images/blue04.png";
	blueIcon.iconSize = new GSize(32, 37);

	var orangeIcon = new GIcon(G_DEFAULT_ICON);
	orangeIcon.image = "http://www.newzealandtravelinsider.com/images/orange03.png";
	orangeIcon.iconSize = new GSize(32, 37);

	moHotel0 = { icon:blackIcon };
	moHotel0.title = "Eichardt's Private Hotel Queenstown";
	var h0Marker = new GMarker(new GLatLng(-45.03288, 168.660436), moHotel0);
    map.addOverlay(h0Marker);
    GEvent.addListener(h0Marker, "click", function() {
	    h0Marker.openInfoWindowHtml("<strong>Eichardt's Private Hotel Queenstown</strong><br/><a target='blank' href='http://www.eichardtshotel.co.nz/'>http://www.eichardtshotel.co.nz</a>");
	  });
	                
	moHotel1 = { icon:blackIcon };
	moHotel1.title = "Hotel St Moritz Queenstown";
	var h1Marker = new GMarker(new GLatLng(-45.034207, 168.652968), moHotel1);
    map.addOverlay(h1Marker);
    GEvent.addListener(h1Marker, "click", function() {
	    h1Marker.openInfoWindowHtml('<strong>Hotel St Moritz Queenstown</strong><br/><a target="blank" href="http://www.stmoritz.co.nz/">http://www.stmoritz.co.nz</a>');
	  });

	moHotel2 = { icon:blackIcon };
	moHotel2.title = "Sofitel Queenstown";
	var h2Marker = new GMarker(new GLatLng(-45.031022, 168.659105), moHotel2);
    map.addOverlay(h2Marker);
    GEvent.addListener(h2Marker, "click", function() {
	    h2Marker.openInfoWindowHtml('<strong>Sofitel Queenstown</strong><br/><a target="blank" href="http://www.sofitelqueenstown.com/">http://www.sofitelqueenstown.com</a>');
	  });

	moHotel3 = { icon:blackIcon };
	moHotel3.title = "The Spire Hotel";
	var h3Marker = new GMarker(new GLatLng(-45.032463, 168.661863), moHotel3);
    map.addOverlay(h3Marker);
    GEvent.addListener(h3Marker, "click", function() {
	    h3Marker.openInfoWindowHtml('<strong>The Spire Hotel</strong><br/><a target="blank" href="http://www.thespirehotels.com/">http://www.thespirehotels.com</a>');
	  });

	moHotel4 = { icon:blueIcon };
	moHotel4.title = "Crowne Plaza Queenstown";
	var h4Marker = new GMarker(new GLatLng(-45.033262, 168.656977), moHotel4);
    map.addOverlay(h4Marker);
    GEvent.addListener(h4Marker, "click", function() {
	    h4Marker.openInfoWindowHtml('<strong>Crowne Plaza Queenstown</strong><br/><a target="blank" href="http://www.crownplaza.com/">http://www.crownplaza.com</a>');
	  });

	moHotel5 = { icon:blueIcon };
	moHotel5.title = "Heritage Queenstown";
	var h5Marker = new GMarker(new GLatLng(-45.037854, 168.64224), moHotel5);
    map.addOverlay(h5Marker);
    GEvent.addListener(h5Marker, "click", function() {
	    h5Marker.openInfoWindowHtml('<strong>Heritage Queenstown</strong><br/><a target="blank" href="http://www.heritagehotels.co.nz/">http://www.heritagehotels.co.nz</a>');
	  });

	moHotel6 = { icon:blueIcon };
	moHotel6.title = "Millennium Hotel Queenstown";
	var h6Marker = new GMarker(new GLatLng(-45.033744, 168.667002), moHotel6);
    map.addOverlay(h6Marker);
    GEvent.addListener(h6Marker, "click", function() {
	    h6Marker.openInfoWindowHtml('<strong>Millennium Hotel Queenstown</strong><br/><a target="blank" href="http://www.millenniumhotels.co.nz/millenniumqueenstown">http://www.millenniumhotels.co.nz/millenniumqueenstown</a>');
	  });

	moHotel7 = { icon:blueIcon };
	moHotel7.title = "Copthorne Hotel & Resort Queenstown Lakefront";
	var h7Marker = new GMarker(new GLatLng(-45.03429, 168.666315), moHotel7);
    map.addOverlay(h7Marker);
    GEvent.addListener(h7Marker, "click", function() {
	    h7Marker.openInfoWindowHtml('<strong>Copthorne Hotel &amp; Resort Queenstown Lakefront</strong><br/><a target="blank" href="http://www.millenniumhotels.co.nz/copthornequeenstownlakefront">http://www.millenniumhotels.co.nz/copthornequeenstownlakefront</a>');
	  });

	moHotel8 = { icon:blueIcon };
	moHotel8.title = "Novotel Queenstown Lakeside";
	var h8Marker = new GMarker(new GLatLng(-45.03332, 168.66241), moHotel8);
    map.addOverlay(h8Marker);
    GEvent.addListener(h8Marker, "click", function() {
	    h8Marker.openInfoWindowHtml('<strong>Novotel Queenstown Lakeside</strong><br/><a target="blank" href="http://www.accorhotels.com.au/">http://www.accorhotels.com.au</a>');
	  });

	moHotel9 = { icon:blueIcon };
	moHotel9.title = "Rydges Lakeland Resort Queenstown";
	var h9Marker = new GMarker(new GLatLng(-45.035458, 168.651488), moHotel9);
    map.addOverlay(h9Marker);
    GEvent.addListener(h9Marker, "click", function() {
	    h9Marker.openInfoWindowHtml('<strong>Rydges Lakeland Resort Queenstown</strong><br/><a target="blank" href="http://www.rydges.com/queenstown">http://www.rydges.com/queenstown</a>');
	  });

	moHotel10 = { icon:blueIcon };
	moHotel10.title = "Scenic Suites Queenstown";
	var h10Marker = new GMarker(new GLatLng(-45.032501, 168.664706), moHotel10);
    map.addOverlay(h10Marker);
    GEvent.addListener(h10Marker, "click", function() {
	    h10Marker.openInfoWindowHtml('<strong>Scenic Suites Queenstown</strong><br/><a target="blank" href="http://www.scenichotelgroup.co.nz/">http://www.scenichotelgroup.co.nz</a>');
	  });

	moHotel11 = { icon:orangeIcon };
	moHotel11.title = "Tanoa Aspen on Queenstown";
	var h11Marker = new GMarker(new GLatLng(-45.03893, 168.633506), moHotel11);
    map.addOverlay(h11Marker);
    GEvent.addListener(h11Marker, "click", function() {
	    h11Marker.openInfoWindowHtml('<strong>Tanoa Aspen on Queenstown</strong><br/><a target="blank" href="http://www.queenstownhotel.com/">http://www.queenstownhotel.com</a>');
	  });

	moHotel12 = { icon:orangeIcon };
	moHotel12.title = "Sherwood Manor Hotel Queenstown";
	var h12Marker = new GMarker(new GLatLng(-45.023483, 168.697861), moHotel12);
    map.addOverlay(h12Marker);
    GEvent.addListener(h12Marker, "click", function() {
	    h12Marker.openInfoWindowHtml('<strong>Sherwood Manor Hotel Queenstown</strong><br/><a target="blank" href="http://www.sherwoodmanorhotel.co.nz/">http://www.sherwoodmanorhotel.co.nz</a>');
	  });

	moHotel13 = { icon:orangeIcon };
	moHotel13.title = "Heartland Hotel Queenstown";
	var h13Marker = new GMarker(new GLatLng(-45.032504, 168.664716), moHotel13);
    map.addOverlay(h13Marker);
    GEvent.addListener(h13Marker, "click", function() {
	    h13Marker.openInfoWindowHtml('<strong>Heartland Hotel Queenstown</strong><br/><a target="blank" href="http://www.scenichotelgroup.co.nz/">http://www.scenichotelgroup.co.nz</a>');
	  });

	moHotel14 = { icon:orangeIcon };
	moHotel14.title = "Mercure Resort Queenstown";
	var h14Marker = new GMarker(new GLatLng(-45.038462, 168.638786), moHotel14);
    map.addOverlay(h14Marker);
    GEvent.addListener(h14Marker, "click", function() {
	    h14Marker.openInfoWindowHtml('<strong>Mercure Resort Queenstown</strong><br/><a target="blank" href="http://www.accorhotels.co.nz/mercureresort-queenstown">http://www.accorhotels.co.nz/mercureresort-queenstown</a>');
	  });

	moHotel15 = { icon:orangeIcon };
	moHotel15.title = "Goldridge Resort";
	var h15Marker = new GMarker(new GLatLng(-45.022895, 168.699174), moHotel15);
    map.addOverlay(h15Marker);
    GEvent.addListener(h15Marker, "click", function() {
	    h15Marker.openInfoWindowHtml('<strong>Goldridge Resort</strong><br/><a target="blank" href="http://www.goldridgeresort.co.nz/">http://www.goldridgeresort.co.nz</a>');
	  });

	moHotel16 = { icon:orangeIcon };
	moHotel16.title = "Kingsgate Hotel Terraces Queenstown";
	var h16Marker = new GMarker(new GLatLng(-45.034169, 168.670448), moHotel16);
    map.addOverlay(h16Marker);
    GEvent.addListener(h16Marker, "click", function() {
	    h16Marker.openInfoWindowHtml('<strong>Kingsgate Hotel Terraces Queenstown</strong><br/><a target="blank" href="http://www.millenniumhotels.co.nz/kingsgatequeenstown">http://www.millenniumhotels.co.nz/kingsgatequeenstown</a>');
	  });

	moHotel17 = { icon:accommIcon };
	moHotel17.title = "Peppers Beacon";
	var h17Marker = new GMarker(new GLatLng(-45.035882, 168.650866), moHotel17);
    map.addOverlay(h17Marker);
    GEvent.addListener(h17Marker, "click", function() {
	    h17Marker.openInfoWindowHtml('<strong>Peppers Beacon</strong><br/><a target="blank" href="http://www.peppersbeacon.co.nz/">http://www.peppersbeacon.co.nz</a>');
	  });

	moHotel18 = { icon:accommIcon };
	moHotel18.title = "Central Ridge Boutique Hotel";
	var h18Marker = new GMarker(new GLatLng(-45.033517, 168.664513), moHotel18);
    map.addOverlay(h18Marker);
    GEvent.addListener(h18Marker, "click", function() {
	    h18Marker.openInfoWindowHtml('<strong>Central Ridge Boutique Hotel</strong><br/><a target="blank" href="http://www.centralridge.co.nz/">http://www.centralridge.co.nz</a>');
	  });

	moHotel19 = { icon:accommIcon };
	moHotel19.title = "Oaks Shores";
	var h19Marker = new GMarker(new GLatLng(-45.029786, 168.686163), moHotel19);
    map.addOverlay(h19Marker);
    GEvent.addListener(h19Marker, "click", function() {
	    h19Marker.openInfoWindowHtml('<strong>Oaks Shores</strong><br/><a target="blank" href="http://www.theoaksgroup.com.au/">http://www.theoaksgroup.com.au</a>');
	  });

	moHotel20 = { icon:accommIcon };
	moHotel20.title = "Oaks Club Resort";
	var h20Marker = new GMarker(new GLatLng(-45.034078, 168.678718), moHotel20);
    map.addOverlay(h20Marker);
    GEvent.addListener(h20Marker, "click", function() {
	    h20Marker.openInfoWindowHtml('<strong>Oaks Club Resort</strong><br/><a target="blank" href="http://www.theoaksgroup.com.au/">http://www.theoaksgroup.com.au</a>');
	  });

	moHotel21 = { icon:accommIcon };
	moHotel21.title = "The Rees Hotel & Luxury Apartments";
	var h21Marker = new GMarker(new GLatLng(-45.028377, 168.687879), moHotel21);
    map.addOverlay(h21Marker);
    GEvent.addListener(h21Marker, "click", function() {
	    h21Marker.openInfoWindowHtml('<strong>The Rees Hotel &amp; Luxury Apartments</strong><br/><a target="blank" href="http://www.therees.co.nz/">http://www.therees.co.nz</a>');
	  });

	var circleRadius2 = 1.86; //miles = 3 km
	circle2 = new CircleOverlay(map.getCenter(), circleRadius2, "#004EFF", 1, 0.15, "#004EFF", 0.15);	
	map.addOverlay(circle2);

	var circleRadius1 = 1.24; //miles = 2 km
	circle1 = new CircleOverlay(map.getCenter(), circleRadius1, "#FFFC00", 1, 0.4, "#FFFC00", 0.4);	
	map.addOverlay(circle1);

	var circleRadius = 0.62; //miles = 1 km
	circle = new CircleOverlay(map.getCenter(), circleRadius, "#0CFF00", 1, 0.25, "#0CFF00", 0.25);	
	map.addOverlay(circle);

    map.setMapType(G_NORMAL_MAP);        
  
	} 
}

