﻿//<![CDATA[

	var cpegeo = new GClientGeocoder();

 	  function createMapspot(pll,html,atit,adrag,aikon,isize,aleir,aspid,alm,ahide,aclick,ateru,atpic,amstip,isizex,isizey,ianchx,ianchy,iwanchx,iwanchy,azindex) {
		if (typeof atit == 'undefined') atit='';
		if (typeof adrag == 'undefined') adrag=false;
		if (typeof aikon == 'undefined') aikon='';
		if (typeof isize == 'undefined') isize=16;
		if (typeof aleir == 'undefined') aleir='';
		if (typeof aspid == 'undefined') aspid='';
		if (typeof ahide == 'undefined') ahide=false;
		if (typeof aclick == 'undefined') aclick='';
		if (typeof ateru == 'undefined') ateru='';
		if (typeof atpic == 'undefined') atpic='';
		if (typeof amstip == 'undefined') amstip='';
		if (typeof isizex == 'undefined') isizex=0;
		if (typeof isizey == 'undefined') isizey=0;
		if (typeof ianchx == 'undefined') ianchx=0;
		if (typeof ianchy == 'undefined') ianchy=0;
		if (typeof iwanchx == 'undefined') iwanchx=0;
		if (typeof iwanchy == 'undefined') iwanchy=0;
		
		var iikon;
		if (aikon) {
		  iikon = new GIcon();
		  iikon.image = aikon;
		  iikon.iconSize = new GSize(isizex?isizex:isize, isizey?isizey:isize);
		  iikon.iconAnchor = new GPoint(ianchx?ianchx:(isize/2), ianchy?ianchy:isize);
		  iikon.infoWindowAnchor = new GPoint(iwanchx?iwanchx:(isize/2), iwanchy?iwanchy:0);
		 }
		else {
		  iikon = new GIcon(G_DEFAULT_ICON);
         }		
		 
		var mapspot = new GMarker(pll,{title:atit, draggable:adrag, icon:iikon, hide:ahide, zIndexProcess: function(pmarker) { return GOverlay.getZIndex(pmarker.getLatLng().lat())-((typeof azindex != 'undefined')?azindex:((typeof pmarker.cpeTerulet == 'undefined')?0:10000)); } });
		if (ateru) {
/*
		var points = [];
  points.push(new GLatLng(46.26257, 20.169588));
  points.push(new GLatLng(46.25137, 20.169588));
  points.push(new GLatLng(46.25137, 20.175788));
  points.push(new GLatLng(46.26257, 20.175788));
  points.push(new GLatLng(46.26257, 20.169588));

			var tesztpoly = new GPolygon(points, '#0000FF', 1, 0.5, "#00FF00", 0.5, { clickable:true });
		cpemap.addOverlay(tesztpoly);
		GEvent.addListener(tesztpoly,"mouseover", function() {
		  //mapspotsinfo.alltext(lastPoint,mapspots);
		  alert(3);
		  //mapspotsinfo.show(lastPoint);
		  //cpePolyOver = true;
        });        
*/
			mapspot.cpeTerulet = cpeGetPolygonFromStr(pll,ateru);
			//if (ahide) { mapspot.cpeTerulet.hide(); } else { mapspot.cpeTerulet.show(); };
		};
        
		if (atpic) {
			mapspot.cpeTeruletKep = cpeGetTeruletKepFromPic(pll,atpic);;
		};
		
        GEvent.addListener(mapspot, "click", function(latLng) {
			//if (aktlangui=='en') $('#buborekmt'+aspid).css('display','block');
			if (html!='') mapspot.openInfoWindowHtml(html,{maxWidth:200, maxTitle:atit, maxContent:aleir});
			if (aclick) eval(aclick);
        });	
        if (ateru) {
			GEvent.addListener(mapspot.cpeTerulet, "click", function(latLng) {
				if (html!='') mapspot.openInfoWindowHtml(html,{maxWidth:200, maxTitle:atit, maxContent:aleir});
				if (aclick) eval(aclick);
			});
		};

		if (adrag) {
		  GEvent.addListener(mapspot,"dragstart", function (latLng) { 
		    mapspot.closeInfoWindow();
		    //mapspotsinfo.hide();
		    setEdit(mapspot);
		  });
		  GEvent.addListener(mapspot,"dragend", function (latLng) { 
		    setEdit(mapspot);
		  });
		 };
	
		//alert(aspid);
		mapspot.cpeLastMod = alm;
		//mapspot.cpeDeleted = false;
		mapspot.cpeSpid = aspid;
		mapspot.cpeMapon = false;
		mapspot.cpeTipus = amstip;
        //alert(mapspot.cpeSpid);
		return mapspot;
      };
	  
	  function cpeDestroyMapspot(pms) {
	    cpemap.removeOverlay(pms);
		if (typeof pms.cpeTerulet != 'undefined') cpemap.removeOverlay(pms.cpeTerulet);
		if (typeof pms.cpeTeruletKep != 'undefined') cpemap.removeOverlay(pms.cpeTeruletKep);
		//delete pms;
	  };
	  
	  function cpeGetPolygonFromStr(pll,pteru) {
		var apoints = new Array();
		var d2r = Math.PI / 180;
		var circleLat = (pteru/1000) * 0.6214 * 0.014483;
		var circleLng = circleLat / Math.cos(pll.lat() * d2r);
		var numPoints = 24;
		for (var i = 0; i < numPoints + 1; i++) { 
			var theta = Math.PI * (i / (numPoints / 2)); 
			var vertexLat = pll.lat() + (circleLat * Math.sin(theta)); 
			var vertexLng = pll.lng() + (circleLng * Math.cos(theta));
			var vertextLatLng = new GLatLng(vertexLat, vertexLng);
			apoints.push(vertextLatLng); 
		};
		var aretpoly = new GPolygon(apoints, '#0000FF', 1, 0.05, "#0000FF", 0.2, { clickable:true });
		return aretpoly;
	  };
	  
	  function cpeGetTeruletKepFromPic(pll,ptpic) {
		var d2r = Math.PI / 180;
		var circleLat = (ELT_TERU_SAV_MAX/1000) * 0.6214 * 0.014483;
		var circleLng = circleLat / Math.cos(pll.lat() * d2r);
		var picLng = ELT_TERU_PIC_WIDTH/ELT_TERU_PIC_HEIGHT * circleLng;
		var bnd = new GLatLngBounds(new GLatLng(pll.lat() - circleLat,  pll.lng() - picLng),new GLatLng(pll.lat() + circleLat,  pll.lng() + picLng));
		var terukep = new GGroundOverlay(ptpic, bnd);
		return terukep;
	  };
//]]>

