var groupIcon = new GIcon(G_DEFAULT_ICON);
groupIcon.iconSize = new GSize(26,26);
groupIcon.iconAnchor = new GPoint(13,13);
groupIcon.shadow = "http://www.devonfhs.org.uk/images/marker/group_shadow.png";
groupIcon.shadowSize = new GSize(34,34);

var greenPushPin = new GIcon(G_DEFAULT_ICON);
greenPushPin.image = "http://maps.google.com/mapfiles/ms/micons/grn-pushpin.png";
greenPushPin.iconSize = new GSize(32,32);
greenPushPin.iconAnchor = new GPoint(9,31);
greenPushPin.shadow = "http://maps.google.com/mapfiles/ms/micons/pushpin_shadow.png";
greenPushPin.shadowSize = new GSize(59,32);

function makeGroupIcon(name)
{
    var icon = new GIcon(groupIcon);
    icon.image = "http://www.devonfhs.org.uk/images/bullet/group_" + name + ".gif";
    return icon;
}
var groupIconExeter = makeGroupIcon("e");
var groupIconPlymouth = makeGroupIcon("p");
var groupIconNorth = makeGroupIcon("n");
var groupIconSouth = makeGroupIcon("s");
var groupIconTreeHouse = makeGroupIcon("th");

function showmap(sMap,x,y,type)
{
	var theDiv = document.getElementById("map" + sMap);
	theDiv.className = "mapvisible";

	//<![CDATA[

	var map1 = new GMap2(document.getElementById("map" + sMap));
    map1.addMapType(G_PHYSICAL_MAP);
	map1.addControl(new GSmallMapControl());
    map1.addControl(new GHierarchicalMapTypeControl());
    var nZoom;
//    var mapType;
    if (type == 'p')
    {
        nZoom = 8;
        mapType = G_PHYSICAL_MAP;
    }
    else
    {
        nZoom = 15;
        mapType = G_NORMAL_MAP;
    }
    map1.setCenter(new GLatLng(y,x), nZoom, mapType);

    markerOptions = { icon:greenPushPin, clickable:false };
    map1.addOverlay(new GMarker(map1.getCenter(),markerOptions));
    //]]>
}

function addGroupIcon(map,icn,latlng,group,address,times)
{
    markerOptions = { icon:icn, clickable:true };

    var marker = new GMarker(latlng,markerOptions);
    map.addOverlay(marker);

    GEvent.addListener(marker,"click",function() {
        if (map.getZoom() == 16)
        {
            map.setCenter(new GLatLng(50.708634400828224, -3.84521484375), 8);
            marker.closeInfoWindow();
        }
        else
        {
            map.setCenter(marker.getLatLng(), 16);
            windowOptions = {maxWidth:200};
            marker.openInfoWindowHtml('<div align="left"><span class="emph">' + group + '</span><br><strong>' + address  + '</strong><br>' + times + '</div>',windowOptions);
        }
    });
}

var hotel = new GIcon(G_DEFAULT_ICON);
hotel.image = "http://www.devonfhs.org.uk/images/marker/hotel.png";
hotel.iconSize = new GSize(16,16);
hotel.iconAnchor = new GPoint(7,7);
hotel.shadow = null;

var busStop = new GIcon(G_DEFAULT_ICON);
busStop.image = "http://www.devonfhs.org.uk/images/marker/busstop.png";
busStop.iconSize = new GSize(15,15);
busStop.iconAnchor = new GPoint(7,7);
busStop.shadow = null;

var carPark = new GIcon(G_DEFAULT_ICON);
carPark.image = "http://www.devonfhs.org.uk/images/marker/carpark.png";
carPark.iconSize = new GSize(16,16);
carPark.iconAnchor = new GPoint(8,8);
carPark.shadow = null;

var TIC = new GIcon(G_DEFAULT_ICON);
TIC.image = "http://www.devonfhs.org.uk/images/marker/info.png";
TIC.iconSize = new GSize(16,16);
TIC.iconAnchor = new GPoint(8,8);
TIC.shadow = null;

var railwayStn = new GIcon(G_DEFAULT_ICON);
railwayStn.image = "http://www.devonfhs.org.uk/images/marker/rail.gif";
railwayStn.iconSize = new GSize(14,11);
railwayStn.iconAnchor = new GPoint(7,6);
railwayStn.shadow = null;

