var map;
var gdir;

function initialize() {
	if (GBrowserIsCompatible()) {  
		
		
		var center = new GLatLng(46.071483,18.209517);
		/*var center = new GLatLng(46.071783,18.215081);*/  
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(center, 14);
		
		var mapTypeControl1 = new GMapTypeControl();
		var mapTypeControl2 = new GLargeMapControl();
		
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
		var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10));
		
		map.addControl(mapTypeControl1, topRight);
		map.addControl(mapTypeControl2, topLeft);
		
		var marker = new GMarker(center);
		GEvent.addListener(marker, "click", function() {
			var html = '<div style="width: 250px; padding-right: 10px"><strong>MarkCon Csoport<\/strong><br>KOMMUNIKÁCIÓS KFT. | INFORMATIKAI KFT.<br>7623 Pécs, Móré Fülöp utca 33.<br>Tel.: +36 72 222 893 | Fax.: +36 72 510 678<\/div>';
			marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
		GEvent.trigger(marker, "click");
		
	    gdir = new GDirections(map, document.getElementById("directions"));
	    GEvent.addListener(gdir, "load", onGDirectionsLoad);
	    GEvent.addListener(gdir, "error", handleErrors);
	}
}

function setDirections(fromAddress, toAddress, locale) {
	gdir.load("from: " + fromAddress + " to: Móré Fülöp utca 33, 7623 Pécs, Hungary", { "locale": "hu" });
}

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_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...
}

var temp_load;
if(window.onload) {
    temp_load = window.onload;
}

window.onload = function() {
    if(temp_load) {
        temp_load();
    }
    initialize();
}

var temp_unload;
if(window.onunload) {
	temp_unload = window.onunload;	
}

window.onunload = function() {
	if(temp_unload) {
		temp_unload();
	}
	GUnload();
}

