var map = null;
var geocoder0 = null

var icons = Array();
icons[1]=cHTMLROOT + 'maps/minilogo4.png';
icons[2]=cHTMLROOT + 'maps/minilogo1.png';
icons[3]=cHTMLROOT + 'maps/minilogo2.png';
icons[4]=cHTMLROOT + 'maps/minilogo3.png';

var description=Array();
description[1]='';
description[2]='';
description[3]='';
description[4]='';

var addresses=Array()
// addresses[1]='Marques de Sentmenat 35 Barcelona Spain';
addresses[2] = new GLatLng( 41.38531 - 0.0004, 2.134813 );
// addresses[2] = 'Numancia 117 Barcelona Spain';
addresses[3] = new GLatLng( 41.386284 -0.0007, 2.134985 );
// addresses[3]='Taquigraf Garriga 48 Barcelona Spain';
addresses[4] = new GLatLng( 41.385519 -0.0005,2.131916+0.00005 );
// addresses[1]='Marques de Sentmenat 75 Barcelona Spain';
// addresses[4] = new GLatLng( 41.375005 -0.008341, 2.132528+0.016565 );
addresses[1] = new GLatLng( 41.385326 -0.0003, 2.137914 );

//http://maps.google.com/maps?f=d&hl=es&saddr=&daddr=Carrer+del+Marqu%C3%A9s+de+Sentmenat,+35,+08029,+Barcelona,+Barcelona,+Catalu%C3%B1a,+Espa%C3%B1a&sll=41.385825,2.137141&sspn=0.006955,0.019333&ie=UTF8&om=1&ll=41.385213,2.135532&spn=0.003477,0.009667&z=17&iwloc=cent
function load() {
	if (GBrowserIsCompatible()) {

		map = new GMap2(document.getElementById('mapa')	);
		map.addControl(	new GLargeMapControl(),
				new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 10))
				);
		map.addControl(new GMapTypeControl());

		geocoder0 = new GClientGeocoder()
// 		showAddress(0, 'Numancia 117 Barcelona', 1);
		showMyAddress( 0, addresses[1], 1 );
	}
}

function showMyAddress( pCnt, point, hideMarker ) {
	if (!point) {
		alert(address + " not found");
		showNextAddress( pCnt + 1 );
		return;
	}

	if (hideMarker!=1)
	{
		var icon = new GIcon();
		icon.image = icons[ pCnt ];
		icon.iconSize = new GSize(50, 50);
		icon.iconAnchor = new GPoint(25, 45);
		icon.infoWindowAnchor = new GPoint(5, 1);

		var marker = new GMarker(point, icon);
		map.addOverlay(marker);
		/*
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml( description[ pCnt ] );
		});*/
	}
	else
	{
		map.setCenter(addresses[2], 16);
	}
	showNextAddress( pCnt + 1 );
}
/*
function showAddress(pCnt, address, hideMarker){
	//var geo = eval('geocoder'+pCnt);
	var geo = eval('geocoder0');
	geo.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert(address + " not found");
				showNextAddress( pCnt + 1 );
				return;
			}

			if (hideMarker!=1)
			{
				var icon = new GIcon();
				icon.image = icons[ pCnt ];
				icon.iconSize = new GSize(50, 50);
				icon.iconAnchor = new GPoint(25, 45);
				icon.infoWindowAnchor = new GPoint(5, 1);

				var marker = new GMarker(point, icon);
				map.addOverlay(marker);

// 				GEvent.addListener(marker, "click", function() {
// 					marker.openInfoWindowHtml( description[ pCnt ] );
// 				});
			}
			else
			{
				map.setCenter(point, 16);
			}
			showNextAddress( pCnt + 1 );
		}
	);
}

*/
function showNextAddress( pNewCnt )
{
	if (pNewCnt<=4)
	{
// 		alert(pNewCnt);
// 		showAddress( pNewCnt, addresses[ pNewCnt ] );
		showMyAddress( pNewCnt, addresses[ pNewCnt ] );
	}
}
