﻿/*
Tsunglin
For  觀光局
*/

function SparseArray(){
	this.sparseArray  = new Object();
	this.add = function(k, o){this.sparseArray[k] = o;};
	this.remove = function(k){delete this.sparseArray[k];};
	this.get = function(k){return k==null ? null : this.sparseArray[k];};
	this.first = function(){return this.get(this.nextKey());};
	this.next = function(k){return this.get(this.nextKey(k));};
	this.nextKey = function(k){
		for(i in this.sparseArray){
			if(!k) 
				return i;
			if(k==i) 
				k=null; /* tricky */
		}
		
		return null;
	}
};

var mutex = function(cmdObject, methodName){
	this.command = cmdObject;
	this.methodID = methodName;
	this.id = ++mutex.NextID;
		
	mutex.Wait.add(this.id, this);
	this.enter = true;
	this.number = (new Date()).getTime();
	this.enter = false;
	
	this.attempt(mutex.Wait.first());
};
mutex.Wait = new SparseArray();
mutex.NextID = 0;
mutex.Retry = function(cmdID, startID){
	mutex.Wait.get(cmdID).attempt(mutex.Wait.get(startID));
}
mutex.prototype.attempt = function(start){
	for(var j=start; j; j=mutex.Wait.next(j.id)){
		if (j.enter || (j.number && (j.number < this.number || (j.number == this.number && j.id < this.id)))){
			var cmdID = this.id;
			return setTimeout(function(){mutex.Retry(cmdID, j.id);}, 10);
		}
	}
		
	this.command[this.methodID]();
		
	this.number = 0;
	mutex.Wait.remove(this.id);
}

var ajaxRequest = function(method, url, data, callback){
	this.attempt = function(start){
		for(var j=start; j; j=ajaxRequest.Wait.next(j.id)){
			if (j.enter || (j.number && (j.number < this.number || (j.number == this.number && j.id < this.id)))){
				var cmdID = this.id; 
				return setTimeout(function(){ajaxReuest.Retry(cmdID, j.id);} , 10);
			}
		}
		
		var pos = ajaxRequest.getInstance();
		if(pos < 0)
			alert('Fail to get XMLHttpRequest object.');
		else{
			var obj = ajaxRequest.objectPool[pos];
			try{
				obj.open(this.method, this.url, true);
				if(this.method == 'POST')
					obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						
				if(document.all)
					obj.setRequestHeader('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT');

				var success, failure;
				if(this.callback){
					success = this.callback.success;
					failure = this.callback.failure;
				}
				callbackData = this.callbackData;
			
				obj.send(this.data);
				obj.onreadystatechange = function() {
					try {
						if(obj.readyState == 4 && (obj.status == 200 || obj.status == 304))
							success(obj.responseText, obj.responseXML, callbackData);
						else if(obj.readyState == 4)
							failure(callbackData);
					}
					catch(e) {alert(e);}
				}
			}catch(e){alert(e);}
		}
	
		this.number = 0;
		ajaxRequest.Wait.remove(this.id);
	};
	
	this.id = ++ajaxRequest.NextID;
	this.method = method;
	this.url = url;
	this.data = data;
	this.callback = callback;
	
	ajaxRequest.Wait.add(this.id, this);
	this.enter = true;
	this.number = (new Date()).getTime();
	this.enter = false;
	this.attempt(ajaxRequest.Wait.first());
};
ajaxRequest.NextID = 0;
ajaxRequest.Wait = new SparseArray();
ajaxRequest.Retry = function(cmdID, startID){
	ajaxRequest.Wait.get(cmdID).attempt(ajaxRequest.Wait.get(startID));
}
ajaxRequest.objectPool = new Array();
ajaxRequest.createObject = function(){
	var status = 0;
	
	if(window.XMLHttpRequest){ // Mozilla, Safari,...
		var objXMLHttpRequest = new XMLHttpRequest();
		status = 1;
	}
	else{ // IE
		var MSXML = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
		for(var n = 0; n < MSXML.length; n++){
			try{
				var objXMLHttpRequest = new ActiveXObject(MSXML[n]); 
				status = 1;
				break;
			}
			catch(e){}
		}
	}
	
	if(status == 1)
		return objXMLHttpRequest;	
};
ajaxRequest.getInstance = function(){
	for(var i = 0; i < ajaxRequest.objectPool.length; i++) {
		if(ajaxRequest.objectPool[i].readyState == 0 || ajaxRequest.objectPool[i].readyState == 4){
			ajaxRequest.objectPool[i].abort(); // Seem to IE bug.
			return i;
		}
	}	
		
	var obj = ajaxRequest.createObject();
	if(obj == null)
		return -1;
				
	ajaxRequest.objectPool[ajaxRequest.objectPool.length] = obj;
			
	return ajaxRequest.objectPool.length - 1;
};

