var map;
//var urlwms = "http://10.56.38.2:8080/eiel/wms?";
var urlwms = "http://www.dicoruna.es/webeiel_ideac/wms?";
var selectorAreaInteres = null;

function inicializaMapa(){

	resizeMap();
	var options = {
		maxExtent: new OpenLayers.Bounds(466835.71307825996, 4700503.494865076, 609718.9790609288, 4853674.3559984965),
		restrictedExtent: new OpenLayers.Bounds(466835.71307825996, 4700503.494865076, 609718.9790609288, 4853674.3559984965),
		resolutions: [420, 300, 189.99, 120.320667, 76.19907841, 48.25687636, 30.5610798, 19.35433184, 12.25709835, 7.762420386, 4.91594083, 3.113265328, 1.971630932, 1.01],
		units: 'm',
		projection: "EPSG:23029",
		controls: []
	};
	map = new OpenLayers.Map('mapaOL', options);
	map.fractionalZoom = true;

	var capaBase = new OpenLayers.Layer.WMS(
	"Capa base",
	urlwms,
	{layers: 'eiel:provincias', transparent:true},
	{'buffer':0, transitionEffect: 'resize','isBaseLayer': true, singleTile: true}
	);

	var municipios = new OpenLayers.Layer.WMS(
	"municipios",
	urlwms,
	{layers: 'eiel:municipios', transparent:true},
	{'buffer':0, transitionEffect: null,'isBaseLayer': false, singleTile: true}
	);


	var nucleos1 = new OpenLayers.Layer.WMS(
	"Nucleos 1",
	urlwms,
	{layers: 'eiel:nucleos_1er_textos', transparent:true},
	{'buffer':0, transitionEffect: null,'isBaseLayer': false, singleTile: true}
	);


	var nucleos2 = new OpenLayers.Layer.WMS(
	"Nucleos 2",
	urlwms,
	{layers: 'eiel:nucleos_2o_textos', transparent:true},
	{'buffer':0, transitionEffect: null,'isBaseLayer': false, singleTile: true}
	);


	var nucleos3 = new OpenLayers.Layer.WMS(
	"Nucleos 3",
	urlwms,
	{layers: 'eiel:nucleos_3er_textos', transparent:true},
	{'buffer':0, transitionEffect: null,'isBaseLayer': false, singleTile: true}
	);


	var nucleos4 = new OpenLayers.Layer.WMS(
	"Nucleos 4",
	urlwms,
	{layers: 'eiel:nucleos_4o_textos', transparent:true},
	{'buffer':0, transitionEffect: null,'isBaseLayer': false, singleTile: true}
	);


	var textosNucleos = new OpenLayers.Layer.WMS(
	"Textos Nucleos",
	urlwms,
	{layers: 'eiel:textos_nucleos', transparent:true},
	{'buffer':0, transitionEffect: null,'isBaseLayer': false, singleTile: true}
	);




	capaBase.setVisibility(true);
    municipios.setVisibility(true);
    nucleos1.setVisibility(true);
    nucleos2.setVisibility(true);
    nucleos3.setVisibility(true);
    nucleos4.setVisibility(true);
    textosNucleos.setVisibility(true);

	map.addLayer(capaBase);
	map.addLayer(municipios);
	map.addLayer(nucleos1);
	map.addLayer(nucleos2);
	map.addLayer(nucleos3);
	map.addLayer(nucleos4);
	map.addLayer(textosNucleos);


//  agregamos las herramientas

    var zoombox = new OpenLayers.Control.ZoomBox({
        title: "Zoom a zona."
    });

    var container = document.getElementById("mainButtonBarNomenclator");
  	var panel = new OpenLayers.Control.Panel({
		defaultControl: zoombox ,
		div: container
 	 });

 	selectorAreaInteres = new OpenLayers.Control.AreaDeInteres({title: 'Seleccionar area de interese'});

  	panel.addControls([new OpenLayers.Control.DragPan({title: 'Mover mapa'}),selectorAreaInteres,
  	                   new OpenLayers.Control.ZoomToMaxExtent({title: 'Ver todo o mapa'}),
  					   new OpenLayers.Control.ZoomOut({title: 'Zoom menos'}), zoombox
                       ]);

    map.addControl(panel);



	OpenLayers.Util.onImageLoadErrorColor = "transparent";
    OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

    //este no funciona
    //map.zoomTo(new OpenLayers.Bounds(466835.71307825996,4700503.494865076,609718.9790609288,4853674.3559984965));

}


function resizeMap(){

	var x, y;
	x= 500;
	y= 500;
	if (self.innerHeight) { // MOS
		y = self.innerHeight;
		x = self.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) { // IE6 Strict
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if (document.body.clientHeight) { // IE quirks
		y = document.body.clientHeight;
		x = document.body.clientWidth;
	}
	//intentamos ajustar el tamano del div que contiene el mapa
	document.getElementById('mapaOL').style.width = 600;
	document.getElementById('mapaOL').style.height = 500;
}



