/**
 * @author paweł smoleński <pawel@smolenski.pl>
 * @copyright Wydawnictwo Kartograficzne Daunpol Sp. z o.o.
 */
var Map = new Class
({
	__container: null,
	
	initialize: function() {},
	
	generate: function(container)
	{
		this.__container = container;
		
		new pl.smolenski.Interface().addFlash
		(
			this.__container,
			{
				'url': './img/map.swf?refresh=' + Math.random(),
				'id': 'map',
				'width': '100%',
				'height': '100%',
				'wmode': 'normal',
				'backgroundColor': '#fff',
				'vars': 'mapData=./data/map.xml'
			}
		);
	}
});


var MapSearchForm = new Class
({
	Extends: SearchForm
});


var MapSearchResults = new Class
({
	Extends: SearchResults,
	
	__perPage: 15,
	
	__fillResults: function(data)
	{
		this.parent(data);
		
		var resultItems = this.__container.getElements('div.resultItem');
		
		for (var i = 0; i < resultItems.length; i++)
		{
			var resultItem = resultItems[i];
			var index = resultItem.getElement('.index');
			
			if (index)
				index.set('text', (i + 1));
			
			resultItem.addEvent('click', this.__showPoi.bind(this, data.poi[i].id))
		}
		
		var mapObject = new pl.smolenski.Interface().getFlash('map');
		mapObject.loadInfoData
		(
			this.__criteria['poi'] ? this.__criteria['poi'] : '', 
			this.__criteria['type'], 
			this.__criteria['subtype'], 
			'', 
			'',
			this.__page, 
			this.__perPage
		);
	},

	__showPoi: function(poiId)
	{
		var mapObject = new pl.smolenski.Interface().getFlash('map');
		mapObject.showPoi(0, poiId);
	}
});
