//<![CDATA[
var bor;
var BorMap = function(){};

BorMap.prototype = {
	map: null,
	bubbleActive: null,
	markers: Array(),
	bubbles: Array(),
	lsteners: Array(),
	videk : new google.maps.LatLng(47.2, 19.5),
	bp: new google.maps.LatLng(47.50, 19.05),
	config: null,
	controlDiv: null,

	initialize: function(config) {
		this.config = config;
		var myOptions = {
			mapTypeControl: false,
			scrollwheel: false,
			zoom: 7,
			center: this.videk,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		 this.map = new google.maps.Map(document.getElementById("gmap"), myOptions);

		if (typeof(config) != undefined )
		{
			this.setConfig(config);
		}

		for (var i in this.markers )
		{
			google.maps.event.addListener(bor.markers[i], 'click', function() {
			bor.setMap(this.index);
			});
		}
		this.setupControls();
	},

	setupControls: function() {
		this.controlDiv = document.createElement('DIV');
		this.controlDiv.index = 1;
		// Set CSS styles for the DIV containing the control
		// Setting padding to 5 px will offset the control
		// from the edge of the map
		this.controlDiv.style.padding = '5px';

		// Set CSS for the control border
		var controlUI = document.createElement('DIV');
		controlUI.style.backgroundColor = 'white';
		controlUI.style.borderStyle = 'solid';
		controlUI.style.borderWidth = '1px';
		controlUI.style.cursor = 'pointer';
		controlUI.style.textAlign = 'center';
		controlUI.title = borStr.countyTitle;
		this.controlDiv.appendChild(controlUI);

		// Set CSS for the control interior
		var controlText = document.createElement('DIV');
		controlText.style.fontFamily = 'Verdana';
		controlText.style.fontSize = '12px';
		controlText.style.padding = '4px';
		controlText.style.width = '120px';
		controlText.innerHTML = borStr.countyButtonLabel;
		controlUI.appendChild(controlText);

		// Setup the click event listeners: simply set the map to
		// Chicago
		google.maps.event.addDomListener(controlUI, 'click', function() {
			bor.setVidek();
		});
		this.map.controls[google.maps.ControlPosition.RIGHT].push(this.controlDiv);
		
		this.controlDiv = document.createElement('DIV');
		this.controlDiv.index = 1;
		// Set CSS styles for the DIV containing the control
		// Setting padding to 5 px will offset the control
		// from the edge of the map
		this.controlDiv.style.padding = '5px';

		// Set CSS for the control border
		var controlUI = document.createElement('DIV');
		controlUI.style.backgroundColor = 'white';
		controlUI.style.borderStyle = 'solid';
		controlUI.style.borderWidth = '1px';
		controlUI.style.cursor = 'pointer';
		controlUI.style.textAlign = 'center';
		controlUI.title = borStr.capitalTitle;
		this.controlDiv.appendChild(controlUI);

		// Set CSS for the control interior
		var controlText = document.createElement('DIV');
		controlText.style.fontFamily = 'Verdana';
		controlText.style.fontSize = '12px';
		controlText.style.padding = '4px';
		controlText.style.width = '120px';
		controlText.innerHTML = borStr.capitalButtonLabel;
		controlUI.appendChild(controlText);

		// Setup the click event listeners: simply set the map to
		// Chicago
		google.maps.event.addDomListener(controlUI, 'click', function() {
			bor.setBP();
		});
		this.map.controls[google.maps.ControlPosition.RIGHT].push(this.controlDiv);

	},
	setVidek: function() {
		this.map.setCenter(this.videk);
		this.map.setZoom(7);
		if (this.bubbleActive != null)
		{
			this.bubbles[this.bubbleActive].close();
		}
	},
	setBP: function() {
		this.map.setCenter(this.bp);
		this.map.setZoom(12);
		if (this.bubbleActive != null)
		{
			this.bubbles[this.bubbleActive].close();
		}
	},


	setConfig: function(config) {
		for (var i in config)
		{
			var obj = config[i];
			var point = new google.maps.LatLng(obj.lat,obj.lng);
			var marker = new google.maps.Marker({ 
								position: point, 
								title: obj.title,
								map: this.map
								});
			var infowindow = new google.maps.InfoWindow({
								content: obj.content
								});
			this.bubbles.push(infowindow);
			marker.index = i;
			this.markers.push(marker);
		}
	},
	
	setMap: function(index) {
		if (this.bubbleActive != null && this.bubbleActive != index)
		{
			this.bubbles[this.bubbleActive].close();
		}
		var m = this.markers[index];
		var b = this.bubbles[index];
//		console.info(this.bubbleActive+' , '+index);
		this.map.setZoom(16);
		this.map.setCenter(m.position);
		b.open(this.map, m);
		this.bubbleActive = index;
	}
};

function createBor() {
	bor = new BorMap;
	bor.initialize(borConfig);
}

addOnLoadListener(createBor);
//]]>