function addHotel(map,latlng,hotelName,URL)
{
    var marker = new GIcon(hotel);

    var markerOptions = { icon:marker, clickable:true };

	var hotelMarker = new GMarker(latlng,markerOptions);
	map.addOverlay(hotelMarker);
    var hotelHtml = '';
    GEvent.addListener(hotelMarker,"click",function() {
        var windowOptions = {maxWidth:300};
        hotelMarker.openInfoWindowHtml('<div align="left" style="font-size:small">' +
                                         '<strong>' + hotelName + '</strong>' +
                                         '<br>' +
                                         '<a href="' + URL + '">' + URL + '</a>' +
                                         '</div>',windowOptions);
    });
}
function addBusStop(map,latlng,busStopName,buses)
{
    var marker = new GIcon(busStop);

    var markerOptions = { icon:marker, clickable:(arguments.length > 2) };

	var busStopMarker = new GMarker(latlng,markerOptions);
	map.addOverlay(busStopMarker);

	if (arguments.length > 2)
	{
		var busHtml = '';
		var b;
		for (b = 0; b < buses.length; b++)
		{
			busHtml += '<br>';
			busHtml += '<img src=\"images/marker/bus_' + buses[b].split(":")[0] + '.gif">';
			busHtml += ' ' + buses[b].split(":")[1];
		}
		GEvent.addListener(busStopMarker,"click",function() {
			var windowOptions = {maxWidth:300};
			busStopMarker.openInfoWindowHtml('<div align="left" style="font-size:small">' +
											 '<strong>Buses to &amp; from ' + busStopName + '</strong>' +
											 busHtml +
											 '<div style="text-align:center;font-size:small;font-style:italic">' +
											 'Please visit <a href="http://www.stagecoachbus.com/southwest">Stagecoach South West</a> for up to date information' +
											 '</div>' +
											 '</div>',windowOptions);
		});
	}
}

function addCarPark(map,latlng,parkID,parkName)
{
    var marker = new GIcon(carPark);

    var markerOptions = { icon:marker, clickable:(arguments.length > 2) };

	var parkMarker = new GMarker(latlng,markerOptions);
	map.addOverlay(parkMarker);

	if (arguments.length > 2)
	{
		GEvent.addListener(parkMarker,"click",function() {
			var windowOptions = {maxWidth:200};
			parkMarker.openInfoWindowHtml('<div align="center">' +
										  '<a href="http://www.exeter.gov.uk/index.aspx?articleid=' + parkID + '">' +
										  '<img src="http://www.devonfhs.org.uk/images/marker/ecclogo.gif" border="0">' +
										  '<br>' +
										  parkName + ' Car Park</a>' +
										  '</div>',windowOptions);
		});
	}
}

function addCathedral(map)
{
    var cathedral = new GIcon(G_DEFAULT_ICON);
    cathedral.image = "http://www.devonfhs.org.uk/images/marker/cathedral.png";
    cathedral.iconSize = new GSize(57,44);
    cathedral.iconAnchor = new GPoint(28,22);
    cathedral.shadow = null;
    var marker = new GIcon(cathedral);

    markerOptions = { icon:marker, clickable:false };

    map.addOverlay(new GMarker(new GLatLng(50.72251287276055, -3.529958724975586),markerOptions));
}

function addExeterTIC(map)
{
    var marker = new GIcon(TIC);

    markerOptions = { icon:marker, clickable:true };

    var TICmarker = new GMarker(new GLatLng(50.724642,-3.525785),markerOptions);
    map.addOverlay(TICmarker);

    GEvent.addListener(TICmarker,"click",function() {
        var windowOptions = {maxWidth:200};
        TICmarker.openInfoWindowHtml('<div align="left">' +
                                      '<a href="http://www.exeter.gov.uk/index.aspx?articleid=9786">' +
                                      'Exeter Visitor Information</a><br>' +
                                      'Dix&rsquo;s Field<br>' +
                                      'Exeter<br>' +
                                      'Devon<br>' +
                                      'EX1 1GF<br>' +
                                      '01392 665700<br>' +
                                      '<img src="http://www.devonfhs.org.uk/images/bullet/postal.gif" border="0" alt="email"> ' +
                                      '<a href="mailto:evit@exeter.gov.uk">evit@exeter.gov.uk</a>' +
                                      '</div>',windowOptions);
    });
}