var elMapa;

function init()
{
	if (GBrowserIsCompatible())
	{
		elMapa = new GMap2(document.getElementById("map"), 
		{
			logoPassive: true
		}
		);
		
		elMapa.setCenter(new GLatLng(6.281173, -75.654351), 10, G_HYBRID_MAP);
		elMapa.addControl(new GLargeMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,40)));
		elMapa.addControl(new GV_MapTypeControl());
		
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,0));
		pos.apply(document.getElementById("logoArea"));
		document.getElementById("map").appendChild(document.getElementById("logoArea"));
		
		var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,121));
		pos.apply(document.getElementById("contenido"));
		document.getElementById("map").appendChild(document.getElementById("contenido"));
		displayLayers();
	}
	else
	{
		alert("Lo sentimos pero no te soportamos");
	}	
}

function showLayer(elCheck, indice, arreglo)
{
	if(elCheck.checked)
	{
		if(arreglo[indice].isMunicipio)
		{
			Cookie.set(arreglo[indice].name, "true");
		}
		if(arreglo[indice].loaded)
			arreglo[indice].show();
		else
			arreglo[indice].loadKML();
	}
	else
	{
		if(arreglo[indice].isMunicipio)
		{
			Cookie.set(arreglo[indice].name, "false");
		}
		arreglo[indice].hide();
	}
}

function gotoLayer(indice, arreglo)
{
	arreglo[indice].geoxml.gotoDefaultViewport(elMapa);
}

var tabbyTabs;

window.addEvent('domready', function(){
  init();
  var ajaxLoad = new Ajax("sections/capas.php", {method: 'get', update: 'middle', onComplete: function(e)
			  {
				var myAccordion = new Accordion($$('.layerTitle'), $$('.layerContent'), {alwaysHide: true});
			  }
			  }).request();
  
  tabbyTabs = new Tabby.Remote('contenido',
			{
				urls: {
					'capas': 'sections/capas.php',
					'imagenes': 'sections/imagenes.php',
					'actividades': 'sections/actividades.php'
				}
			});
});

window.onunload = GUnload;