function BlockInfo(){
	this.x = 0;
	this.y = 0;
	this.itemCount = 0;
	this.topicCount = 0;
	this.item = null;
	this.marker = null;
	this.clickHandler = null;
};

function BlogMap(options){	
	var LATLNG_PRECISION = 6;
	var SOUTH_WEST_LNG = 0;
	var SOUTH_WEST_LAT = 0;
	var NORTH_EAST_LNG = 0;
	var NORTH_EAST_LAT = 0;
	var LEVEL_1_WIDTH_PIXEL = 450;
	var LEVEL_1_HEIGHT_PIXEL = 550;
	var SCALE_LEVEL_COUNT = 10;
	var SCALE_RATIO = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512];
	var LEVEL_1_LNG_PER_PIXEL = 0;
	var LEVEL_1_LAT_PER_PIXEL = 0;
	var SEARCH_RESULT_ZOOM_LEVEL = 8;
	var BLOCK_WIDTH_PIXEL = 50;	
	var BLOCK_HEIGHT_PIXEL = 50;
	var MAP_CENTER_LNG = 120.850529;
	var MAP_CENTER_LAT = 23.634012;
	var MAP_MOVE_DISTANCE_THRESHOLD = 0.2;
	var INIT_ZOOM = 0;
	var ICON_URL = "/image/dot.gif";	
	var GET_ITEM_INFO_INTERFACE = "/interface/getPictureInfo2.php";
	var IMG_TAG = "map";
	var FOLOG_LINK_PREFIX = "/tour/servlet/ListTopicServlet?folog_id=";
	
	if(options.GET_ITEM_INFO_INTERFACE)
		GET_ITEM_INFO_INTERFACE = options.GET_ITEM_INFO_INTERFACE;
	if(options.FOLOG_LINK_PREFIX)
		FOLOG_LINK_PREFIX = options.FOLOG_LINK_PREFIX;
	if(options.IMGTAG)
		IMG_TAG = options.IMGTAG;
	if(options.INITLAT && options.INITLNG){
		 MAP_CENTER_LNG = options.INITLNG;
		 MAP_CENTER_LAT = options.INITLAT;
	}
	if(options.ICON_URL)
		ICON_URL = options.ICON_URL;
	
	if(options.INITZOOM && options.INITZOOM >= 0 && options.INITZOOM < SCALE_LEVEL_COUNT)
		INIT_ZOOM = options.INITZOOM;
	options = null;
	
	var mapDiv = null;
	var oData = null;
	var data = null;
	var dragFlag = false;

	var dragstartHandler = null;
	var dragHandler = null;
	var dragendHandler = null;
	var zoomendHandler = null;
	
	var isLoaded = false;
	var map = null;
	var zoomLevel = 0; 
	var screenSWX = -1, screenSWY = -1, screenNEX = -1, screenNEY = -1;
	var blockInfoArray = null;
	var doGroupingItem = false;
	var icon = null;
	var markerOpen = "";
	
	var toInteger = function(value){
		return Math.floor(value * Math.pow(10, LATLNG_PRECISION));
	};
	
	var toFloat = function(value){
		return value * Math.pow(0.1, LATLNG_PRECISION);
	};

	var getBlockX = function(lng){	
		return Math.floor((lng - SOUTH_WEST_LNG) / (LEVEL_1_LNG_PER_PIXEL / SCALE_RATIO[zoomLevel]) / BLOCK_WIDTH_PIXEL) + 1; 
	};
	
	var getBlockY = function(lat){	
		return Math.floor((lat - SOUTH_WEST_LAT) / (LEVEL_1_LAT_PER_PIXEL / SCALE_RATIO[zoomLevel]) / BLOCK_HEIGHT_PIXEL) + 1; 
	};
	
	var getBlockLng = function(x){
		var result = (((x - 1) * BLOCK_WIDTH_PIXEL * (LEVEL_1_LAT_PER_PIXEL / SCALE_RATIO[zoomLevel])) + (x * BLOCK_WIDTH_PIXEL * (LEVEL_1_LAT_PER_PIXEL / SCALE_RATIO[zoomLevel]))) / 2;
		result = result + SOUTH_WEST_LNG;
		
		return result; 
	};
	
	var getBlockLat = function(y){
		var result = (((y - 1) * BLOCK_HEIGHT_PIXEL * (LEVEL_1_LAT_PER_PIXEL / SCALE_RATIO[zoomLevel])) + (y * BLOCK_HEIGHT_PIXEL * (LEVEL_1_LAT_PER_PIXEL / SCALE_RATIO[zoomLevel]))) / 2;
		result = result + SOUTH_WEST_LAT;
		
		return result; 
	};
	
	var setScreen = function(){
		var bounds = map.getBounds();
		var swLoc = bounds.getSouthWest();
		var neLoc = bounds.getNorthEast();
		var nScreenSWX = toInteger(swLoc.lng());
		var nScreenNEX = toInteger(neLoc.lng());
		var nScreenSWY = toInteger(swLoc.lat());
		var nScreenNEY = toInteger(neLoc.lat());
		
		doGroupingItem = true;
			
		screenSWX = nScreenSWX;
		screenNEX = nScreenNEX;
		screenSWY = nScreenSWY;
		screenNEY = nScreenNEY
		
		if(screenSWX > NORTH_EAST_LNG || screenSWY > NORTH_EAST_LAT )
			doGroupingItem = false;
		else if(screenNEX < SOUTH_WEST_LNG || screenNEY < SOUTH_WEST_LAT )
			doGroupingItem = false;
		
		if(doGroupingItem){
			if(screenSWX < SOUTH_WEST_LNG) screenSWX = SOUTH_WEST_LNG;
			if(screenSWY < SOUTH_WEST_LAT) screenSWY = SOUTH_WEST_LAT;
			if(screenNEX > NORTH_EAST_LNG) screenNEX = NORTH_EAST_LNG;
			if(screenNEY > NORTH_EAST_LAT) screenNEY = NORTH_EAST_LAT;
		}
		
		return;
	};
	
	var clickMarkHandler = function(blockIndex){
		this.blockIndex = blockIndex;
	};
	clickMarkHandler.prototype.action = function(){
		if(!blockInfoArray[this.blockIndex]) return;
		
		var content = "<div class='map_picture_window'>";
		content += "		<div class='map_picture_window_title'>";
		content += "			<span>";
		content += "				部落格資訊";
		content += "				<input type='hidden' id='" + this.blockIndex + "_pos" + "' value='0'>";
		content += "			</span>";
		content += "		</div>";
		content += "		<div class='map_picture_window_content'>";
		content += "			<span class='map_picture_window_content_image'>";
		content += "				<a target='_blank' id='" + this.blockIndex + "_a" + "' href='" + FOLOG_LINK_PREFIX + blockInfoArray[this.blockIndex].item[0]["id"] +"'>";
		content += "					<img border='0' id='" + this.blockIndex + "' src='" + blockInfoArray[this.blockIndex].item[0]['thumbnail'] + "' width='" + blockInfoArray[this.blockIndex].item[0]['width'] + "' height='" + blockInfoArray[this.blockIndex].item[0]['height'] + "'>";
		content += "				</a>";
		content += "			</span><br>";
		content += "			<span>";
		content += "				<span id='" + this.blockIndex + "_title" + "'>" + blockInfoArray[this.blockIndex].item[0]['topicTitle'] + "</span>";
		content += "					<br>from ";
		//content += "				<a href='#'>";
		content += "					<span id='" + this.blockIndex + "_account" + "'>" + blockInfoArray[this.blockIndex].item[0]['topicPoster'] + "</span>";
		//content += "				</a>";
		content += "			</span>";
		content += "		</div>";
		content += "		<div class='map_picture_window_bottom'>";
		content += "			<span class='map_picture_window_bottom_pos'>";
		content += "				<span  id='" + this.blockIndex + "_show_pos" + "'>1</span> ";
		content += "				/ ";
		content += "				<span id='" + this.blockIndex + "_pic_count'>" + blockInfoArray[this.blockIndex].itemCount + "</span>";
		content += "			</span>";
		content += "			<div class='map_picture_window_bottom_select'>";
		content += "				<a href=\"javascript:document.getElementById('" + IMG_TAG + "').blogmap.changePicture('" + this.blockIndex + "', 2); \">Prev</a>";
		content += "			 	&nbsp;| &nbsp;";
		content += "				<a href=\"javascript:document.getElementById('" + IMG_TAG + "').blogmap.changePicture('" + this.blockIndex + "', 1); \">Next</a>";
		content += "			</div>";
		content += "		</div>";
		content += "</div>";
		
		var infoWindowSize = new CSize(180);
		blockInfoArray[this.blockIndex].marker.openInfoWindow(content, infoWindowSize);
		markerOpen = this.blockIndex;
	}
	var clickMarkEvent = function(){
		new mutex(new clickMarkHandler(this.blockIndex), "action");
	};
	
	var getMarkText = function(num){
		var text = "<table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'>";
		text +=	"		<tr>";
		text +=	"			<td align='center' valign='middle'>";
		text +=	"				<span style='font-family: Times New Roman, Tahoma, Verdana; font-size:12pt; color:#FFFFFF; overflow:hidden;'><strong>";
		text += num;
		text += "				</strong></span>";
		text += "			</td>";
		text += "		</tr>";
		text += "	</table>";
		
		return text;
	};
	
	var setBlockInfo = function(){
		if(map.getInfoWindow().isHidden()){
			markerOpen = "";
		}

		var tmpBlockInfoArray = new Array();

		for(var i in data.P){
			if(data.P[i].C < screenSWX || data.P[i].C > screenNEX)
				continue;
			if(data.P[i].B < screenSWY || data.P[i].B > screenNEY)
				continue;

			var index = getBlockX(data.P[i].C) + '_' + getBlockY(data.P[i].B);
			if(markerOpen == index)
				continue;
			
			if(!tmpBlockInfoArray[index]){
				tmpBlockInfoArray[index] = new BlockInfo();
				tmpBlockInfoArray[index].item = new Array();
			}
			
			tmpBlockInfoArray[index].itemCount ++; 
			if(tmpBlockInfoArray[index].x == 0) tmpBlockInfoArray[index].x = parseInt(data.P[i].C, 10);
			else tmpBlockInfoArray[index].x = (tmpBlockInfoArray[index].x + parseInt(data.P[i].C, 10)) / 2;
			if(tmpBlockInfoArray[index].y == 0) tmpBlockInfoArray[index].y = parseInt(data.P[i].B, 10);
			else tmpBlockInfoArray[index].y = (tmpBlockInfoArray[index].y + parseInt(data.P[i].B, 10)) / 2;
		
			var item = new Array();
			
			item["id"] = data.P[i].A;
			item["topicCount"] = data.P[i].D;
			item["topicPoster"] = data.P[i].E;
			item["topicTitle"] = data.P[i].F;
			item["thumbnail"] = data.P[i].G;
			item["height"] = "100";
			item["width"] = "100";
			
			tmpBlockInfoArray[index].topicCount += parseInt(item["topicCount"], 10) ;

			tmpBlockInfoArray[index].item.push(item);
			delete data.P[i];
		}

		for(var key in tmpBlockInfoArray){
			if(!blockInfoArray[key]){
				blockInfoArray[key] = tmpBlockInfoArray[key];
				var location = new CLatLng(toFloat(blockInfoArray[key].y), toFloat(blockInfoArray[key].x));
				blockInfoArray[key].marker = new CMarker(location, {icon: icon, clickable: true, draggable: false});
				map.addOverlay(blockInfoArray[key].marker);
				blockInfoArray[key].marker.setText(getMarkText(blockInfoArray[key].topicCount));
				blockInfoArray[key].marker.blockIndex = key;
				blockInfoArray[key].clickHandler = CEvent.addListener(blockInfoArray[key].marker, "click", clickMarkEvent);
				preloadImages(blockInfoArray[key].item[0]['thumbnail']);
			}
			else{
				if(blockInfoArray[key].marker)
					map.removeOverlay(blockInfoArray[key].marker); blockInfoArray[key].marker = null;
				if(blockInfoArray[key].clickHandler)
					CEvent.removeListener(blockInfoArray[key].clickHandler); blockInfoArray[key].clickHandler = null;
					
				for(var k in tmpBlockInfoArray[key].item)
					blockInfoArray[key].item.push(tmpBlockInfoArray[key].item[k]);
				blockInfoArray[key].itemCount += tmpBlockInfoArray[key].itemCount;
				blockInfoArray[key].topicCount += tmpBlockInfoArray[key].topicCount;
				
				blockInfoArray[key].y = (blockInfoArray[key].y + tmpBlockInfoArray[key].y) / 2;
				blockInfoArray[key].x = (blockInfoArray[key].x + tmpBlockInfoArray[key].x) / 2;	
				var location = new CLatLng(toFloat(blockInfoArray[key].y), toFloat(blockInfoArray[key].x));
				blockInfoArray[key].marker = new CMarker(location, {icon: icon, clickable: true, draggable: false});
				map.addOverlay(blockInfoArray[key].marker);
				blockInfoArray[key].marker.setText(getMarkText(blockInfoArray[key].topicCount));
				blockInfoArray[key].marker.blockIndex = key;
				blockInfoArray[key].clickHandler = CEvent.addListener(blockInfoArray[key].marker, "click", clickMarkEvent);
			}
			tmpBlockInfoArray[key] = null;
		}
		tmpBlockInfoArray = null;
		
		return;
	}
	
	var groupItem = function(){
		setBlockInfo();
		return;
	};

	var clearMapMarker = function(){
		if(!blockInfoArray) return;
		
		markerOpen = "";
		
		for(var key in blockInfoArray){
			if(blockInfoArray[key] != null){
				if(blockInfoArray[key].marker)
					map.removeOverlay(blockInfoArray[key].marker); blockInfoArray[key].marker = null;
				if(blockInfoArray[key].clickHandler)
					CEvent.removeListener(blockInfoArray[key].clickHandler); blockInfoArray[key].clickHandler = null;
				delete blockInfoArray[key];
			}
		}
		
		return;
	};
	
	var mapDragStart = function(){
		dragFlag = false;	
	}
	var mapDrag = function(){
		dragFlag = true;
	}
	var dragendMapHandler = function(){
		;
	};
	dragendMapHandler.prototype.action = function(){
		var center = map.getCenter();
		var lng = center.lng(); 
		var lat = center.lat();
		
		var distance = Math.abs((lng - MAP_CENTER_LNG)*(lat - MAP_CENTER_LAT));
		
		if(distance >= (MAP_MOVE_DISTANCE_THRESHOLD / Math.pow(SCALE_RATIO[zoomLevel], 2))){	
			MAP_CENTER_LNG = lng; 
			MAP_CENTER_LAT = lat;
			setScreen();
			groupItem();
		}
	};
	var dragendMapEvent = function(){
		if(dragFlag == true)
			new mutex(new dragendMapHandler(), "action");
	};
	
	var zoomendMapHandler = function(oldScale, newScale){
		this.oldScale = oldScale;
		this.newScale = newScale;
	};
	zoomendMapHandler.prototype.action = function(){
		delete data;
		data = clone(oData);
		
		zoomLevel = this.newScale;
		
		var center = map.getCenter();
		MAP_CENTER_LNG = center.lng(); 
		MAP_CENTER_LAT = center.lat();
		
		markerOpen = "";
		clearMapMarker();
		setScreen();
		groupItem();
	}
	var zoomendMapEvent = function(oldScale, newScale){
		if(oldScale != newScale)
			new mutex(new zoomendMapHandler(oldScale, newScale), "action");
	};
	
	var procOnload = function(responseText, responseXML){
		this.responseText = responseText;
		this.responseXML = responseXML;
	};
	procOnload.prototype.action = function(){
		var result = eval('(' + this.responseText + ')');
		if(!result || result.S != 0){
			//alert("Error in procOnload()! ");
			return;
		}
		oData = result;
		data = clone(oData);

		map.addControl(CControl.C_LARGE_ZOOM);
		zoomendHandler = CEvent.addListener(map, "zoomend", zoomendMapEvent);
		dragstartHandler = CEvent.addListener(map, "dragstart", mapDragStart);
		dragHandler = CEvent.addListener(map, "drag", mapDrag);
		dragendHandler = CEvent.addListener(map, "dragend", dragendMapEvent);

		blockInfoArray = new Array();
		setScreen();
		groupItem();

		isLoaded = true;
	}
	
	var procChangePicture = function(index, type){
		this.index = index;
		this.type = type;
	};
	procChangePicture.prototype.action = function(){
		if(!isLoaded) return;
		
		if(map.getInfoWindow().isHidden())
			markerOpen = "";
		
		if(markerOpen != this.index) return;
		
		var imageNode = document.getElementById(this.index);
		var posNode = document.getElementById(this.index + "_pos");
		var aNode = document.getElementById(this.index + "_a");
		var titleNode = document.getElementById(this.index + "_title");
		var showPosNode = document.getElementById(this.index + "_show_pos");
		var accountNode = document.getElementById(this.index + "_account");
		
		if(this.type == 1){
			if(posNode.value < blockInfoArray[this.index].itemCount - 1){
				posNode.value++;
				if((posNode.value + 1) < blockInfoArray[this.index].itemCount)
					preloadImages(blockInfoArray[this.index].item[posNode.value + 1]['thumbnail'])
				aNode.href = FOLOG_LINK_PREFIX + blockInfoArray[this.index].item[posNode.value]["id"];
				imageNode.width = blockInfoArray[this.index].item[posNode.value]['width'];
				imageNode.height = blockInfoArray[this.index].item[posNode.value]['height'];
				imageNode.src = blockInfoArray[this.index].item[posNode.value]['thumbnail'];
				titleNode.innerHTML = blockInfoArray[this.index].item[posNode.value]['topicTitle'];
				accountNode.innerHTML = blockInfoArray[this.index].item[posNode.value]['topicPoster'];
				showPosNode.innerHTML = parseInt(posNode.value) + 1;
			}
		}
		else if(this.type == 2){
			if(posNode.value > 0){
				posNode.value--;
				aNode.href = FOLOG_LINK_PREFIX + blockInfoArray[this.index].item[posNode.value]["id"];
				imageNode.width = blockInfoArray[this.index].item[posNode.value]['width'];
				imageNode.height = blockInfoArray[this.index].item[posNode.value]['height'];
				imageNode.src = blockInfoArray[this.index].item[posNode.value]['thumbnail'];
				titleNode.innerHTML = blockInfoArray[this.index].item[posNode.value]['topicTitle'];
				accountNode.innerHTML = blockInfoArray[this.index].item[posNode.value]['topicPoster'];
				showPosNode.innerHTML = parseInt(posNode.value) + 1;
			}
		}
	};
	
	this.changePicture = function(index, type){
		new mutex(new procChangePicture(index, type), 'action');
	};
	
	this.onload = function(){
		SOUTH_WEST_LNG = toInteger(119.22111271081461);
		SOUTH_WEST_LAT = toInteger(21.761859626368323);
		NORTH_EAST_LNG = toInteger(122.52668001952914);
		NORTH_EAST_LAT = toInteger(25.488348594913248);
		
		LEVEL_1_LNG_PER_PIXEL = (NORTH_EAST_LNG - SOUTH_WEST_LNG) / LEVEL_1_WIDTH_PIXEL;
		LEVEL_1_LAT_PER_PIXEL = (NORTH_EAST_LAT - SOUTH_WEST_LAT) / LEVEL_1_HEIGHT_PIXEL;
		icon = new CIcon();
		icon.image = ICON_URL;
		icon.iconSize = new CSize(26, 27);
		icon.iconAnchor = new CPoint(13, 13);
		icon.infoWindowAnchor = new CPoint(13, 13);
		
		mapDiv = document.getElementById(IMG_TAG);
		mapDiv.blogmap = this;
		map = new CMap(mapDiv);
		
		map.enableInfoWindow();
		map.setCenter(new CLatLng(MAP_CENTER_LAT, MAP_CENTER_LNG));
		map.setZoom(INIT_ZOOM); 
		zoomLevel = INIT_ZOOM;
		map.setMapMode(CMode.C_SATELLITEHYBRID_MAP);
		
		var callback = new Object();
		callback.success = function(responseText, responseXML){
			new mutex(new procOnload(responseText, responseXML), "action");
		}
		callback.failure = function(){
			//alert("Error in onload (get data)!");
		};
		
		var data = "swx=" + SOUTH_WEST_LNG + "&swy=" + SOUTH_WEST_LAT + "&nex=" + NORTH_EAST_LNG + "&ney=" + NORTH_EAST_LAT ; 
		new ajaxRequest("POST", GET_ITEM_INFO_INTERFACE, data, callback);
		
		return;
	};

	this.setNull = function(){
		mapDiv.blogmap = null;
		mapDiv = null;
		data = null;
		
		CEvent.removeListener(zoomendHandler);
		CEvent.removeListener(dragstartHandler);
		CEvent.removeListener(dragHandler);
		CEvent.removeListener(dragendHandler);
		clearMapMarker();
		blockInfoArray = null;
		markerOpen = "";
		icon = null; 
		map = null;
		
		return;
	};
};
BlogMap.onunload = function(){
	for(var i = 0; i < ajaxRequest.objectPool.length; i++)
		ajaxRequest.objectPool[i].abort();

	ajaxRequest.objectPool = null;
	ajaxRequest.Wait = null;
	
	mutex.Wait = null;
	CUnload();
};
