GGSB.modules.maptools = function(ggsb) {
	
	var DEFAULT_ZOOM = 17;
	
	function MapTools(args) {
		var self = this;
		
		this._dataObj = {};
		
		this.map = null;
		this._mapData = {};
		
		this._mapImageData = [];
		this._mapImageLayer = null;
		this._mapImageIcon = null;
		this._mapImageMarker = null;
		
		$(window).bind('updateHoleId', function(e, args) {
			self.updateHole(args);
		});
	}
	
	var prot = {
		initMap : function(args) {
			
			this._dataObj = args.data;
			
			
			
			var self = this,
				i,
				l,
				image,
				marker;
			
			this._mapData = this._dataObj.getMapData();
			
			this.map = new ZdcMap(	document.getElementById('MapBlock'), 
								ZdcCommon.WGS2TKY((this._mapData.MAX_LON + this._mapData.MIN_LON) / 2, (this._mapData.MAX_LAT + this._mapData.MIN_LAT) / 2),
								DEFAULT_ZOOM
							);
			
			this.map.setMapZoomLimit(14, 17);
			this.map.setWheelOff();
			
			/*
			$('#HolenumSelected .holenum').click(function() {
				var holeId = $('#HolenumSelected .holenum').index(this)+1;
				
				self.showShotIndex(holeId);
				
			});
			*/
			
			
			this._mapImageData = this._dataObj.getMapImage();
			
			if (this._mapImageData) {
				this._mapImageLayer = new ZdcUserLayer();
				this.map.addUserLayer(this._mapImageLayer, 1999);
				
				this._mapImageIcon = new ZdcIcon();
				this._mapImageIcon.offset = new ZdcPixel(0, 0);
			}
			
			this.setMapImage(DEFAULT_ZOOM);
			
		},
		
		
		
		showWait : function() {
			if (!this.map) {
				return;
			}
			
			GGOLF.mapCoverLoadView.show();
			return;
			
			/*
			var dom = $('#MapSection');
			
			this.map.addZdcWait((dom.height() / 2) - 10, (dom.width() / 2) - 60, "読み込み中");
			this.map.visibleZdcWait();
			*/
		},
		
		
		
		hideWait : function() {
			GGOLF.mapCoverLoadView.hide();
			return;
			//this.map.removeZdcWait();
		},
		
		
		
		getMap : function() {
			return this.map;
		},
		
		
		
		setMapImage : function(scale) {
			if (!this._mapImageData) {
				return;
			}
			
			
			var i,
				l = this._mapImageData.length,
				mapbox = this.map.getMapBoundBox(),
				min = ZdcCommon.WGS2TKY(this._mapData.MIN_LON, this._mapData.MIN_LAT),
				max = ZdcCommon.WGS2TKY(this._mapData.MAX_LON, this._mapData.MAX_LAT),
				golfbox = new ZdcBox(min, max),
				bstate = golfbox.isContainBox(mapbox),
				self = this;
			
			this._mapImageLayer.clearMarker();
			
			
			for (i = 0; i < l; i++) {
				
				if (this._mapImageData[i].SCALE_NO == scale && bstate != 3) {
					
					this._mapImageIcon.image = '/Content/data/emap/'+this._mapImageData[i].IMG_FILE_NAME;
					//this._mapImageIcon.offset = new ZdcPixel(0, 0);
					//this._mapImageIcon.size = new ZdcSize(1557, 1840);
					this._mapImageMarker = new ZdcMarker(ZdcCommon.WGS2TKY(this._mapData.MIN_LON, this._mapData.MAX_LAT), this._mapImageIcon, 'static', true);
					this._mapImageMarker.dragOn();
					
					/*
					this._mapImageMarker.setIcon(this._mapImageIcon);
					this._mapImageMarker.setPoint(ZdcCommon.WGS2TKY(this._mapData['MIN_LON'], this._mapData['MAX_LAT']));
					this._mapImageMarker.opt = true;
					*/
					this._mapImageLayer.addMarker(this._mapImageMarker);
					
					
					ZdcEvent.addListener(this.map, 'dragmapend', function() {
						self.map.refreshMap();
					});
					
					break;
				} else {
					ZdcEvent.clearListeners(this.map, 'dragmapend');
				}
			}
		},
		
		updateHole:function(args) {
			var data = this._dataObj.getCourse(args);
			
			if (!data) {
				return;
			}
			
			$('#CourseInfo>strong').html(data.COURSE_NAME);
		}
		
	}
	MapTools.prototype = prot;
	
	ggsb.MapTools = $.extend(MapTools, {});
	
};

