﻿var RegionExplorer = function(options) {
	var defaults = {
		regionMapID: 'map',
		dropDownID: 'citiesDropDown',
		regions: {
			bhbl: [],
			gl: [],
			glap: [],
			se: []
		}
	};
	
	var _options = $.extend({}, defaults, options);
	var _citiesClone;
	var _map;
	
	function mapClick(val) {
		var city = _citiesClone.clone(true);
		var oldcity = $('#' + _options.dropDownID).replaceWith(city);
		var selectedCity = oldcity.val();
		
		if(val) {
			_map.setRegion(val.toUpperCase());
			var array = _options.regions[val];
			
			var options = $('option', city).get();
			for (var x = options.length - 1; x >= 0; x--) {
				var optval = $(options[x]).val();
				if (optval && ($.inArray(optval, array) < 0)) {
					options[x].parentNode.removeChild(options[x]);
				}
			}
		} else {
			_map.hideAll();
		}
	}
	
	_citiesClone = $('#' + _options.dropDownID).clone(true);
	
	_map = new MiniMap({
		id: _options.regionMapID,
		width: 165,
		height: 103,
		onClick: function(v) { mapClick(v); }
	});
};