//*******************************************************************
// Login Service JavaScript Class Def. & Variable Declaration.
//
//			// (c) 2000-2004 Kappa Solutions Ltd.
//*******************************************************************
//	This class contains utility methods to determine whether a user 
//  is logged in etc. 
//*******************************************************************

function Sections()
{
	this.points = [
{name:"Bristol &amp; West Section",place:"Pill Memorial Club",town:"Easton in Gordano",postcode:"BS20 0DH",web:"www.arocbriswest.co.uk/",lat:51.480274, lng:-2.689826}
,{name:"Central &amp; East Midlands Section",place:"The George and Dragon",town:"Thringstone",postcode:"LE67 8UH",web:"www.aroc-uk.com/cemids/",lat:52.7597, lng:-1.3746}
,{name:"Cornish Section",place:"Regular meeting place varies",town:"",postcode:"",web:"www.aroc-uk.com/cornwall/",lat:50.368241, lng:-4.971313}
,{name:"Cotswold Section",place:"Merrymouth Inn",town:"Bet Stow &amp; Burford",postcode:"OX76HR",web:"www.aroc-uk.com/cotswolds/",lat:51.865137, lng:-1.66297}
,{name:"Cumbria &amp; Borders Section",place:"The Farmers Inn",town:"Clarencefield",postcode:"DG1 4NF",web:"www.aroc-uk.com/cumbria-borders/",lat:55.002592, lng:-3.420492}
,{name:"Derbyshire Section",place:"Elmtree Inn",town:"Elmton",postcode:"S80 4LS",web:"www.arocderbyshire.com/",lat:53.254944, lng:-1.245918}
,{name:"Devon Section",place:"The Ley Arms",town:"Kenn",postcode:"EX6 7UW",web:"www.aroc-uk.com/devon/",lat:50.686018, lng:-3.56781}
,{name:"East Anglian Section",place:"Regular meeting place varies",town:"",postcode:"",web:"www.aroc-uk.com/east-anglia/",lat:52.385658, lng:1.038208}
,{name:"Essex Section",place:"Ashwells Sports and Country Club",town:"Bentley",postcode:"CM15 9SE",web:"www.aroc-uk.com/essex/",lat:51.64853, lng:0.273392}
,{name:"Goodwood Section",place:"The Fox and Hounds",town:"Funtington",postcode:"PO18 9LL",web:"www.aroc-uk.com/goodwood/",lat:50.8688656523148, lng:-0.865044593811035}
,{name:"Herts &amp; South Beds Section",place:"The Colney Fox",town:"London Colney",postcode:"AL2 1BL?",web:"www.aroc-uk.com/hertsandsouthbeds/",lat:51.721392, lng:-0.28513}
,{name:"Kent And East Sussex Section",place:"The Moat",town:"Wrotham",postcode:"TN15 7RR",web:"www.arockes.org.uk",lat:51.2733994, lng:0.2448366}
,{name:"Lancashire Section",place:"Myerscough Arms",town:"Balderstone",postcode:"BB2 7LE",web:"www.aroc-uk.com/lancs/",lat:53.773624, lng:-2.580543}
,{name:"Lincolnshire Section",place:"The Red Lion Inn",town:"Redbourne",postcode:"DN21 4QR",web:"www.aroc-uk.com/lincs/",lat:53.486324, lng:-0.537195}
,{name:"London Section",place:"The Harcourt Arms",town:"London ",postcode:"W1 H",web:"www.aroc-uk.com/london/",lat:51.519813, lng:-0.164537}
,{name:"North East Section",place:"Ramside Hall Hotel",town:"Durham",postcode:"DH1 1TD",web:"www.aroc-uk.com/northeast/",lat:54.813348, lng:-1.511993}
,{name:"North West Section",place:"The Whipping Stocks",town:"Over Peover",postcode:"WA16 9EX",web:"www.aroc-uk.com/north-west/",lat:53.262543, lng:-2.338285}
,{name:"Scottish Section (North)",place:"Northern Lights",town:"Hatton of Fintray",postcode:"AB21 0YG",web:"www.alfascot.com/",lat:57.237683, lng:-2.265814}
,{name:"Scottish Section (South)",place:"Windlestrae Hotel",town:"Kinross",postcode:"KY13 8AS",web:"www.alfascot.com/",lat:56.192189, lng:-3.387909}
,{name:"Somerset Section",place:"The Half Moon",town:"Stoke St Mary",postcode:"TA3 5BY",web:"www.aroc-uk.com/somerset/",lat:50.995612, lng:-3.050144}
,{name:"South Midlands Section",place:"The Aviator",town:"Sywell Aerodrome",postcode:"NN6 0BN?",web:"www.aroc-uk.com/southmidlands/",lat:52.300673, lng:-0.791897}
,{name:"South Wales Section",place:"No regular meeting place.",town:"",postcode:"",web:"www.aroc-uk.com/south-wales/",lat:51.514512, lng:-3.682823}
,{name:"Surrey Section",place:"The Plough",town:"Bletchingley",postcode:"RH1 4PE?",web:"www.aroc-uk.com/surrey/",lat:51.25504, lng:-0.072784}
,{name:"Central Sussex Section",place:"Jack and Jill",town:"Clayton",postcode:"BN6 9PD",web:"www.aroc-uk.com/central-sussex/",lat:50.9130995158021, lng:-0.154581069946289}
,{name:"Thames Valley Section",place:"The Bird in Hand",town:"Knowl Hill",postcode:"RG10 9UP",web:"www.aroc-uk.com/thamesvalley/",lat:51.502797, lng:-0.822374}
,{name:"Wessex Section",place:"The St Leonards Hotel",town:"St Leonards ",postcode:"BH24 2NP?",web:"www.aroc-uk.com/wessex/",lat:50.832397, lng:-1.837292}
,{name:"West Midlands Section",place:"Lyndon House Hotel",town:"Walsall",postcode:"WS1 2HA?",web:"www.aroc-uk.com/west-mids/",lat:52.583899, lng:-1.976402}
,{name:"West Wiltshire Section",place:"The Bath Arms",town:"Crockerton",postcode:"BA12 8AJ",web:"www.aroc-uk.com/west-wilts/",lat:51.179056, lng:-2.197014}
,{name:"Yorkshire Section",place:"The Angel &amp; White Horse",town:"Tadcaster",postcode:"LS24 9AW?",web:"www.aroc-yorkshire.co.uk ",lat:53.884524, lng:-1.260767}
,{name:"Ireland",place:"Regular meeting place varies",town:"",postcode:"",web:"www.aroc-uk.com/ireland/",lat:53.344608, lng:-6.252766}
]
}

