// JavaScript Document
function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	for (i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1){
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){
				this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout=function(){
				this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}


//<![CDATA[

    function load() {
            if (GBrowserIsCompatible()) { 

                  var map = new GMap2(document.getElementById("map"));
                  map.addControl(new GLargeMapControl());
                  map.addControl(new GMapTypeControl());

                  // ==== It is necessary to make a setCenter call of some description before adding markers ====
                  // ==== At this point we dont know the real values ====
                  map.setCenter(new GLatLng(0,0),0);
                
               
                  var sidebar_html = "";
                  var gmarkers = [];
                  var htmls = [];
                  var i = 0;


                  function createMarker(point,name,html) {
                    var marker = new GMarker(point);
                    GEvent.addListener(marker, "click", function() {
                      marker.openInfoWindowHtml(html);
                    });
                    gmarkers[i] = marker;
                    htmls[i] = html;
                    //sidebar_html += '<a href="javascript:myclick(' + i + ')">' + name + '</a><br>';
                    i++;
                    return marker;
                  }


                  function myclick(i) {
                    gmarkers[i].openInfoWindowHtml(htmls[i]);
                  }

                  
                  // ===== Start with an empty GLatLngBounds object =====     
                  var bounds = new GLatLngBounds();
                  
                  // Read the data from example.xml
                  var request = GXmlHttp.create();
                  request.open("GET", "resources/data.xml", true);
                  request.onreadystatechange = function() {
                    if (request.readyState == 4) {
                      var xmlDoc = request.responseXML;
                      // obtain the array of markers and loop through it
                      var markers = xmlDoc.documentElement.getElementsByTagName("marker");
                      
                      for (var i = 0; i < markers.length; i++) {
                        // obtain the attribues of each marker
                        var lat = parseFloat(markers[i].getAttribute("lat"));
                        var lng = parseFloat(markers[i].getAttribute("lng"));
                        var point = new GLatLng(lat,lng);
                        var html = markers[i].getAttribute("html");
                        var label = markers[i].getAttribute("label");
                        // create the marker
                        var marker = createMarker(point,label,html);
                        map.addOverlay(marker);
                        
                        // ==== Each time a point is found, extent the bounds ato include it =====
                        bounds.extend(point);
                      }

                      //document.getElementById("sidebar").innerHTML = sidebar_html;
                      
                      // ===== determine the zoom level from the bounds =====
                      map.setZoom(map.getBoundsZoomLevel(bounds));

                      // ===== determine the centre from the bounds ======
                      var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
                      var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
                      map.setCenter(new GLatLng(clat,clng));

                      
                    }
                  }
                  request.send(null);

                }
                
                // display a warning if the browser was not compatible
                else {
                  alert("Sorry, the Google Maps API is not compatible with this browser");
                }
    }

    //]]>