
function Gmaps(){
this.MAP
this.MGR
this.ICONO1
this.ICONO2
this.GEOCODER=null;
this.LOCALIZACIONES=new Array();
this.GEOCODER = new GClientGeocoder();
}


Gmaps.prototype.addlocalizacion=function(id,coordenadas,html,zoom,mostrar){

indice=this.LOCALIZACIONES.length;
this.LOCALIZACIONES[indice]=new Array();
this.LOCALIZACIONES[indice][0]=id;
//alert(2);
//alert(parseFloat(coordenadas.split(",")[0]))
_x=parseFloat(coordenadas.split(",")[0])
_y=parseFloat(coordenadas.split(",")[1])

this.LOCALIZACIONES[indice][1]=new GLatLng(_x,_y)
       var infoTabs = [
	  new GInfoWindowTab("Tab "+id, html)
	];
this.LOCALIZACIONES[indice][2]= infoTabs
this.LOCALIZACIONES[indice][3]=zoom;
//alert(5);
 //var newIcon = MapIconMaker.createMarkerIcon({width: 40, height: 40,primaryColor: "#00ff00"});
  
//var gg=new Image();
//gg.src='/images/marca.png';
this.ICONO1 = new GIcon();
this.ICONO1.iconSize = new GSize(80, 30);
this.ICONO1.shadowSize = new GSize(0, 0);
this.ICONO1.image = "images/marca.png";

this.ICONO1.iconAnchor = new GPoint(44, 30);
this.ICONO1.infoWindowAnchor = new GPoint(44, 30);
this.ICONO1.imageMap = [ 10, 11, 12, 13, 14, 15 ];




  //icono.iconAnchor = new GPoint(53, 253);
this.LOCALIZACIONES[indice][4]=new GMarker(this.LOCALIZACIONES[indice][1],this.ICONO1);
this.LOCALIZACIONES[indice][5]=this.ICONO1
this.LOCALIZACIONES[indice][7]=html;
this.LOCALIZACIONES[indice][8]=mostrar;
this.LOCALIZACIONES[indice][9]=coordenadas;
//alert(6);


}

Gmaps.prototype.getlocalizacion=function(){


prompt('',this.MAP.getCenter());


}




Gmaps.prototype.getIcon=function() {
      var icon = null;
   
          icon = new GIcon();
          icon.image = "images/marca.png";
         
          icon.iconSize = new GSize(80, 30);
          icon.iconAnchor = new GPoint(80 >> 1, 30 >> 1);
         // icon.shadow = "images/"  + images[1] + ".png";
      
          icon.shadowSize = new GSize(80, 30);
        //  icons[images[0]] = icon;
      
      return icon;
    }

 












