	var map;
    var gdir;
    var geocoder = null;
	var addressMarker;
	
// this variable will collect the html which will eventualkly be placed in the side_bar
	var kontaktu_saraso_div_html = "";
  
	// arrays to hold copies of the markers used by the side_bar
	// because the function closure trick doesnt work there
	var gmarkers = [];
	var i = 0;


	// Ikoneles kurimas Pagrindas, jo nereiktu kesiti jeigu naudojamos Google ikoneles
	//var baseIcon = new GIcon(); // - defaultine
	var baseIcon = new GIcon(baseIcon, "/images/map_icon.png", null, "null");
	// Chia galima keisti path'a, kuris nurorod ikoneles
	// Pazhiureti jas galima http://econym.googlepages.com/geicons.htm
	baseIcon.iconSize=new GSize(32,32);
    baseIcon.shadowSize=new GSize(0,0);
    baseIcon.iconAnchor=new GPoint(10,10);
    baseIcon.infoWindowAnchor=new GPoint(10,10);

   // A function to create the marker and set up the event window
   function createMarker(point,name,html) {
        var marker = new GMarker(point,baseIcon);
        GEvent.addListener(marker, "click", function() {
        //marker.openInfoWindowTabsHtml([new GInfoWindowTab(label,html), new GInfoWindowTab(label2,html2)]); // - tabsai
		  marker.openInfoWindowHtml(html); // -org
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        // add a line to the side_bar html
        kontaktu_saraso_div_html += '<div class="kontaktu_saraso_item">' + html + '<a href="javascript:myclick(' + i + ')">' + name + '</a></div>';
        i++;
        return marker;
   }

   // This function picks up the click and opens the corresponding info window
   function myclick(i) {
        GEvent.trigger(gmarkers[i], "click");
   }

   function load() {
		if (GBrowserIsCompatible()) {
			// Objekto koordinates //
			var point = new GLatLng(lat_i, lon_i);
			
			// Priartinimas lygis
			var zoomLevel = zoom;
			
			// map kurimas nustatymas
			map = new GMap2(document.getElementById("map"));
			map.setCenter(point, zoomLevel);
			map.enableScrollWheelZoom();     // Ijungia zoom + scroll
			map.setMapType(G_NORMAL_MAP);   // Nustatom zhemelapio tipa

			gdir = new GDirections(map, document.getElementById("directions"));		
			GEvent.addListener(gdir, "load", onGDirectionsLoad);
			GEvent.addListener(gdir, "error", handleErrors);
			//setDirections("Vilnius", "Kaunas", "lt_LT");
			
			// pvz ideti info ballon
			//map.openInfoWindowHtml(new GLatLng(54.8956752813, 23.8898143882), "Dariaus neplauta mashina =D...");
			
			// Mazhas zhemelapio valdymo panelis
			//map.addControl(new GSmallMapControl());
			
			// Didelis zhemelapio valdymo panelis
			map.addControl(new GLargeMapControl());
			
			// Zhemelapio tipu perjungimo panele
			//map.addControl(new GMapTypeControl());
			
			// Mastelio panele
			//map.addControl(new GScaleControl());
			
			// Sumazhinto zhemelapio panele
			//map.addControl(new GOverviewMapControl());


			// http://www.commchurch.freeserve.co.uk  http://econym.googlepages.com/index.htm 
			// Read the data from example.xml
			var request = GXmlHttp.create();
			request.open("GET", "/custom/scripts/cords_"+LANGUAGE+".xml", true);
			request.onreadystatechange = function() {
			if (request.readyState == 4) {
				var xmlDoc = GXml.parse(request.responseText);
				// 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");
					var html = GXml.value(markers[i].getElementsByTagName("infowindow")[0]);
					// create the marker
					var marker = createMarker(point,label,html);
					map.addOverlay(marker,baseIcon);
				}
				// put the assembled side_bar_html contents into the side_bar div
				//document.getElementById("kontaktu_saraso_div").innerHTML = kontaktu_saraso_div_html;
				}
			}
			request.send(null);
		}
	}
  
    function setDirections(fromAddress, locale) {
	  document.getElementById("directions").innerHTML = "";
      gdir.load("from: " + fromAddress + ", Lithuania to: " + kur,
                { "locale": locale });
    }
    function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
		 document.getElementById("directions").innerHTML = "<strong>Nieko nerasta! Ieškomas adresas gali būti naujas arba neteisingas. Taip pat paieška vykdoma tik Lietuvos ribose.</strong>";
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
		 document.getElementById("directions").innerHTML = "<strong>Klaida!</strong>";
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
		 document.getElementById("directions").innerHTML = "<strong>Tuščia užklausa!</strong>";
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
		 document.getElementById("directions").innerHTML = "<strong>Blogas Google Maps raktas!</strong>";
	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
		 document.getElementById("directions").innerHTML = "<strong>Bloga maršruto užklausa!</strong>";
	   else document.getElementById("directions").innerHTML = "<strong>Nežinoma klaida!</strong>";
	   
	}

	function onGDirectionsLoad(){ 

	}
