/*
	Copyright (C) 2008 - Juan Ferrer Toribio

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this program; if not, write to the Free
	Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
	02111-1307 USA.
*/

var LOCATION = [
	{
		 lat: 39.436596
		,lng: -0.351297
		,desc: [
			 'Verdnatura Levante S.L.'
		 	,'Mercavalencia, S/N'
			,'46013 Valencia'
			,'96 367 71 77'
		]
	},{
		 lat: 39.359785
		,lng: -0.421772
		,desc: [
			 'Ferrer Toribio Hermanos S.L.'
			,'Avda Espioca, 100'
			,'46460 Silla'
			,'96 324 21 00'
		]
	}
];

var VnLocation = new Class
({
	Extends: VnModule,

	activate: function (data)
	{
		var div;
		var map;
		var lat;
		var marker;
		var loc;
		var obj;
		var p, h, n;

		div = new HtkFrame ();
		this.setChild (div);
	
		map = new GMap2 (div.getNode ());
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
		
		loc = LOCATION;

		for (var m = 0; m < loc.length; m++)
		{
			div = document.createElement ('div');

			h = document.createElement ('h3');
			h.style.marginBottom = '8px';
			h.appendChild (document.createTextNode (loc[m].desc[0]));
			div.appendChild (h);
		
			for (n = 1; n < loc[m].desc.length; n++)
			{
				p = document.createElement ('p');
				p.style.padding = '0px';
				p.style.margin = '0px';
				p.appendChild (document.createTextNode (loc[m].desc[n]));
				div.appendChild (p);
			}

			lat = new GLatLng (loc[m].lat, loc[m].lng);

			marker = new GMarker (lat, {title: loc[m].desc[0]});
			map.addOverlay(marker);

			marker.userData = div;
			GEvent.addListener (marker, 'click', function() {
        		this.openInfoWindow (this.userData);
      		});
		}
		
		marker.openInfoWindowHtml (div);

		lat = new GLatLng (39.412935, -0.385609);
		map.setCenter (lat, 12);
	}
});


