function load(){
	var map = null;
    var geocoder = null;

    function initialize() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("Map"));
				map.addControl(new GLargeMapControl());
        geocoder = new GClientGeocoder();
      }
    }

    function showAddress(location,anchor) {
			var target = $j(anchor);
			var html = $j('.address',target).clone().get(0);
      if (geocoder) {
        geocoder.getLatLng(
          location.searchAddress,
          function(point) {
            if (!point) {
              //alert(address + " not found");
            } else {
			  map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              //marker.openInfoWindowHtml('<p><strong>'+ location.company +'</strong></div>');
            }
          }
        );
      }
    }
	
	function locationsMapInstance(){};
	locationsMapInstance.prototype = {
		init : function(){
			var o = this;
			//Gmap Functions
			initialize();
			
			//Instance Functions
			o.LocationsList = $j('#LocationsList');
			o.LocationsListItems = $j('#LocationsList li');
			o.LocationsLinks = $j('#LocationsList a');
			o.prev = $j('.scroll-arrow-up');
			o.next = $j('.scroll-arrow-down');
			o.current = {};
			o.loadXML();
		},
		loadXML : function() {
			var o = this;
			$j.ajax({
		  type: "GET",
		  url: "_Client/Scripts/OfficeLocations.php",
		  dataType: "xml",
			complete: function(data){
				o.JSON = $j.xmlToJSON(data.responseXML);
				var i;
				for(i=0;i<o.JSON.Office.length;i++) {
					o.render();
					o.events();
				}
			}
			});
		},
		searchXML : function(location){
			var o = this;
			o.locationFound = false;
			for (i = 0; i < o.JSON.Office.length; i++) {
				//Needs a better search loop
	  		if(o.JSON.Office[i].Name[0].Text == location) {
					o.current.name = o.JSON.Office[i].Name[0].Text;
					o.current.company = o.JSON.Office[i].Company[0].Text;
					o.current.address = o.JSON.Office[i].Address[0].Text;
					o.current.searchAddress = o.JSON.Office[i].AddressToSearch[0].Text;
					o.scrollPane = $j('#LocationListScrollPane');
					o.locationFound = true;
				}
			}
			//If location not found
			if(o.locationFound == false ){ alert('Location not found in XML'); }

		},
		render : function(){
			var o = this;
			//Set first office as active
			var firstAnchor = $j('#LocationsList li a:first');
			o.searchXML(firstAnchor.attr('rel'));

			showAddress(o.current,firstAnchor.attr('href'));
			
			$j('#Locations').localScroll({
				target: '#OfficesPane',
				axis: 'x',
				onBefore : function(e, anchor, $target){
					//Highlight clicked location
					$j(this).parent().addClass('active');
					//Save location to search till scroll has finished
					o.locationToSearch = $j(this).attr('rel');
				},
				onAfter: function(anchor) {
					o.searchXML(o.locationToSearch,function(){});
					//Set new map locations
					showAddress(o.current,$j(anchor).attr('href'));
				}
			});
			//Scroll Pane
			o.scrollPane.serialScroll({
				items:'li',
				axis: 'y',
				prev: o.prev,
				next: o.next,
				offset:0, //1
				start:0, //as we are centering it, start at the 2nd
				step: 5,
				duration:1200,
				force:true,
				stop:true,
				lock:false,
				cycle:false, //don't pull back once you reach the end
				jump: true //click on the images to scroll to them
			});
		},
		events : function() {
			var o = this;
			o.LocationsListItems.click(function(){
				o.LocationsListItems.removeClass('active');
				});
		o.next.hover(
			function(){ $j(this).addClass('scroll-arrow-down-hover'); },
			function(){ $j(this).removeClass('scroll-arrow-down-hover');}
		);
		o.prev.hover(
			function(){ $j(this).addClass('scroll-arrow-up-hover'); },
			function(){ $j(this).removeClass('scroll-arrow-up-hover');}
		);
		}
	}
	var locationsMap = new locationsMapInstance();
	locationsMap.init();
}
