
var marker_store = [];
var map;  
var myData = [];
/**
* init_map - this function is used to initiate the map 
*/
function init_map()
{	var map_height="600px";
	$('map-x-map').setStyle({ height: map_height});
//	var  = 15;
	var az_html = "";
	map = new GMap2( $('map-x-map') );
    $('map-x-map').setStyle({
    width: "75%",   
    float:"right",
    border:"1px solid gray"});

	var orig_type="";
    map.enableScrollWheelZoom();
	map.addMapType(G_PHYSICAL_MAP); //	The physical map shows the mountains arround here. It is nice.
    map.setMapType( G_NORMAL_MAP );

	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
//	map.enableContinuousZoom();

	if (typeof ( window[ 'startAddr' ] ) !="undefined" )
	{	var directions_shown = display_directions(startAddr, endAddr);
	}	
	else
	{	var directions_shown = display_directions();
	}
	//if( !directions_shown )
	//{
	//	look at the URL to decide where to centre the map:
	//      Special case - strip out referances to go
	var matches = /\/([^/]+)(\/google)?\/?$/.exec( window.location.pathname );
	var map_centre = map_centres[ matches[1] ];

	if( !map_centre )
	{	alert( "unknown map page " + matches[1] );
	}
	map.setCenter(new GLatLng(map_centre.lat, map_centre.long), parseInt(map_centre.zoom));

	//	add the directions form and layers form to the map; above or below the map as required
	if(matches[1] != "route-planner")
	{	add_directions_form("below");
	}
	else
	{	add_directions_form("above");
		$$('div.googlemaps-x-directions')[0].addClassName('orange-box');
	}
	add_layers_form();

	//if(($('saddr').value) == "")
	if ((typeof ( window[ 'startAddr' ] ) !="undefined" ) && (typeof ( window[ 'endAddr' ] ) !="undefined" ))
	{	orig_type="menu";
		$('saddr').value = startAddr;
		$('daddr').value = endAddr;
	}
	//}

// add the layers form to the map
    //add_layers_form();

//	add more detailed roads and buildings for campuses:
	/** 
	*@name create_overlay
    *@function
    *@description this is an internal funcition inside init_map() and is not publically available 
	*@param n - northen corner coordinates for the overlay
	*@param s - southern corner coordinates for the overlay
	*@param e - eastern corner coordinates for the overlay
	*@param w - western corner coordinates for the overlay
	*@param campus - name of the campus e.g. penglais
	*@return GGroundOverlay object 				   
	*/ 
	function create_overlay( n, s, e, w, campus )
	{	var bottomleft       = new GLatLng( s, w );
		var topright         = new GLatLng( n, e );
		var boundaries       = new GLatLngBounds( bottomleft, topright );
		return new GGroundOverlay("http://www.aber.ac.uk/corp-maps/" + campus + ".png", boundaries );
	}
	var penglais_overlay   = create_overlay( 52.4198   , 52.41207 , -4.0601  , -4.07115 , 'penglais'   );
	var llanbadarn_overlay = create_overlay( 52.411850 , 52.409090, -4.050250, -4.056620, 'llanbadarn' );
	var gogerddan_overlay  = create_overlay( 52.435556 , 52.431300, -4.011500, -4.022500, 'gogerddan'  );

//	add_overlay( n, s, e, w, 'gogerddan'  );
	map.addOverlay( penglais_overlay   );
	map.addOverlay( llanbadarn_overlay );
	map.addOverlay( gogerddan_overlay  );



	/** 
	*@name show_hide_overlays
    *@function
    *@description this function decides if the overlap should be shown or not when the map is zoomed or the mode changed. This is an internal funcition inside init_map() and is not publically available 
	*/ 	
	function show_hide_overlays()
	{
		var zoom = map.getZoom();

		if( (map.getCurrentMapType() == G_NORMAL_MAP) && (zoom >= 15) )
		{
			map.addOverlay( penglais_overlay   );
			map.addOverlay( llanbadarn_overlay );
			map.addOverlay( gogerddan_overlay  );
		}else
		{	map.removeOverlay( penglais_overlay   );
			map.removeOverlay( llanbadarn_overlay );
			map.removeOverlay( gogerddan_overlay  );
		}
	}
	GEvent.addListener( map, "zoomend"       , show_hide_overlays );
	GEvent.addListener( map, "maptypechanged", show_hide_overlays );
	show_hide_overlays();
    generate_markers();
	if ($('default').checked == true)
    {	add_a_z();
	}

	/** 
	*@name add_a_z
    *@function
    *@description this function is called to add the A-Z of departments to the map's left hand bar. This is an internal funcition inside init_map() and is not publically available 
	*/ 
    function add_a_z()
    {	var sort_by = function(field, reverse, primer)
		{	reverse = (reverse) ? -1 : 1;
	    	return function(a,b){
        	a = a[field];
        	b = b[field];
        	if (typeof(primer) != 'undefined')
        	{	a = primer(a);
        		b = primer(b);
        	}
        	if (a<b) return reverse * -1;
        	if (a>b) return reverse * 1;
        	return 0;
      	}
     }

	myData.sort(sort_by('name', false, function(a){return a.toUpperCase()}));
	var az_controls=
		      [ 'div', {  id: 'az-x-menu'}
			  ,	'\n'
			  ,['h3' ,'A-Z']
			  ,'\n'
			  ,[ 'div',	{'class': 'menu', 'id': 'az-container', style: 'border-width:1px 0 1px 0;border-style:solid;border-color:grey;margin-left:-0.35em;overflow:auto;height:426px;background:rgb(242, 239, 233)!important'}
			  ,'\n',' '],' '].parseJsonML();

        Element.insert( $('map-x-layers'), { after : az_controls } );

        az_controls="<ul>";
        for(var i=0,len=myData.length; value=myData[i], i<len; i++)
		{    az_controls+=value.link;
		}
		az_controls+="</ul>";
 	    Element.update( $('az-container'), az_controls  );
	}
	/** 
	*@name clearMap
    *@function
    *@description this function is called to clear all the map overlays. This is an internal funcition inside init_map() and is not publically available 
	*/ 	
    function clearMap()
	{	map.clearOverlays();  
	}

	var mgr;
    function generate_markers()
    {    layer_param=get_layer_param();
	     var many_layers=layer_param.indexOf(",");
		 if ( many_layers != -1)
		 {    layers_param=layer_param.split(",");
		 }
		 else
		 {    var layers_param=new Array(layer_param);
	     }
	//	add the markers to the map. This involves seperating them into
	//	sub-arrays by size and then adding them to manager
		 var pin_categories = 	//	arrays for each of the classes of points:
				{	town:     []
				,	campus:   []
				,	building: []
				};

		 pin_data.each(
		 function ( pin )
		 {    if(
		 	     ( Search_Array(layers_param, pin.layer))
				 ||
				 ( pin.layer == "all"))
				 {
			//	put the pin into a subarray of pin_categories, depending on
			//	its size:
					  if (layer_data[pin.layer].custom!=null)
					  {    var img_url= ""+layer_data[pin.layer].custom;
						   img_url=trim(img_url);
		                   var blueIcon = new GIcon(G_DEFAULT_ICON);
						   blueIcon.image = "http://"+img_url;
			 			   blueIcon.transparent = "http://"+img_url;
						   blueIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
						   blueIcon.iconSize = new GSize(32, 32);
						   blueIcon.shadowSize = new GSize(59, 32);
						   blueIcon.iconAnchor = new GPoint(9, 34);
						   blueIcon.infoWindowAnchor = new GPoint(9, 2);
		                   var pushpin = create_marker( pin, blueIcon );
					  }
					  else
					  {    var pushpin = create_marker( pin, "" );
					  }
	              	  pin_categories[ pin.size ].push( pushpin );
	     		  }
			});
		    mgr = new MarkerManager( map );
			mgr.addMarkers( pin_categories.town,     1 , 10 );
			mgr.addMarkers( pin_categories.campus,   11, 14 );
			mgr.addMarkers( pin_categories.building, 15, 17 );
			mgr.refresh();
    	}


/*	window.setTimeout( function(){ display_directions( map ); }, 500 );*/

	/** 
	*@name get_var
    *@function
    *@description returns the specified GET variable from the current page. This is an internal funcition inside init_map() and is not publically available 
	*@param var_name - variable to get from the page	
	*/ 
	function get_var( var_name )
	{    var regexp = new RegExp( var_name + '=([^&]*)' );
		 var var_match = window.location.search.match( regexp );
		 if( var_match )
		 {    var g_var = var_match[1];
			  return decodeURIComponent( g_var );
		 }else
		 {    return null;
		 }
	//	flow never gets here
	}




	
	/** 
	*@name handle_directions_error_debug
    *@function
    *@description A developer function to show the errors we get (this isn't so friendly for everyone else). This is an internal funcition inside init_map() and is not publically available 
	*@param event - the event that was fired
	*@param directions - the directions that were specified
	*/ 	
	function handle_directions_error_debug( event, directions )
	{   var messages =
		{
			G_GEO_UNKNOWN_ADDRESS:
				"No corresponding geographic location could be found for one of the specified addresses. This"
			+	" may be due to the fact that the address is relatively new, or it may be incorrect."
		,	G_GEO_SERVER_ERROR:
				"A geocoding or directions request could not be successfully processed, yet the exact reason"
			+	" for the failure is not known."	
		,	G_GEO_MISSING_QUERY:
				"The HTTP q parameter was either missing or had no value. For geocoder requests, this means"
			+	" that an empty address was specified as input. For directions requests, this means that no"
			+	" query was specified in the input."
		,	G_GEO_UNKNOWN_DIRECTIONS:
				"The GDirections object could not compute directions between the points mentioned in the"
			+	" query. This is usually because there is no route available between the two points, or"
			+	" because we do not have data for routing in that region."
		,	G_GEO_BAD_KEY:
				"The given key is either invalid or does not match the domain for which it was given."
		,	G_GEO_BAD_REQUEST:
				"A directions request could not be successfully parsed."
		};
		var code = directions.getStatus().code;
		var message = messages[ code ];

		if( !message )
			message = "Unknown error";

		alert( message + "\nError code:" + code );
	}


	/** 
	*@name handle_directions_error_nicely
    *@function
    *@description Shows an error message related to the directions errors by replacing the div with id 'map-x-directions-errors'. This is an internal funcition inside init_map() and is not publically available 
	*@param event - the event that was fired
	*@param directions - the directions that were specified
	*@param saddr - the start address
	*@param daddr - the destination address
	*/ 	
	function handle_directions_error_nicely( event, directions, saddr, daddr )
	{    var code = directions.getStatus().code;
		 var error_area = $( 'map-x-directions-errors' );
		 function show_error( error_text )
		 {
		 //	create a new error area, and replace the old one:
			 var new_area = [ 'div', {id:'map-x-directions-errors'}, error_text ].parseJsonML();
			 $('map-x-directions-errors').up().replaceChild( new_area, $('map-x-directions-errors') );
		 }
         var error_lang_values =
    	 {    'noway' 	 : { en:"Sorry, Google couldn't find directions from "+ saddr +" to Aberystwyth"  , cy:"Ymddiheuriadau, nid oedd Google yn gallu darganfod y fordd o " +saddr +" yno i Aberystwyth"}
    	   ,  'wrong' 	 : { en:"Sorry, something went wrong. Please try again later" , cy:"Ymddiheuriadau, bu problem. Ceisiwch eto"}
    	 };

		 switch( code )
		 {    case G_GEO_UNKNOWN_ADDRESS:
			  case G_GEO_UNKNOWN_DIRECTIONS:
				 var place;
				 show_error( error_lang_values['noway'][page_language()] );
				 break;
			  default:
				 show_error( error_lang_values['wrong'][page_language()] );
				 break;
		 }
	} 

/*	Local functions used during initilisation follow */

	var directions;
	
	/**	
	* @name display_directions
    * @function
    * @description if there are directions in the GET, displays them. This is just the same as sending
	* saddr and daddr get vars to a page on Google maps, excpet we're picking it up when it
	* lands on our maps page. This is an internal funcition inside init_map() and is not publically available 
	* @param saddr start address
	* @param daddr destination address
	* @return true if directions were shown, false otherwise 
	*/
	function display_directions( saddr, daddr )
	{
		/**	the first time, creates a directions object and adds a panel for textual
		directions display to the page. The second etc time called, just returns
		the directions object */
		function lazy_instantiate_directions()
		{	if( directions )
			{	directions.clear();
				return directions;
			}

		//	add a div to the page, which will contain the textual directions in
		//	a moment:
			var panel = ['div', { id:'map-x-textual-directions' } ].parseJsonML();

		//	the try-catch is because sometimes we get errors from JSONStringify
		//	not interacting properly with Prototype's insert, but this seems to be
		//	completely non-harmful and can be ignored
			try
			{	Element.insert( $('maincontent-inner'), { bottom : panel } );
			}catch(e){ /*alert(e);*/ }
	

		//	for ducumentation on GDirections, see: 
		//	http://code.google.com/apis/maps/documentation/reference.html#GDirections
			directions = new GDirections( map, panel );
			return directions;
		}


		 if( !saddr )
	     	saddr = get_var( 'saddr' );
			if(orig_type=="menu")
            {	if(testPostCode (saddr))
	            {    if($('geocode-error'))
					 {    Element.remove ($('geocode-error'));
					 }
					 working_saddr=removeSpaces(checkPostCode (saddr));
		   	         var lurl = '/corp-maps/geocode.php?postcode='+working_saddr;
			    	 var lxml = new JKL.ParseXML( lurl );
			    	 var ldata = lxml.parse();
					 if(ldata.response.error=="Partial")
					 {  	var load_warning='<div id="geocode-error"><p>Could only retrieve partial postcode match</p></div>';
	                        Element.insert( $('map-x-directions-errors'), { before : load_warning } )
					 }
			    	 if(ldata.response.longitude!=null)
			    	 {    saddr=ldata.response.latitude+','+ldata.response.longitude;
					 }
	
	   	        }
   	        }
   	        else
   	        {    orig_type="";
			}


		if( !saddr )
		{	return false; // not being asked for directions - do nothing.
		}

		if( !daddr )
			daddr = get_var( 'daddr' );

	//	if we have source, but no destination, assume Penglais: 
		if( !daddr )
			daddr = "52.416623,-4.066573";

	//	make sure the directions object has been created and set up:
		lazy_instantiate_directions();

		GEvent.addListener( directions, "error",
							function( event )
							{	handle_directions_error_nicely( event, directions, saddr, daddr );
							} );

//		replace the error area with a blank error area. If there was no error show, this does
//		nothing. Otherwise, it clears the error.
							try {
		$('map-x-directions-errors').replace( [	'div', { id:'map-x-directions-errors' } ].parseJsonML() );
							}
							catch(e){}

		var directions_string = "from:" + saddr + " to:" + daddr;

		directions.load( directions_string, {getSteps:true} );


		return true;
	}

	/** 
	*@name removeSpaces
    *@function
    *@description returns the specified GET variable from the current page. This is an internal funcition inside init_map() and is not publically available 
	*@param var_name - variable to get from the page	
	*/ 
    function removeSpaces(string)
	{    return string.split(' ').join('');
    }

    function testPostCode (saddr)
	{	if (checkPostCode (saddr))
		{    return true;
		}
        else
		{
			 return false;
		}
	}


	/** 
	*@name add_directions_form
    *@function
    *@description this function is used to add the directions form to the page at a specified location. This is an internal funcition inside init_map() and is not publically available 
	*@param placement - location where the form should go - either below or above the map.	
	*/ 
	function add_directions_form(placement)
	{    var direction_lang_values =
    	 {	'title' 	 : { en:'Directions to Aberystwyth' , cy:'Sut i gyrraedd Aberystwyth'}
    	 ,	'from' 		 : { en:'From:' , cy:'Cychwyn o:'}
    	 ,	'to' 		 : { en:'To:' , cy:'Mynd i:'}
    	 ,	'penglais'	 : { en:'Penglais (main) Campus' , cy:'Campws Penglais (prif)'}
    	 ,	'oldcollege' : { en:'Old College' , cy:'Yr Hen Goleg'}
    	 ,	'gogerddan'	 : { en:'Gogerddan Campus' , cy:'Campws Gogerddan'}
    	 ,	'llambadarn' : { en:'Llanbadarn Campus' , cy:'Campws Llanbadarn'}
    	 ,	'button'     : { en:'Get Directions' , cy:'Dangos Cyfarwyddiadau'}
    	 };
		 var saddr = get_var( 'saddr' );
		 if( !saddr )
			saddr = '';

	     post_location=document.location.href;
		 arr_post_location=post_location.split("aber.ac.uk");
		 post_location=arr_post_location[1];


		 var directions_form =
			 [ 'div' ,  { 'class':'googlemaps-x-directions'}
			,[ 'h4' , form_title=direction_lang_values['title'][page_language()]]
            ,[	'form', { action:''+post_location+'', 'method':'get', id:'map-x-getdirections' }
				,	[	'div' ,  { 'class':'googlemaps-x-directions-from' }
					,	[ 'label'	, { 'for'  : 'saddr' } , direction_lang_values['from'][page_language()] ]
					,	[ 'input'	, { 'type' : 'text', 'name':'saddr', 'id':'saddr', 'value':saddr } ]
					]

				,	[	'div' , ,  { 'class':'googlemaps-x-directions-to' }
					,	[ 'label'	, { 'for'  : 'daddr' } , direction_lang_values['to'][page_language()] ]
					,	[ 'select'	, { 'name' : 'daddr', id:'daddr' }
						,	[ 'option' , {value:'52.416623,-4.066573'}, direction_lang_values['penglais'][page_language()] 	]
						,	[ 'option' , {value:'52.41475,-4.088306'}, direction_lang_values['oldcollege'][page_language()] 				]
						,	[ 'option' , {value:'52.432778,-4.016611'}, direction_lang_values['gogerddan'][page_language()] 		]
						,	[ 'option' , {value:'52.410444,-4.05325'}, direction_lang_values['llambadarn'][page_language()]		]
						]
				]
				,	[	'div'		, { id:'map-x-directions-errors' }
                    ]

				,	[	'input'		, { 'type' : 'submit', 'value' : direction_lang_values['button'][page_language()] } ]
				]
                ].parseJsonML();
		 directions_form = $( directions_form );

		 try
		 {  
			if (placement=="below")
			{
			Element.insert( $('map-x-map'), { after : directions_form } );
			}
			else
			{
			Element.insert( $('map-x-map'), { before : directions_form } );
			}
			  $('map-x-map')[0].outerHTML;
		 }catch(e){}

		$( 'map-x-getdirections' ).observe( 'submit' ,
				function( e )
				{   var saddr = $( 'saddr' ).getValue();
					var daddr = $( 'daddr' ).getValue();
					display_directions( saddr, daddr );
					Event.stop( e ); //don't actually submit to the server
				} );
	}
	/** 
	*@name add_layers_form
    *@function
    *@description this function is used to add the the layer control form. This is an internal funcition inside init_map() and is not publically available 	
	*/ 
    function add_layers_form()
	{	var layer_lang_values =
    	{	'title' 	 : { en:'Layer Controls' , cy:'Rheoli Heanau'}
    	,	'button'     : { en:'Change' , cy:'Newid'}
    	};
		var div_style=' padding-left:0.5%; width: 23.5%; float:left; height:'+map_height+'; border:1px solid gray; background:#f2efe9;'
		var layers_form =
			[ 'div' ,  { 'class':'googlemaps-x-layers' , 'id':'map-x-sidebar', 'style':div_style }
			,[ 'h4' , form_title=layer_lang_values['title'][page_language()]]
            ,[	'form', { action:'/en/maps/town/google', 'method':'get', id:'map-x-layers' }
				, [	'div' , { 'id'   : 'layers-x-checkboxes'}
					]
				,	[	'div'
                    ]
				,	[	'input' 	, { 'type' :'hidden' , 'id':'layerstring'}]
				]
                ].parseJsonML();
		layers_form = $( layers_form );
	//	the try-catch is because sometimes we get errors from JSONStringify
	//	not interacting properly with Prototype's insert, but this seems to be
	//	completely non-harmful and can be ignored
      try
		{	Element.insert( $('map-x-map'), { before : layers_form } );
            $('googlemaps-x-layers')[0].outerHTML;
		}catch(e){}
		Form.Element.setValue($('layerstring'), initial_lp);


		layer_data_array.each (function( layer )
		 					   {   if (page_language()=="en")
		 					  	   {    name_string=layer.fullname;
	                               }
	                               else
	                               {    name_string=layer.fullnamecy;
								   }
								   if (layer.control=="false")
								   {    visible="display: none";
								   }
								   else
								   {  visible="display: block";
                                   }
								       var check_object=
														[	'div'       , { 'style': visible}
														,   [ 'input'	, { 'id'   : layer.name, 'value':layer.name, 'type':'checkbox'}]
														,	[ 'label'	, { 'for'  : layer.name } , ' '+name_string ]
														].parseJsonML();
								        try
									    {   //document.body.insertBefore ($('layers-x-checkboxes'), check_object)
											Element.insert( $('layers-x-checkboxes'), { before : check_object } );
									    }catch(e){}
							       
							  });

                      for (var i = 0, length = defaults.length; i< length; i++)
							        {   MYcheckbox=defaults[i];
							        	if ($(MYcheckbox))
							        	{
							           	   $(MYcheckbox).setAttribute('checked', true);
							        	}
									}

	//	as well as the form being (well, a form) - listen to it being submitted
	//	and react on-page. In this way, the form on this page will probably never
	//	actually be submitted (but if it were, it'd still work)
	   $( 'map-x-layers' ).observe( 'submit' ,
				function( e )
				{   refresh_shown_layers();
					Event.stop( e ); //don't actually submit to the server
				} );

		for (var i = 0, length = layer_data_array.length; i< length; i++)
		{   MYcheckbox=layer_data_array[i].name;
            if($(MYcheckbox))
			{   $(MYcheckbox).observe('click', function(e)
											   {   if(this.checked)
											  	   {    updateChecked(''+this.id) ;
													  	refresh_shown_layers();

												   }
												   else
												   {    updateUnchecked(''+this.id);
													 	refresh_shown_layers();
												   }
												});
			}
		}

	}
	/** 
	*@name refresh_shown_layers
    *@function
    *@description this function is called to refresh which layers are displayed. This is an internal funcition inside init_map() and is not publically available 		
	*/ 
	function refresh_shown_layers()
	{    clearMap();
		 show_hide_overlays();
		 mgr.clearMarkers();
         generate_markers();

		 var az_visible=''+$('default').checked;
         if(az_visible == 'false')
		 {  if ($('az-x-menu').visible()==true)
		    {
		 	$('az-x-menu').toggle();
		 	  }
         }
         if(az_visible == 'true')
         {  if ($('az-x-menu').visible()==false)
		    {    $('az-x-menu').toggle();
		 	}
         }

		 if (typeof ( window[ 'startAddr' ] ) !="undefined" )
		 {    var directions_shown = display_directions(startAddr, endAddr);
         }
		 else
		 {    var directions_shown = display_directions();
		 }
			
			
	}
	/** 
	*@name page_language
    *@function
    *@description this function is used to find the language of the page based on the address URI. This is an internal funcition inside init_map() and is not publically available 		
	*/ 
	function page_language()
	{	var lang_match = /^\/(en|cy)/.exec( window.location.pathname );
		var lang = lang_match[1];
		return lang;
	}
	
	/** 
	*@name create_marker
    *@function
    *@description this function is used to create a new marker that will eventually be added to the map. This is an internal funcition inside init_map() and is not publically available 		
	*@param pin - the pin object that wil be used in the construction of the marker
	*@param pin_icon - the icon that will be assigned to the marker
	*@returns marker - a new GMarker object	
	*/
	function create_marker( pin, pin_icon )
	{   var point =  new GLatLng(parseFloat(pin.lat), parseFloat(pin.long));
		var name  = pin.title[ page_language() ];
		var desc  = pin.desc[  page_language() ];
		var test_layer = pin.layer;
		var test_size = pin.size;
		if (pin_icon !="")
		{    markerOptions = { icon:pin_icon };
           	 var marker = new GMarker(point, markerOptions);


		}
		else
		{    var marker = new GMarker(point);

		}
		var html = "<b>" + name + "</b> <br/>" + desc+"<br>";
		GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html);
		});
	    if(test_layer=="default")
	    {
		marker_store.push(marker);
			 var az_name=name;
			 az_name=az_name.replace("Department of ","");
			 az_name=az_name.replace("School of ","");
			 az_name=az_name.replace("Institute of ","");

			 az_html += '<li><a href="javascript:bubbleclick(' + (marker_store.length-1) + ',16)">' + az_name + '<\/a></li>';
			var link_uri= '<li><a href="javascript:bubbleclick(' + (marker_store.length-1) + ',16)">' + az_name + '<\/a></li>'

			 myData.push({'name': az_name, 'link' : link_uri});
	  }
		return marker;
	}

	/** 
	*@name Search_Array
    *@function
    *@description this function is used to search an array object for a specific item. This is an internal funcition inside init_map() and is not publically available 		
	*@param ArrayObj - the array in which to search
	*@param SearchFor - the value to search for
	*@returns true or false depending on whether the value is present in the array	
	*/
	function Search_Array(ArrayObj, SearchFor)
	{    var Found = false;
	  	 for (var i = 0; i < ArrayObj.length; i++)
		 {    if (ArrayObj[i] == SearchFor)
		 	  {    return true;
	      		   var Found = true;
	      		   break;
	    	  }
	    	  else if ((i == (ArrayObj.length - 1)) && (!Found))
			  {    if (ArrayObj[i] != SearchFor)
			  	   {    return false;
	      		   }
	    	  }
	  	  }
	}

	/** 
	*@name include
    *@function
    *@description this function is used to load extra javascrit files into the head of the document. This is an internal funcition inside init_map() and is not publically available 		
	*@param scriptFile - the file to include
	*/
	function include(scriptFile)
	{    var headTag = document.getElementsByTagName('head').item(0);
	 	 var js = document.createElement('script');
	 	 js.setAttribute('language', 'javascript');
	 	 js.setAttribute('type', 'text/javascript');
	 	 js.setAttribute('src', scriptFile);
	 	 headTag.appendChild(js);
	}

/**==============================================
*Utility String trimming functions
*================================================*/
	function trim(str, chars) {
		return ltrim(rtrim(str, chars), chars);
	}

	function ltrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
	}

	function rtrim(str, chars) {
		chars = chars || "\\s";
		return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
	}

}/*	end of function init_map */

window.onload = init_map; // this line will forever be a mystery to Simon because he
						  // thinks Coffee is more important than my words. Probably, he is right.
// Prototypey replacement for the above nonsense:
//Event.observe( window, 'load', init_map );
