//Direction Functions

    var map;
    var gdir;
    var geocoder = null;
    var addressMarker;
	var point;
	


function createMarker(point, name, address, type, map) {
	var OCTA = new GIcon(); 
    OCTA.image = 'http://ohiochristmastree.com/images/googleicon.png';
    OCTA.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	if (zoom == 13) {OCTA.iconSize = new GSize(30, 38);}
	if (zoom == 7){OCTA.iconSize = new GSize(18, 22);}
    OCTA.shadowSize = new GSize(0, 0);
    OCTA.iconAnchor = new GPoint(6, 20);
    OCTA.infoWindowAnchor = new GPoint(5, 1);
  var mycatid = type.substr(type.length-2,2);
  var marker = new GMarker(point, OCTA);
  var html = "<br/><strong><a href=" + type + "> " + name + "</a></strong> <br/>" + address + "<p align=center class=gmap><a href=" + type + ">click here for more information</a>";
  map.addOverlay(marker);
  
  GEvent.addListener(marker, 'click', function(o, p) {
	if(catid=='15'){marker.openInfoWindowHtml(html);}
	else{
    if(map.getZoom()!=7){	marker.openInfoWindowHtml(html);}
	else{ 
	
 			   map.setCenter( marker.getLatLng(), map.getZoom() + 4 );
 			 
	}
  }
											   });
  return marker;
}
    function load(lat, long) {
		if(long == -82.0){id=2;}
		else{id='';}
		var map = new GMap2(document.getElementById("map"+id));
		map.addControl(new GSmallMapControl());
		map.addControl(new GHierarchicalMapTypeControl());
		//map.setCenter(new GLatLng(40.25511,-83.026428), 6);
		map.setCenter(new GLatLng(lat,long), zoom);
		map.addMapType(G_PHYSICAL_MAP);
		GEvent.addListener( map, "click", function(o,p) {
		if(map.getZoom()==7){								   
 			 if ( o != null ) return;
 			 if ( map.getZoom() > 1 )
 			   map.setCenter( p, map.getZoom() + 2 );
 			 else if ( map.getZoom() == 1 )
   			 map.setCenter( p, 0 );
		}
		});
				
		GDownloadUrl("http://ohiochristmastree.com/index.php?option=com_qcontacts&view=category&catid="+catid+"&Itemid=29&format=feed&type=rss", function(data, responseCode) {
		  var xml = GXml.parse(data);
		  var markers = xml.documentElement.getElementsByTagName("marker");
		 
		  for (var i = 0; i < markers.length; i++) {
		  	
			 var name = markers[i].getAttribute("name");
			var address = markers[i].getAttribute("address");
			var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
									parseFloat(markers[i].getAttribute("lng")));
			var type = markers[i].getAttribute("type");
		  // map.addOverlay(new GMarker(point));
		   var marker = createMarker(point, name, address, type, map);
		
					
		  }
		});

    }
    
    function setDirections(fromAddress, toAddress, locale) {
			  map.closeInfoWindow(point);
      gdir.load("from: " + fromAddress + " to: " + "11500 Obee Rd, Whitehouse Oh, 43571 @41.538181, -83.816626",
                { "locale": locale });
	  
    }

    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("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.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("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.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	}

	function onGDirectionsLoad(){ 
          // Use this function to access information about the latest load()
          // results.

          // e.g.
	  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
	  // and yada yada yada...
	 
	 //document.getElementById("directionholder").style.visibility = "visible";
	}


    // Direction Functions

