
	if ( !qFlux )
		{ var qFlux = {}; }
	qFlux.map = {};
	qFlux.map.zoom = 1;
	qFlux.map.width = 570;
	qFlux.map.height = qFlux.map.width/3 * 2;
	
	//####################################################################################################
	
	qFlux.map.color = {};
	qFlux.map.color['neutral'] = '0px -42px';
	qFlux.map.color['start'] = '0px -30px';
	qFlux.map.color['end'] = '-24px -30px';
	qFlux.map.color['transfer'] = '-12px -30px';
	qFlux.map.color['objective'] = '-36px -30px';
	qFlux.map.color['focus'] = '-48px -30px';

	//####################################################################################################

	qFlux.wheelQueue.push([['id','map_image'],'qFlux.map.mouseWheel']);
	qFlux.wheelQueue.push([['className','point'],'qFlux.map.mouseWheel']);
	qFlux.wheelQueue.push([['className','area'],'qFlux.map.mouseWheel']);
	qFlux.mouseQueue.push([['id','map_image'],0,'qFlux.map.move','qFlux.map.mouseUp','map']);
	qFlux.mouseQueue.push([['id','map'],0,'qFlux.map.move','qFlux.map.mouseUp']);
	
	//####################################################################################################
	
	qFlux.map.select = function(map, name)
		{
			qFlux.map.map = map;
			qFlux.map.reset();
			document.getElementById('map_image').src = 'Map_' + name + '.jpg';
		}
	
	//####################################################################################################
	
	qFlux.map.reset = function()
		{
			var container = document.getElementById('map');
			container.style.left = '0px';
			container.style.top = '0px';
			container.style.width = qFlux.map.width + 'px';
			container.style.height = qFlux.map.height + 'px';
			qFlux.map.clear();
			document.body.focus();
			qFlux.map.zoom = 1;
		}
	
	//####################################################################################################
	
	qFlux.map.clear = function()
		{
			var container = document.getElementById('map');
			for ( var i in container.childNodes )
				{
					if ( container.childNodes[i].style )
						{ container.childNodes[i].style.display = 'none'; }
				}
			document.getElementById('map_image').style.display = 'block';
		}
	
	//####################################################################################################
	
	qFlux.map.mouseWheel = function(target, delta)
		{
			if ( qFlux.map.isLocked )
				{ return; }
			var map = document.getElementById('map');
			var width = qFlux.map.width * qFlux.map.zoom;
			var height = qFlux.map.height * qFlux.map.zoom;
			if ( delta < 0 )
				{
					if ( qFlux.map.zoom > 1 )
						{ qFlux.map.zoom -= 0.3; }
					else
						{ return; }
				}
			else
				{
					if ( qFlux.map.zoom < 4 )
						{ qFlux.map.zoom += 0.3; }
					else
						{ return; }
				}
			var left = qFlux.parseFloat(map.style.left);
			var top = qFlux.parseFloat(map.style.top);
			var focusX = (-left + qFlux.map.width/2) / width;
			var focusY = (-top + qFlux.map.height/2) / height;
			width = qFlux.map.width * qFlux.map.zoom;
			height = qFlux.map.height * qFlux.map.zoom;
			map.style.width = width + 'px';
			map.style.height = height + 'px';
			left = qFlux.map.width/2 - focusX * width;
			top = qFlux.map.height/2 - focusY * height;
			qFlux.map.move(0, left, top);
			map.style.cursor = 'default';
		}
	
	//####################################################################################################
	
	qFlux.map.move = function(event, left, top)
		{
			var map = document.getElementById('map');
			map.style.cursor = 'move';
			if ( left > 0 )
				{ map.style.left = '0px'; }
			else
				{
					var right = left + qFlux.map.width * qFlux.map.zoom;
					if ( right > qFlux.map.width )
						{ map.style.left = left + 'px'; }
					else
						{ map.style.left = -qFlux.map.width * qFlux.map.zoom + qFlux.map.width + 'px'; }
				}
			if ( top > 0 )
				{ map.style.top = '0px'; }
			else
				{
					var bottom = top + qFlux.map.height * qFlux.map.zoom;
					if ( bottom > qFlux.map.height )
						{ map.style.top = top + 'px'; }
					else
						{ map.style.top = -qFlux.map.height * qFlux.map.zoom + qFlux.map.height + 'px'; }
				}
		}
	
	//####################################################################################################
	
	qFlux.map.mouseUp = function()
		{ document.getElementById('map').style.cursor = 'default'; }
	
	//####################################################################################################
	
	qFlux.map.translate = function(data)
		{
			if ( !data[0] )
				{ return 0; }
			if ( !data[1] )
				{ return [[data[0][0], data[0][1] * 100, data[0][2] * 100]]; }
			var x = 100/60;
			var y = 100/40;
			var map = data[0][0];
			var grid = [];
			var minRow = 40, maxRow = 0;
			for ( var i in data )
				{
					if ( data[i][0] != map )
						{ continue; }
					var column = Math.floor(data[i][1] * 100 / x);
					var row = Math.floor(data[i][2] * 100 / y);
					if ( !grid[column] )
						{ grid[column] = []; }
					grid[column][row] = true;
					if ( row < minRow )
						{ minRow = row; }
					if ( row > maxRow )
						{ maxRow = row; }
				}
			for ( var i in grid )
				{
					for ( var n in grid[i] )
						{
							for ( var column = i - 2; column <= i + 2; column++ )
								{
									if ( !grid[column] )
										{ continue; }
									for ( var row = n - 2; row <= n + 2; row++ )
										{
											if ( !grid[column][row] )
												{ continue; }
											var newColumn = Math.round((column + 2 * i) / 3);
											if ( !grid[newColumn] )
												{ grid[newColumn] = []; }
											var newRow = Math.round((row + 2 * n) / 3);
											grid[newColumn][newRow] = true;
											if ( newRow < minRow )
												{ minRow = newRow; }
											if ( newRow > maxRow )
												{ maxRow = newRow; }
										}
								}
						}
				}
			for ( var column in grid )
				{
					for ( var row = minRow; row <= maxRow; row++ )
						{
							if ( grid[column][row] )
								{ continue; }
							var sides = 0;
							if ( grid[column - 1] && grid[column - 1][row] )
								{ sides++; }
							if ( grid[column + 1] && grid[column + 1][row] )
								{ sides++; }
							if ( grid[column][row - 1] )
								{ sides++; }
							if ( grid[column][row + 1] )
								{ sides++; }
							if ( sides > 2 )
								{ grid[column][row] = true; }
						}
				}
			var result = [];
			var minColumn = 60, maxColumn = 0;
			for ( var i in grid )
				{
					for ( var n in grid[i] )
						{ result.push([i * x, n * y]); }
					if ( i < minColumn )
						{ minColumn = i; }
					if ( i > maxColumn )
						{ maxColumn = i; }
				}
			result.splice(0, 0, [map, (Number(minColumn) + Number(maxColumn))/2 * x + x/2, (minRow + maxRow)/2 * y + y/2]);
			return result;
		}
	
	//####################################################################################################
	
	qFlux.map.point = function(index, x, y, style, type, id, over, out, down)
		{
			var point;
			if ( document.getElementById('point_' + index) )
				{
					point = document.getElementById('point_' + index);
					point.style.display ='block';
				}
			else
				{
					point = document.createElement('div');
					point.id = 'point_' + index;
					point.className = 'point';
					document.getElementById('map').appendChild(point);
				}
			point.onmouseover = over;
			point.onmouseout = out;
			point.onmousedown = down;
			point.style.left = x + '%';
			point.style.top = y + '%';
			point.style.backgroundPosition = qFlux.map.color[style];
			point.color = style;
			if ( style == 'neutral' )
				{ point.style.zIndex = 2; }
			else
				{ point.style.zIndex = 3; }
			point.linkType = type;
			point.linkID = id;
		}
	
	//####################################################################################################
	
	qFlux.map.area = function(index, data)
		{
			var container = document.getElementById('map');
			for ( var i = 1; i < data.length; i++ )
				{
					var area;
					if ( document.getElementById('area_' + index) )
						{
							area = document.getElementById('area_' + index);
							area.style.display ='block';
						}
					else
						{
							area = document.createElement('div');
							area.id = 'area_' + index;
							area.className = 'area';
							area.style.width = 100/60 + '%';
							area.style.height = 100/40 + '%';
							area.index = index;
							container.appendChild(area);
						}
					area.style.left = data[i][0] + '%';
					area.style.top = data[i][1] + '%';
					index++;
				}
			return index;
		}

