    var clusterer,map,zoomToThat,baseIcon,icon,sec,viewInfoData,url,func,marker,mmarkers = Array(),markersid,ciID=null;
    
    function load() {
        if (!GBrowserIsCompatible()) {
            return;
        }
        G_DEFAULT_ICON.shadow = "";
    	map = new GMap2(document.getElementById("map"));
    	goToTurkey();
    	var typePosition = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,35));
    	var controlPosition= new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,60));
    	map.addControl(new GLargeMapControl(), controlPosition);
    	map.addControl(new GMapTypeControl(),typePosition);
    	map.addControl(new GOverviewMapControl());
    	map.addControl(new GScaleControl());
   		map.setMapType(G_NORMAL_MAP);
  	 	map.enableScrollWheelZoom();
  	 	clusterer = new Clusterer(map);
        clusterer.SetMaxVisibleMarkers(10);
        clusterer.SetMaxLinesPerInfoBox(5);

	baseIcon = new GIcon();
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(15, 15);
	baseIcon.shadowSize = new GSize(15, 15);
	baseIcon.iconAnchor = new GPoint(0, 0);
	baseIcon.infoWindowAnchor = new GPoint(0, 0);
	baseIcon.infoShadowAnchor = new GPoint(18, 25);
    }

    function parsePoints(data, responsecode) {
        var xml = GXml.parse(data);
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
            var lat = markers[i].getAttribute("lat");
            var lng = markers[i].getAttribute("lng");
            lat = lat == null || lat.length == 0 ? 0 : parseFloat(lat);
            lng = lng == null || lng.length == 0 ? 0 : parseFloat(lng);
            var city = markers[i].getAttribute("city");
            var country = markers[i].getAttribute("country");
            var name = unescape(markers[i].getAttribute("name"));
            var id = markers[i].getAttribute("id");
            var link = markers[i].getAttribute("link");
            var image = markers[i].getAttribute("image");
            var sec = markers[i].getAttribute("sec");
            var description = markers[i].getAttribute("description");
            if(zoomToThat==1) {
            	map.setCenter(new GLatLng(lat,lng), 11);
            	zoomToThat = 0;
            }
            /*label += name +"</a></div>";
            var title = "<a id='title' rel='"+ ARKIV_urlProjectPhotoThumbnail + image +"' href='" + ARKIV_baseUrl + link + "' target='_blank'>" + name + "</a><br />";*/
            var title = "<a href='javascript:goToCoordinates(\"" + lat + "\",\"" + lng + "\",15);'>" + name + "</a><br/>";
            var point;
            if ( lat != 0 && lng != 0 ) { // if coordinates found, use that point
                point = new GLatLng(lat, lng);
                marker = createMarker(point, description, sec);
				clusterer.AddMarker(marker, title); // name is title in cluster list
				mmarkers[markersid].push(marker);
				//alert(markersid);
				marker = null;
             } 
        }
       $("div#loading").hide();
    }
    
    
    function geocodeMarker(label, name) {
        // we have to pass a reference to a function to geocodeMarker, but we also have to copy the value of label.
        // using the anonymous function inline would always use the last value of 'label' in the loop
        return function(point) {
            if (point) {
                clusterer.AddMarker(createMarker(point, label), name);
            }
        };
    }
    
    // Creates a marker at the given point with the given number label
    function createMarker(point, label,icon) {
		var markericon = new GIcon(baseIcon);
		markericon.image = baseUrl + "images/icons/" + icon + "_pin.png";
		markericon.smallImage = baseUrl + "images/icons/" + icon + "_on.png";
		markericon.shadow = baseUrl + "images/icons/shadow.png";
		markericon.iconSize = new GSize(20, 34);
		markericon.shadowSize = new GSize(37, 34);
		markericon.iconAnchor = new GPoint(10, 34);
		markericon.infoWindowAnchor = new GPoint(5, 1);
        var marker = new GMarker(point, markericon);
       GEvent.addListener(marker, "click", function() {
       marker.openInfoWindowHtml(label);
        });
        return marker;
    }

    var timeoutId;
    function refreshMap(millis) {
        clearTimeout(timeoutId);
        if (millis == undefined) {
            millis = 2000;
        }
        timeoutId = setTimeout('reloadMap()', millis);
    }

    function reloadMap(id,url,dontRemoveOther) {
        //<%-- 
        // Download the data in data.xml and load it on the map. The format we
        // expect is:
        // <markers>
        //   <marker lat="37.441" lng="-122.141"/>
        //   <marker lat="37.441" lng="-122.141"/>
        //   <marker lat="37.322" lng="-121.213"/>
        // </markers>
        // pass parsePoints as a function reference
        //--%>
		//alert(sec);
		markersid = id;
		mmarkers[markersid] = new Array();
		Clusterer.defaultIcon.image = baseUrl + "images/icons/cluster.png";
		Clusterer.defaultIcon.shadow = baseUrl + "images/icons/cluster_shadow.png";
		Clusterer.defaultIcon.iconSize = new GSize(25, 50);
		Clusterer.defaultIcon.shadowSize = new GSize(37, 34);
        clusterer.map.closeInfoWindow();
		clusterer.map.SetIcon = icon;
		if(!dontRemoveOther)
		clusterer.RemoveAll();
		$("div#loading").show();
		url = (url) ? url : layers[id].url; 
		//alert("reload CityID" + ciID);
		url = url + "&ciID="+ciID; // Add cityID
       	GDownloadUrl(url, parsePoints);     
    }
        
        
    
    function toggleURL(id,dontRemoveOther) {
    		//alert(removeSingle);
   			reloadMap(id,null,dontRemoveOther);
   			changePageUrl("toggleURL",null,id);
   			//goToTurkey();
}	
    function togglePeople(id,urllink,dontRemoveOther) {
    		//alert(removeSingle);
   			reloadMap(id,urlLink,dontRemoveOther);
   			changePageUrl("toggleURL",null,id);
   			//goToTurkey();
}
/*  
function zoomToGeoXML(geoXml) {
  var center = geoXml.getDefaultCenter();
  var span = geoXml.getDefaultSpan();
  var sw = new GLatLng(center.lat() - span.lat() / 2,
                       center.lng() - span.lng() / 2);
  var ne = new GLatLng(center.lat() + span.lat() / 2,
                       center.lng() + span.lng() / 2);
  var bounds = new GLatLngBounds(sw, ne);
  map.setCenter(center);
  map.setZoom(10);
}*/

