	var map ; 
	function debug(val) {
		alert(val)
	}
	function resize_() {
		
		
			escala() 
				if(  mapa_abierto  ) { 
			mapa_web_tv.muestra_controles(true)
		}
	}
	function checks(val) {
		if( val )
		FancyForm.all() 
		else 
		FancyForm.none()
		
	}
	function unflot() {
		
		if(contacto_abierto) { 
			cerrar_contacto()
			return ;
		}
		$('flotante').setStyles({display: 'none'});
		$('fondo_flotante').setStyle('display' , 'none') ; 
		$('iframe_flotante').setStyle('display' , 'none') ;
		setup(false) ; 
		return ;  
	}

	function setup(open){
		
		var fn = open ? 'addEvent' : 'removeEvent';
		window[fn]('scroll', this.eventPosition)[fn]('resize', eventPosition);
		document[fn]('keydown', eventKeyDown);
		
	}
	function saca_frame() {
		$('cargador').setStyle('display' , 'none') ;
		$('iframe_flotante').setStyle('display' , 'block') ;
		
	}

	function fin_contacto() {
		$('cargador_contacto').setStyle('display' , 'none') ;
		$('iframe_flotante_contacto').setStyle('display' , 'block') ;
		
		
	}
	var contacto_abierto = false 
	function contacto() { 
		if( contacto_abierto)
			return ; 
		contacto_abierto = true 
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		altura = st + (wh / 15);
		
		$('flotante_contacto').setStyles({top: altura+'px', display: 'block'});
		$('fondo_flotante').setStyle('display' , 'block')
		//alert( id )
		$('iframe_flotante_contacto').src = 'contacto.php'  
		$('cargador_contacto').setStyle('display' , 'block') ;
		setup(true) ; 
		return ; 

	}
	function cerrar_contacto() {
		
		if(!contacto_abierto)
			return ; 
		$('flotante_contacto').setStyles({display: 'none'});
		$('fondo_flotante').setStyle('display' , 'none') ; 
		$('iframe_flotante_contacto').setStyle('display' , 'none') ;
		setup(false) ; 
		contacto_abierto = false 
		return ;  
	}
	function flot(id) {
		
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		altura = st + (wh / 15);
		
		$('flotante').setStyles({top: altura+'px', display: 'block'});
		$('fondo_flotante').setStyle('display' , 'block')
		//alert( id )
		$('iframe_flotante').src = 'flotante.php?s=menu&id_articulo=' + id 
		$('cargador').setStyle('display' , 'block') ;
		setup(true) ; 
		return ;  
	}
	function eventKeyDown(event){
		
		switch (event.keyCode){
			case 27: case 88: case 67: unflot(); 
			break;
		}
	}
	function eventPosition(){
		//IE6 - XML prolog problem.
		var ww = (window.getWidth() == 0) ? window.getScrollWidth()-22 : window.getWidth();
		var wh = (window.getHeight() == 0) ? window.getScrollHeight() : window.getHeight();
		var st = document.body.scrollTop  || document.documentElement.scrollTop;
		$('fondo_flotante').setStyles({top: st+'px', height: wh+'px', width:ww+'px'});
		
	}

	function saca_flotante(id) { 
	
		//Lightbox.show('flotante.php?s=menu&id_articulo=' + id , '' , 'width=680, height=530' , 0.8 );
		
		flot(id) ; 
		return  ;
				
	}
	
	function saca_flotante_mapa(id , m ) { 
	
		//Lightbox.show('flotante.php?s=map&id=' + id , '' , 'width=300, height=300' , 0 );
		//Lightbox.show('flotante.php?s=map&id=' + id, '' , 'width=680, height=530' , 0);
		return ;
		el = $('link_' + id ) ; 
		if (!el)
		{
			return 
		}
		//el.setStyle('top' , m.y )
		//el.setStyle('left' , m.x )
		el.href = 'flotante.php?s=map&id_articulo=' + id 
		box.open(el)
	}
	function cierra_flotante() { 
		//box.close() 
		//parent.ventana.hide()
		unflot()
		//Lightbox.close() ;
	}
	function carga(data) {
		try
		{
				var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
          for (var i = 0; i < markers.length; i++) {
				var opciones = {} ; 
				
				var id = parseInt(markers[i].getAttribute("id"))
				var lat = parseFloat(markers[i].getAttribute("lat"))
				var lng = parseFloat(markers[i].getAttribute("lng"))
				opciones.nom = markers[i].getAttribute("nom")
				opciones.tex = markers[i].getAttribute("tex")
				opciones.fic = markers[i].getAttribute("fic")
				opciones.cat = markers[i].getAttribute("cat")
				opciones.dir = markers[i].getAttribute("d")
				opciones.cod = markers[i].getAttribute("c")
				
				mapa_web_tv.addMarker( id , lat , lng , opciones ) ;
			 }
		}
		catch (e)
		{
			alert( "error cargando " + e.description )
		}
          
    }

	
	 function load_mapa() {

      if (GBrowserIsCompatible()) {
		  //return ;
		  try
		  {
				map = new GMap2(document.getElementById("google_map"));
				map.setCenter(new GLatLng( 39.473 , -0.3755), 15);
				map.enableContinuousZoom()
				//geocoder = new GClientGeocoder(); // para buscar calles
				mapa_web_tv = new Gmapa(map) ;
				map.setMapType(G_SATELLITE_MAP) ; 
				GDownloadUrl("markers.xml.php", carga );
				//svOverlay = new GStreetviewOverlay();
				//map.addOverlay(svOverlay);
				//var mapControl = new GOverviewMapControl();
				//map.addControl(mapControl);


		  }
		  catch (e)
		  {
			alert("error llamando XML " + e.description )
		  }
       
      }
    }
	function escala() { 
		
		var altura = window.getScrollHeight() //-  parseInt( $('mapa_topbar').getStyle('height') ) ;  //window.getHeight() ; 
		//$('div_mapa').setStyle('height' , '400px' );
		$('div_mapa').setStyle('height' , altura );
		if( window.ie6 )
			$('google_map').setStyle('height' , altura );
		//alert($('div_mapa').getStyle('height') ) 
		//alert($('div_mapa').getStyle('height') ) 
		
		//$('menu_mapa').setStyle("bottom" , ventana )
	}

	function ajusta() { 
			//$(document.body).setStyle('overflow','hidden'); 
			$(document.documentElement).setStyle('overflow','hidden');
			return ;
			var altura = window.getHeight() //-  parseInt( $('mapa_topbar').getStyle('height') ) ; 
			$('div_mapa').setStyle('height' , altura );
		}
	//// clase Gmapa ///////////////////////////////////////////////

	function Gmapa( map ) { 
		
		try
		{
			this.controlLarge =  new GLargeMapControl( )  
			//this.controlType =  new GMapTypeControl()
			this.mapa = map 
			this.capas = new Array()
			categorias.each(  function(item , index ) 
				{
					this[item] = new Gcapa( this , id_categorias[index] , null );
					this.capas.push( this[item] ) ; 
				} , this 
			)
			this.zoom = 15
			this.zoom_cerrado = 15
		}
		catch (e)
		{
			debug("error creando Gmapa " +  e ) // e.description )
		}
		
	}
	
	Gmapa.prototype.muestra_controles = function ( val ) { 
		if( val ) { 
			try
			{			
				
					
				this.mapa.addControl( this.controlLarge , new GControlPosition(G_ANCHOR_BOTTOM_LEFT , new GSize(10, window.getScrollHeight() - window.getHeight() + 20 ) ) );
				checks(true)
				//this.mapa.addControl( this.controlType );
				//this.setZoom(this.zoom)
			}
			catch (e)
			{
				alert("error " + e  + " " + altura )
			}
		} else { 
			try
			{			
				
					this.mapa.removeControl(this.controlLarge)
					this.zoom = this.getZoom() ;
					//this.setZoom(this.zoom_cerrado)
					//this.mapa.removeControl( this.controlType );
					//this.mapa.removeControl(G_PHYSICAL_MAP)
			}
			catch (e)
			{
				alert("error " + e )
			}
		}
	}
	Gmapa.prototype.addMarker = function ( id , lat , lng , opciones ) { 

		try
		{			
			this.getCapa(opciones.cat).addMarker( id , lat , lng , opciones ) 
		}
		catch (e)
		{
			alert("error " + e )
		}
	}
	
	Gmapa.prototype.getCapa = function ( tipo ) {
		for ( var i in this.capas )
		{
			if( this.capas[i].tipo == tipo  ) 
				return this.capas[i]

		}
		return null 
	}
	Gmapa.prototype.verCapa = function ( tipo ,  ver ) {

		if( !ver )
			this.escondeCapa(tipo)
		else 
			this.muestraCapa(tipo)

	}
	Gmapa.prototype.escondeCapa = function ( tipo ) {
		try
		{
			this.getCapa(tipo).esconde() 
		}
		catch (e)
		{
		}
			
	}
	
	Gmapa.prototype.muestraCapa = function ( tipo ) {
		try
		{
			this.getCapa(tipo).muestra() 
		}
		catch (e)
		{
		}
	}

	Gmapa.prototype.selectMarker = function ( id ) {
		try
		{
			//alert( this.capas.length )
			for ( var i=0 ; i<this.capas.length  ; i++ )			
			{
				//alert( this.capas[i].puntos.length )
				if( this.capas[i].puntos.length == 0   )
					continue ; 
				for (var j=0 ; j<this.capas[i].puntos.length ; j++ ) {
					//alert( this.capas[i].puntos[j].webTvMarker.id , id  )
					if( this.capas[i].puntos[j].webTvMarker.id == id )
						return this.capas[i].puntos[j].webTvMarker
				}

			}
			return null 
		}
		catch (e)
		{
				alert( "error select " + e )
		}
	}

	Gmapa.prototype.muestraSolo = function ( marcador ) {
		try
		{
			checks(false)
			//alert( this.capas.length )
			marcador.capa.addMarker(marcador , 0 )
			/*for ( var i=0 ; i<this.capas.length  ; i++ )			
			{

				//alert( "capa " + i )
				if( this.capas[i].puntos.length == 0   )
					continue ; 
				this.capas[i].muestraSolo( marcador ) ;

			}*/
			
			this.mapa.setCenter( marcador.getLatLng() )
			this.mapa.setZoom(16)
			return null 
		}
		catch (e)
		{
				alert( "error select " + e )
		}
	}

	Gmapa.prototype.buscaMarker = function ( id ) {
		try
		{
			var marcador = this.selectMarker( id )
			
			if( marcador != null ) { 
				esconde_paneles() ; 
				//alert("errorrrrrrrrrrrrrrrr "  )
				this.muestraSolo( marcador.marker )
				
				
					//GEvent.trigger(marcador.marker ,  "click")
			}
		}
		catch (e)
		{
				//alert("errorrrrrrrrrrrrrrrr " + e )
		}
	}

	Gmapa.prototype.cambia_mapa = function () {
		try
		{
				this.mapa.setMapType(G_NORMAL_MAP)
		}
		catch (e)
		{
				
		}
	}
	Gmapa.prototype.cambia_satelite = function () {
		try
		{
				this.mapa.setMapType(G_SATELLITE_MAP)
		}
		catch (e)
		{
				
		}
	}

	Gmapa.prototype.hibrido = function () {
		try
		{
				this.mapa.setMapType(G_HYBRID_MAP)
		}
		catch (e)
		{
				
		}
	}

	Gmapa.prototype.setZoom = function (level) {
		try
		{
				this.mapa.setZoom(level)
		}
		catch (e)
		{
				
		}
	}

	Gmapa.prototype.getZoom = function () {
		try
		{
				return this.mapa.getZoom()
		}
		catch (e)
		{
				
		}
	}
	



	////// clase capa ///////////////////////////////////////////////
	function Gcapa( _mapa , _tipo , _icono ) { 
		this.mapa = _mapa 
		this.tipo = _tipo ; 
		this.icono = _icono ;
		this.capa = new MarkerManager( _mapa.mapa , null );
		this.puntos = new Array() ;  
	}

	Gcapa.prototype.addMarker = function( id , lat , lng , opciones ) { 
		
		var marc = new webTvMarker( id , lat , lng , opciones , this.capa ) ; 
		this.capa.addMarker(  marc  , 0  ) ; 
		this.puntos.push( marc ) ; 
		//this.capa.refresh() ;
	}

	Gcapa.prototype.esconde = function() { 
		this.capa.clearMarkers() ;
	}
	Gcapa.prototype.muestraSolo = function(marcador) { 
		for ( var i=0 ; i<this.puntos.length  ; i++ )		{ 	
			//alert( "punto " + i )
			if( this.puntos[i] != marcador )
				this.capa.removeMarker(this.puntos[i]) ; 
		}

		
	}
	Gcapa.prototype.muestra = function() { 
		this.capa.addMarkers( this.puntos , 0  ) ;
		this.refresh() ;
	}

	Gcapa.prototype.refresh = function() { 
		this.capa.refresh() ;
	}
	
	////// clase web_marker ///// 

	function webTvMarker( id , lat , lng , opciones , capa  ) { 
		
		this.id = id ; 
		this.lat = lat 
		this.ln = lng 
		this.visible = true 
		this.nom = opciones.nom
		this.tex = opciones.tex 
		this.fic = opciones.fic 
		this.cat = opciones.cat 
		this.dir = opciones.dir 
		this.cod = opciones.cod 
		this.marker = new GMarker( new GLatLng( lat, lng ) , new Wicono(this.cat) ) ; 
		//.setImage(this.icono_activado)
		GEvent.addListener( this.marker , "click", this.openInfoWindowHtml );
		GEvent.addListener(this.marker , "mouseover", this.toolTip ); 
		GEvent.addListener(this.marker , "mouseout", this.untoolTip ); 
		this.marker.webTvMarker = this ;
		this.marker.capa = capa ;
		this.marker.title = opciones.nom 
		
			return this.marker ; 
	}

	webTvMarker.prototype.toolTip = function() { 
					
			

		Tip( this.webTvMarker.nom , BALLOON, true, ABOVE, true , OFFSETX, -15  )
		
	}
	webTvMarker.prototype.untoolTip = function() { 
					
			

		UnTip()
		
	}

	webTvMarker.prototype.openInfoWindowHtml = function() { 
			 //var punto = map.fromLatLngToDivPixel( this.getLatLng() )
			 //alert( punto.x + " " + punto.y )
			// var m = map.fromLatLngToDivPixel(this.getLatLng()); 
			 //map.panTo( this.getLatLng() );
			 //saca_flotante_mapa(this.webTvMarker.id , m )
				// return ;
			 saca_flotante(this.webTvMarker.id)
			return ;
			 var padre = this.webTvMarker ;  
			 var text = "<div style=\"white-space:no-wrap; width:310px;\" class=\"cartel_mapa\"><div class=\"titulo_cartel\">" + padre.nom +"</div><img src='upload/imagenes/" + padre.fic + "' "  + "alt='pic' height='180px'/><div style=\"padding:5px\" class=\"texto_cartel\">" + padre.tex + "</div><div style=\"text-align:left;font-size:9px\" class=\"direccion_cartel\">" + padre.dir + "<br/>" + padre.cod + "</div></div>";
			 var formu = "<div class='gmapsdirections'><form action='http://maps.google.com/maps' method='get' target='_blank'><div class='directionstitle'>" + diccionario.direccion_hasta + " " + padre.nom + "</div><label for='saddr'>" + diccionario.direccion_desde + "</label><input name='saddr' id='saddr' size='30' type='text'/><input value='Go' type='submit' /><input name='daddr' value='" + padre.lat + "," + padre.ln + "' type='hidden'/><input name='hl' value='" + diccionario.codigo + "' type='hidden'/><address>" + diccionario.ejemplo_direccion + "</address></form></div>" ; 
		 tabList = [
			new GInfoWindowTab( diccionario.titulo  , text ),
			new GInfoWindowTab(diccionario.como_llegar , formu )
			]
		 //var cartel = this.openInfoWindowHtml(text);
		 this.openInfoWindowTabsHtml( tabList , { maxContent:"hola"});
		
	}


	/////// clase Wicono //// 
	
	function Wicono( cat ) { 

		this.icon = new GIcon();
		this.icon.image = "imagenes/iconos/icono_"  + cat + ".png";
		//this.icon.image = "imagenes/iconos/icono_azul.png";
		this.icon.shadow = "imagenes/iconos/icono_sombra.png";
		this.icon.iconSize = new GSize(24, 24);
		this.icon.shadowSize = new GSize(32, 22 );
		this.icon.iconAnchor = new GPoint(5 , 24);
		this.icon.infoWindowAnchor = new GPoint( 11, 11 );
		this.icon.transparent = "imagenes/iconos/icono_comun.png";
		//icon.imageMap = [2 , 2, 2 , 21 , 9 , 21 , 16, 26, 22 , 21 , 30 , 21 , 30 , 2 ] ;
		return this.icon ; 
	}
	//// bug ie7 __flash__removeCallback
	function fixRaceCondition () {
	
	var backup = window.__flash__removeCallback;
	window.__flash__removeCallback = function (instance, name) { try {backup(instance, name)} catch (x){} };
	} 
	window.addEvent("beforeunload", fixRaceCondition );


	
	

		