// 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, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
	// 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(56,32);
    baseIcon.iconAnchor=new GPoint(16,32);
    baseIcon.infoWindowAnchor=new GPoint(16,32);

   // 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(55.578344672182055, 23.994140625);
		
	    // Priartinimas lygis
	    var zoomLevel = 7;
		
		// map kurimas nustatymas
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(point, zoomLevel);
		map.enableScrollWheelZoom();     // Ijungia zoom + scroll
		map.setMapType(G_NORMAL_MAP);   // Nustatom zhemelapio tipa
		
		// 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);
		
		
    }
}