function goToCity(city,sec) {
if(city==0) {
goToTurkey();
} else {
	//clusterer.RemoveAll();
	cityArray = city.split("|");
	ciID = cityArray[0];
	goToCoordinates(cityArray[1], cityArray[2],10);
	if(sec != 0) {
	if(sec == null)
	sec = 'pr1,pr6,pr13,pr21,pr35,pr45,pr56,pr65,pr71,pr81,pr92,of,fo,sf';
	secparts = sec.split(",");
	for(i=0;i<secparts.length;++i){
	reloadMap(secparts[i],layers[secparts[i]].url,0);
	}
	changePageUrl("goToCity",ciID,'');
	}
	
}
	}
	
	function goToCoordinates(lat,lon,zoomLevel) {
		map.setCenter(new GLatLng(lat,lon,5), zoomLevel);
	}
	function goToTurkey() {
	map.setCenter(new GLatLng(39,35,5), 6);
	ciID = null; 
	}
function goTo(urllink,zoom){
	zoomToThat = (zoom==1) ? 1 : 0;
	url = urllink;
	reloadMap(null,urllink,0);
	//alert(urllink);
	//changePageUrl("goTo",null,urllink);
}

function getCenter(lat,lng) {
	map.setCenter(new GLatLng(lat,lng), 10);
}
function changePageUrl(func,ciID,urllink) {
	$(document).ready(function(){
	$("input#pageurl").attr("value",baseUrl + "?func="+func+"&ciID="+ciID+"&urllink=" + escape(urllink));
	});
}
function addPoint() {
			// Create our "tiny" marker iconvar 
		icon = new GIcon();
		icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
		icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
		icon.iconSize = new GSize(12, 20);
		icon.shadowSize = new GSize(22, 20);
		icon.iconAnchor = new GPoint(6, 20);
		icon.infoWindowAnchor = new GPoint(5, 1);
		var center = map.getCenter();
        var marker = new GMarker(center, {draggable: true});
     	     
     	GEvent.addListener(marker, "dragstart", function() {
         // map.closeInfoWindow();
        });      
        GEvent.addListener(marker, "dragend", function() {
       var markerpoint = marker.getPoint();
      $("input#coordinates").val(markerpoint.toString());
      $("span#coordinates_text").html(markerpoint.toString());
      
      // marker.openInfoWindowHtml($("span#pointTitle").html());
        });
        map.addOverlay(marker);
       // marker.openInfoWindowHtml($("span#pointTitle").html());
        $("input#coordinates").val(center.toString());
      	$("span#coordinates_text").html(center.toString());
      	$("input#pointSubmitButton").removeAttr("disabled");
      	$("input#addPointButton").attr("disabled","true");
}
function insertPoint() {
if(confirm("Girişinizin doğruluğundan eminseniz devam etmek için 'OK' düğmesine basınız.\n\rYaptığınız yanlış girişlerin kural ihlal sistemindeki karşılığı 2 puandır.")){
	location.href = 'insertpoint.php?sec='+$("input#sec").attr("value")+'&ID='+$("input#ID").attr("value")+'&coordinates=' + $("input#coordinates").attr("value");
	}
}
function getPeopleSearch(sPattern) {
$.ajax ({
        type            : 'GET',
        dataType        : 'html',
        url             : 'search.php?sec[]=pe&sPattern=' + sPattern,
        success        	: function(data)
        {
        		$("div#peoples_list_text").html(data);
              	$("div#peoples_list").fadeIn("slow");
        }	
});
};  // <end> function