Gmaps.prototype.iniciamapa=function(id,auto){
var valort
if (GBrowserIsCompatible()) 
{
 //GEvent.addListener(be.MAP,  "click", function()  {  $('coord').innerHTML=gApplication.getMap().getCenter() });

this.MAP = new GMap2($("map"));
this.MAP.setMapType(G_NORMAL_MAP);
this.MAP.addControl(new GSmallMapControl());
this.ICONO2 = new GIcon();
this.ICONO2.iconSize = new GSize(25, 30);
this.ICONO2.shadowSize = new GSize(0, 0);
this.ICONO2.image = "images/marca2.png";
this.ICONO2.iconAnchor = new GPoint(10, 30);
this.ICONO2.infoWindowAnchor = new GPoint(10, 30);
this.ICONO2.imageMap = [ 10, 11, 12, 13, 14, 15 ];


if (auto=='internacional'){
this.MAP.setCenter(new GLatLng(40.27952566881291, -3.515625), 2)
}else{

this.MAP.setCenter(new GLatLng(40.27952566881291, -3.515625), 6)
}



		  for (i=0;i<this.LOCALIZACIONES.length;i++)
		  {
		     var _id=this.LOCALIZACIONES[i][0]
		//	 alert('ggg: '+_id);
		     var _coordenadas=this.LOCALIZACIONES[i][1]
			 
			  var infoTabs = [
	  new GInfoWindowTab("Tab "+id, this.LOCALIZACIONES[i][7])
	];

this.LOCALIZACIONES[indice][2]= infoTabs
			 
			 
		     var _html=this.LOCALIZACIONES[i][2]
		     var _zoom=this.LOCALIZACIONES[i][3]
		     var _marcador=this.LOCALIZACIONES[i][4]
		    // this.LOCALIZACIONES[i][6]= 
			 this.MAP.addOverlay(_marcador);
		     if (id==_id){
			  valort=i;
				   this.MAP.setCenter(_coordenadas, _zoom);
			   
			   _marcador.openInfoWindowTabsHtml(getHTML(i)); 
			   
			 
			    
				 
			  }else{
			   //  GEvent.addListener(this.LOCALIZACIONES[i][4],  "click", function()  {alert('uuuuuuu')  });	 
			  }
			    eval(' be.GMAPS.LOCALIZACIONES['+i+'][6]=GEvent.addListener(be.GMAPS.LOCALIZACIONES['+i+'][4],  "click", function()  {be.GMAPS.LOCALIZACIONES['+i+'][4].openInfoWindowTabsHtml(getHTML('+i+')); cambiaprov(be.GMAPS.LOCALIZACIONES['+i+'][0]); });')	 
 
			 // alert(this.LOCALIZACIONES[i][4].getPoint())
			  var contador=i;
				  // GEvent.addListener(be.GMAPS.LOCALIZACIONES[contador][4],  "click", function()  {alert('blablabla') ;be.GMAPS.LOCALIZACIONES[contador][4].openInfoWindowTabsHtml(be.GMAPS.LOCALIZACIONES[contador][2]); });	 
		 }
		
 
	
		//   GEvent.addListener(this.LOCALIZACIONES[i][4],  "click", function()  {alert(_id)  ; _marcador.openInfoWindowTabsHtml(_html); });	 
		 
	if ( this.MAP.getZoom()>14){this.outlineMark(null,this.ICONO2,this.MAP.getZoom())}else{this.outlineMark(_marcador,this.ICONO1,this.MAP.getZoom())}; 
		// $('zoom').innerHTML=this.MAP.getZoom() ;
		if (id==''){}else{
		setTimeout(function(){ try{eval('be.GMAPS.LOCALIZACIONES['+valort+'][4].openInfoWindowTabsHtml(getHTML('+valort+'))')}catch(e){}},500); 
		}
		
		
}
var feo=this;





GEvent.addListener(this.MAP, "move", function() { try{  $('coord').innerHTML=feo.MAP.getCenter() ;  }catch(e){} });
GEvent.addListener(this.MAP, "zoomend", function() { if ( feo.MAP.getZoom()>14){feo.outlineMark(_marcador,feo.ICONO2,feo.MAP.getZoom())}else{feo.outlineMark(_marcador,feo.ICONO1,feo.MAP.getZoom())};try{ $('zoom').innerHTML=feo.MAP.getZoom() ;  }catch(e){}});
}

