var bugRiddenCrashPronePieceOfJunk = (navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1);
var W3CDOM = (!bugRiddenCrashPronePieceOfJunk && document.getElementsByTagName && document.createElement);
var onLoadObj = new Object;

function js_inicializar()
{if (W3CDOM){
	for (var i in onLoadObj) {
		if (onLoadObj [i]) {
			if (onLoadObj [i].search (/\(/) > 0) eval (onLoadObj [i]);
			else eval (onLoadObj [i] +'()');
		}
	}
}}

var googleMap = false;
var gmOverlays = Array ();

function js_googleMap () {
	if (typeof GBrowserIsCompatible != 'undefined' && GBrowserIsCompatible()) {
		googleMap = new GMap2 (document.getElementById ('map'));
		googleMap.addControl(new GSmallMapControl());
		googleMap.addControl(new GMapTypeControl());
		googleMap.setCenter (new GLatLng(36.0, -2.0), 16, G_NORMAL_MAP);
		googleMap.id = 'googleMap';
	}
}

function js_googleMapIni () {
	if (typeof GBrowserIsCompatible != 'undefined' && GBrowserIsCompatible()) {
		js_googleMapPos (gmCooLon, gmCooLat, gmCooTxt);
		googleMap.setCenter (new GLatLng (gmCooLat, gmCooLon), gmCooZoom);
	}
}

function js_googleMapPos (lon, lat, texto) {
	if (typeof GBrowserIsCompatible != 'undefined' && GBrowserIsCompatible()) {
		var posPoint = new GLatLng(lat, lon);
		googleMap.setCenter (posPoint);

		var baseIcon = new GIcon();
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);

		icon = new GIcon(baseIcon);
		icon.image = "img/popup_marca.png";
		icon.printImage = "img/popup_marca.gif";
		gmOverlays.push (new GMarker (posPoint, icon));
		googleMap.addOverlay (gmOverlays [gmOverlays.length-1]);
		if (texto) GEvent.addListener(gmOverlays [gmOverlays.length-1], "mouseover", function() { this.openInfoWindowHtml(texto); });
	}
}

function js_googleStreetIni () {
	if (typeof GBrowserIsCompatible != 'undefined' && GBrowserIsCompatible()) {
		document.getElementById ('map').innerHTML = '';
		var gmSV = new GLatLng (gmSVPov.lat, gmSVPov.lon);
		if (typeof gmSVPov.pov.heading != 'undefined' && typeof gmSVPov.pov.yaw == 'undefined') {
			gmSVPov.pov.yaw = gmSVPov.pov.heading;
			gmSVPov.pov.pitch *= -1;
			if (gmSVPov.pov.zoom>1) gmSVPov.pov.zoom -= 1;
		}
		pOps = { latlng: gmSV, pov:gmSVPov.pov };
		document.getElementById ('contenedor').acaPano = new GStreetviewPanorama (document.getElementById ('map'), pOps);
		GEvent.addListener (document.getElementById ('contenedor').acaPano, 'error', jsPanoNoFlash);
	}
}
function jsPanoNoFlash (errorCode) {
	if (errorCode == 603) {
		alert ('Error: necesitar tener Flash para ver la panorámica');
		return;
	}
	else if (errorCode == 600) {
		alert ('Error: no hay imágenes para esta localización!');
		window.location = window.location.href +'&_ec=600';
		return;
	}
}

onLoadObj ['focus'] = 'window.focus';
window.onload = js_inicializar;