Sections.prototype.getMarkerHtml = function(index)
{
	var html = "";
	var point = this.points[index];
	if (point.postcode)
	{
	    html = ['<b>', point.name, '</b><br/>', 
                 point.place, '<br/>', 
				 point.town, '<br/>', 
                 point.postcode,'<br/><br/>', 
                 '<a target="_blank" title="Get directions to section meeting"',
                 'href="http://maps.google.com/maps?z=10&saddr=&daddr=',
                 this.formatAddress(index), '">Get directions</a><br/>', 
                 '<a target="_blank" title="Go to section web site" href="http://', point.web, '">Go to web site</a>'].join('');
	}
	else
	{
	    html = ['<b>', point.name, '</b><br/>', 
                 point.place, '<br/>', 
				 point.town, '<br/>', 
                 point.postcode,'<br/><br/>',
                 '<a target="_blank" title="Go to section web site" href="http://', point.web, '">Go to web site</a>'].join('');
	}

  	return html;
}

Sections.prototype.formatAddress = function(index) {
	var point = this.points[index];

	var address = point.postcode;
	return escape(address.replace(' ', '+'));
}


SectionMap = function()
{
	this.lat = 54.0;
	this.lng = -4.0;
	this.zoom = 5;
	this.addControl = true;
}



function MapManager(me, canvas, mapSettings, overlay)
{
	this.markers=[];
	if (GBrowserIsCompatible()) 
	{
        this.map = new GMap2(document.getElementById(canvas));
        this.map.setCenter(new GLatLng(mapSettings.lat, mapSettings.lng), mapSettings.zoom);
 
	    // Add control, if required
		if (mapSettings.addControl) this.map.addControl(new GLargeMapControl());
        
		// Add markers to the map
        for (var i = 0; i < overlay.points.length; i++) {
			this.markers[i] = new GMarker(new GLatLng(overlay.points[i].lat, overlay.points[i].lng))
			this.map.addOverlay(this.markers[i]);
			
			//this.markers[i].index = i;
			this.markers[i].popUpHtml =  overlay.getMarkerHtml(i);
			GEvent.addListener(this.markers[i], 'click', function() { return this.openInfoWindowHtml(this.popUpHtml);} );
			
		}

    }
}

MapManager.prototype.openInfoWindow = function(index) 
{    
	var marker = this.markers[index];
//	marker.openInfoWindowHtml(marker.popUpHtml);
	
    GEvent.trigger(marker, "click");

}


function showMarker(point)
{
debugger;
    var marker = createMarker(point);
   	currentMarker = marker;
    GEvent.trigger(marker, "click");
}



/**
 * Convenience function for creating an element and assigning an id to it.
 * @param {String} elementType
 * @param {String} id
 * @return {Element} 
 */
function _cel(elementType, id) {
  var element = document.createElement(elementType);
  element.id = id;
  return element;
}

/**
 * Loads in the Maps API script. This is called after some sort of user interaction.
 * The script loads asynchronously and calls loadMap once it's in.
 */
function loadScript() {
	debugger;
  if (!isLoaded) {
    isLoaded = true;
    var div = document.createElement('div');
    div.className = 'message';
    div.innerHTML = 'Loading...';
    div.style.left = (400/2 - 53) + 'px';
    div.style.top = 400/2 + 'px'; 
    //mapDiv.appendChild(div);
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'http://maps.google.com/maps?file=api&v=2.x' + 
                 '&async=2&callback=loadMap&key=ABQIAAAALwS_eGeFi6n5ygxcmxL-1hSqU2GWjlxXC_NHxzyA3TNFK5jOQBSFiGtNuYs37aIWheiGH_qn_AaShw';
    document.body.appendChild(script);
  }
}

/**
 * Sets up the gadget by setting CSS and click events.
 */
function loadMapGadget() {
  containerDiv = document.getElementById('container');
  mapDiv = document.getElementById('map');

  //mapDiv.onclick = function (e) {
  //  clickedX = (window.event && window.event.offsetX) || e.clientX;
  //  clickedY = (window.event && window.event.offsetY) || e.clientY;
    loadScript(); 
  //};

  mapDiv.style.cursor = 'pointer';

  var urlString = ['http://maps.google.com/staticmap?markers='];
  var markerString = [];
  for (var i = 0; i < points.length; i++) {
    markerString.push(points[i].lat + ',' + points[i].lng + ',red');
  }
  urlString.push(markerString.join('|'));
  urlString.push('&size=400x400');
  urlString.push('&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxSPW5CJgpdgO_s4yyMovOaVh_KvvhSfpvagV18eOyDWu7VytS6Bi1CWxw');
  mapDiv.style.background = 'url(\'' + urlString.join('') + '\')';

}