Gmaps.prototype.outlineMark=function(_marcador, icon,zoom){


  for (i=0;i<this.LOCALIZACIONES.length;i++)
		  {
		  
		    if (zoom>10){
			
			}else{
		
		//	icon.iconSize = new GSize(25-zoom, 30-zoom);
//icon..shadowSize = new GSize(0, 0);
//icon..image = "images/marca2.png";

//icon..iconAnchor = new GPoint(10-, 30);
//icon..infoWindowAnchor = new GPoint(10, 30);
	
			}
		  
		  
		  try{
		GEvent.removeListener(this.LOCALIZACIONES[i][6])
		 var _id=this.LOCALIZACIONES[i][0]
		
		  var marca=this.LOCALIZACIONES[i][4];
    this.MAP.removeOverlay(this.LOCALIZACIONES[i][4])
_marca=new GMarker (marca.getPoint(), icon)
    this.LOCALIZACIONES[i][4] = _marca
	  var infoTabs = [
	  new GInfoWindowTab("Tab "+this.LOCALIZACIONES[i][0], this.LOCALIZACIONES[i][7])
	];

this.LOCALIZACIONES[indice][2]= infoTabs
	var _html=this.LOCALIZACIONES[i][2]
   this.MAP.addOverlay(this.LOCALIZACIONES[i][4])
   var feo=this
  if (zoom>14){
 
 eval(' be.GMAPS.LOCALIZACIONES['+i+'][6]=GEvent.addListener(be.GMAPS.LOCALIZACIONES['+i+'][4],  "click", function()  { be.GMAPS.LOCALIZACIONES['+i+'][4].openInfoWindowTabsHtml(getHTML('+i+'));cambiaprov(be.GMAPS.LOCALIZACIONES['+i+'][0]); });')
   }else{
  if (this.LOCALIZACIONES[i][8]==1){
  eval('be.GMAPS.LOCALIZACIONES['+i+'][6]=GEvent.addListener(be.GMAPS.LOCALIZACIONES['+i+'][4],  "click", function()  {  be.GMAPS.situazona(be.GMAPS.LOCALIZACIONES['+i+'][4].getPoint(),14);try{eval(\'be.GMAPS.LOCALIZACIONES['+i+'][4].openInfoWindowTabsHtml(getHTML('+i+'))\');cambiaprov(be.GMAPS.LOCALIZACIONES['+i+'][0]);}catch(e){} });')
  // setTimeout(function(){ },500);
  
  }else{
  
   eval(' be.GMAPS.LOCALIZACIONES['+i+'][6]=GEvent.addListener(be.GMAPS.LOCALIZACIONES['+i+'][4],  "click", function()  { be.GMAPS.LOCALIZACIONES['+i+'][4].openInfoWindowTabsHtml(getHTML('+i+'));cambiaprov(be.GMAPS.LOCALIZACIONES['+i+'][0]); });')
  
  
  }
   }
		
		 //this.LOCALIZACIONES[i][4].openInfoWindowTabsHtml(this.LOCALIZACIONES[i][2]); 
}catch(e){}
     
}

}
Gmaps.prototype.situazona2=function(id,zoom){
  for (i=0;i<be.GMAPS.LOCALIZACIONES.length;i++)
		  {
		  var mostrar=0;
		  	var ty=0;
		  if (id==be.GMAPS.LOCALIZACIONES[i][0]){
		 
		  ty=i;
		if  (be.GMAPS.LOCALIZACIONES[i][8]==1){
		mostrar=14
		}else{
		mostrar=6
		}
		
	
		  
		 be.GMAPS.situazona(be.GMAPS.LOCALIZACIONES[i][1],mostrar)
		//  alert(be.GMAPS.LOCALIZACIONES[i][1])

		  break;
		  }
		  
		  }
setTimeout("eval('be.GMAPS.mostrartab("+ty+")') ",900);

}
Gmaps.prototype.mostrartab=function(num){

try{
eval("be.GMAPS.LOCALIZACIONES["+num+"][4].openInfoWindowTabsHtml(getHTML("+num+"))")
}catch(e){}


}

function cambiaprov(id){

if ($('fprovincia').value==id.split('_')[2]){


}else{

$('fprovincia').value=id.split('_')[2];

be.VALUE=id;
//$('fagente').value=id;
buscaselects($('fprovincia'));
}





}




 Gmaps.prototype.pcoord=function(id,coordenadas,html,zoom,mostrar) {
 		//be.GMAPS.MAP.clearOverlays() ;

    	if (be.GMAPS.GEOCODER) {
		//alert('cargado');
        	be.GMAPS.GEOCODER.getLatLng(coordenadas,
          		function(point) {
            		if (!point) {
            			alert(address + " no encontrada");
            		} else {
				//	alert(point.y+","+point.x)
					be.GMAPS.addlocalizacion(id,point.y+","+point.x,html,zoom,mostrar)
					
               		}
               	}
        	);
      	}
}





Gmaps.prototype.situazona=function(localizacion,zoom){
this.MAP.setCenter(localizacion, zoom);
}

function getHTML(num){
  var infoTabs = [
	  new GInfoWindowTab("Tab "+be.GMAPS.LOCALIZACIONES[num][0], be.GMAPS.LOCALIZACIONES[num][7])
	];

be.GMAPS.LOCALIZACIONES[num][2]= infoTabs

return infoTabs;

}
