var CONST_IMG_PATH = 'http://map.hongkonghomes.com/map_lib_svg/'; var CONST_ZOOM_P1 = eval({ "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"2.34375", "gla1_per_px":"3.3125", "la" : "848000", "ln" : "800000", "total_y_meter": "3000", "total_y_px" : "1280", "total_x_meter": "3750", "total_x_px" : "1600"}); var CONST_ZOOM_P2 =  [{"level":"0", "id":"11"},{"level":"1", "id":"10"},{"level":"2", "id":"9"},{"level":"3", "id":"8"},{"level":"4", "id":"7"},{"level":"5", "id":"6"},{"level":"6", "id":"3"},{"level":"7", "id":"2"},{"level":"8", "id":"1"}]; var CONST_ALL_ZOOM = [{"id":"11","level":"0", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"0.29296875", "gla1_per_px":"0.4165625", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "10240", "total_x_meter": "3750", "total_x_px" : "12800" },{"id":"10","level":"1", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"0.5859375", "gla1_per_px":"0.833125", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "5120", "total_x_meter": "3750", "total_x_px" : "6400" },{"id":"9","level":"2", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"1.171875", "gla1_per_px":"1.66625", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "2560", "total_x_meter": "3750", "total_x_px" : "3200" },{"id":"8","level":"3", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"2.34375", "gla1_per_px":"3.3125", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "1280", "total_x_meter": "3750", "total_x_px" : "1600" },{"id":"7","level":"4", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"4.6875", "gla1_per_px":"6.625", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "640", "total_x_meter": "3750", "total_x_px" : "800" },{"id":"6","level":"5", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"9.375", "gla1_per_px":"13.25", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "320", "total_x_meter": "3750", "total_x_px" : "400" },{"id":"3","level":"6", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"18.75", "gla1_per_px":"26.5", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "160", "total_x_meter": "3750", "total_x_px" : "200" },{"id":"2","level":"7", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"37.5", "gla1_per_px":"53", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "80", "total_x_meter": "3750", "total_x_px" : "100" },{"id":"1","level":"8", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"75", "gla1_per_px":"106", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "40", "total_x_meter": "3750", "total_x_px" : "50" },{"id":"4","level":"9", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"150", "gla1_per_px":"212", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "20", "total_x_meter": "3750", "total_x_px" : "25" },{"id":"5","level":"10", "lg1_per_px":"0.0000000000", "la1_per_px":"0.0000000000", "glg1_per_px":"300", "gla1_per_px":"424", "la" : "848000", "ln" : "800000" , "total_y_meter": "3000", "total_y_px" : "10", "total_x_meter": "3750", "total_x_px" : "12" }]; var CONST_DEFAULT_ZOOM = 3; var CONST_DEFAULT_LN= 834262; var CONST_DEFAULT_LA = 815940; // JavaScript Document
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
 	var is_ie7    = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.")!=-1) );
 	//alert(is_ie7);
    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1); 

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));
    
   /*if( !(is_ie6 || is_ie6up || agt.indexOf("gecko/2006") != -1 || agt.indexOf("firefox/1.5") != -1 || agt.indexOf("firefox/2") != -1) )
    {
	 	alert("Sorry, Hongkonghomes Map does not support your browser.\n\nPlease use any of the supported browsers:\n1. Internet Explorer 6+\n2. Firefox 1.5+\n3. Mozilla 1.7+\n4. Netscape 8+"); 
	 	parent.change_location("http://www.hongkonghomes.com");
    }*/
/*var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}*/function setCookie(_1,_2,_3,_4,_5,_6){
document.cookie=_1+"="+escape(_2)+((_3)?"; expires="+_3.toGMTString():"")+((_4)?"; path="+_4:"")+((_5)?"; domain="+_5:"")+((_6)?"; secure":"");
}
function getCookie(_7){
var dc=document.cookie;
var _9=_7+"=";
var _a=dc.indexOf("; "+_9);
if(_a==-1){
_a=dc.indexOf(_9);
if(_a!=0){
return null;
}
}else{
_a+=2;
}
var _b=document.cookie.indexOf(";",_a);
if(_b==-1){
_b=dc.length;
}
return unescape(dc.substring(_a+_9.length,_b));
}
function deleteCookie(_c,_d,_e){
if(getCookie(_c)){
document.cookie=_c+"="+((_d)?"; path="+_d:"")+((_e)?"; domain="+_e:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function testGetDNS(){
cookieDomain=document.location.hostname;
}
function testGetCookie(){
var _f="varCook";
if(document.cookie.indexOf(_f)==-1){
return false;
}else{
cookieStart=document.cookie.indexOf(_f);
cookieValStart=(document.cookie.indexOf("=",cookieStart)+1);
cookieValEnd=document.cookie.indexOf(";",cookieStart);
if(cookieValEnd==-1){
cookieValEnd=document.cookie.length;
}
cookieValue=document.cookie.substring(cookieValStart,cookieValEnd);
}
if(cookieValue="True"){
return ("True");
}
}
function testSetCookie(_10,_11,_12,_13,_14,_15){
var _16=testGetDNS();
document.cookie=_10+"="+escape(_11)+((_12)?";expires="+_12.toGMTString()+1000*60*20:"")+((_13)?";path="+_13:"")+((_14)?";domain="+_16:"")+((_15)?";secure":"");
return true;
}
function CheckCookiesEnabled(){
testSetCookie("varCook","True","","/","","");
if(testGetCookie()=="True"){
return true;
}else{
return false;
}
}
var Drag={enable:true,obj:null,init:function(o,_18,_19,_1a,_1b,_1c,_1d,_1e,_1f,_20){
o.onmousedown=Drag.start;
o.hmode=_1d?false:true;
o.vmode=_1e?false:true;
o.root=_18&&_18!=null?_18:o;
if(o.hmode&&isNaN(parseInt(o.root.style.left))){
o.root.style.left="0px";
}
if(o.vmode&&isNaN(parseInt(o.root.style.top))){
o.root.style.top="0px";
}
if(!o.hmode&&isNaN(parseInt(o.root.style.right))){
o.root.style.right="0px";
}
if(!o.vmode&&isNaN(parseInt(o.root.style.bottom))){
o.root.style.bottom="0px";
}
o.minX=typeof _19!="undefined"?_19:null;
o.minY=typeof _1b!="undefined"?_1b:null;
o.maxX=typeof _1a!="undefined"?_1a:null;
o.maxY=typeof _1c!="undefined"?_1c:null;
o.xMapper=_1f?_1f:null;
o.yMapper=_20?_20:null;
o.root.onDragStart=new Function();
o.root.onDragEnd=new Function();
o.root.onDrag=new Function();
},start:function(e){
var o=Drag.obj=this;
e=Drag.fixE(e);
/*if(ie){
if(e.button!=1){
return;
}
}else{
if(e.button!=0){
return;
}
}*/
var y=parseInt(o.root.offsetTop);
var x=parseInt(o.root.offsetLeft);
o.root.onDragStart(e,x,y);
o.lastMouseX=e.clientX;
o.lastMouseY=e.clientY;
document.onmousemove=Drag.drag;
document.onmouseup=Drag.end;
var evt = e ? e : window.event;
var src = (evt.target) ? evt.target : evt.srcElement;
o.drag_src = src;
if(is_ie)
	return false;
else
{
	if(o.drag_src.tagName == "INPUT" || o.drag_src.tagName == "TEXTAREA")
		return;
	else
		return false;
}
},drag:function(e){
try{
e=Drag.fixE(e);
var o=Drag.obj;
var ey=e.clientY;
var ex=e.clientX;
var y=parseInt(o.root.offsetTop);
var x=parseInt(o.root.offsetLeft);
var nx,ny;
nx=x+(ex-o.lastMouseX);
ny=y+(ey-o.lastMouseY);
Drag.obj.root.style.left=nx+"px";
Drag.obj.root.style.top=ny+"px";
Drag.obj.lastMouseX=ex;
Drag.obj.lastMouseY=ey;
Drag.obj.root.onDrag(e,nx,ny);
return false;
if(is_ie)
	return false;
else
{
	if(o.drag_src.tagName == "INPUT" || o.drag_src.tagName == "TEXTAREA")
		return;
	else
		return false;
}
}
catch(e){
}
},end:function(){
try{
document.onmousemove=null;
document.onmouseup=null;
Drag.obj.root.onDragEnd(parseInt(Drag.obj.root.style[Drag.obj.hmode?"left":"right"]),parseInt(Drag.obj.root.style[Drag.obj.vmode?"top":"bottom"]));
Drag.obj=null;
}
catch(e){
}
},fixE:function(evt){
var e=evt?evt:window.event;
return e;
}};
var Drag2={obj:null,init:function(o,_2f,_30,_31,_32,_33,_34,_35,_36,_37){
o.onmousedown=Drag2.start;
o.hmode=_34?false:true;
o.vmode=_35?false:true;
o.root=_2f&&_2f!=null?_2f:o;
if(o.hmode&&isNaN(parseInt(o.root.style.left))){
o.root.style.left="0px";
}
if(o.vmode&&isNaN(parseInt(o.root.style.top))){
o.root.style.top="0px";
}
if(!o.hmode&&isNaN(parseInt(o.root.style.right))){
o.root.style.right="0px";
}
if(!o.vmode&&isNaN(parseInt(o.root.style.bottom))){
o.root.style.bottom="0px";
}
o.minX=typeof _30!="undefined"?_30:null;
o.minY=typeof _32!="undefined"?_32:null;
o.maxX=typeof _31!="undefined"?_31:null;
o.maxY=typeof _33!="undefined"?_33:null;
o.xMapper=_36?_36:null;
o.yMapper=_37?_37:null;
o.root.onDragStart=new Function();
o.root.onDragEnd=new Function();
o.root.onDrag=new Function();
},start:function(e){
var o=Drag2.obj=this;
e=Drag2.fixE(e);
var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);
var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);
o.root.onDragStart(e,x,y);
o.lastMouseX=e.clientX;
o.lastMouseY=e.clientY;
if(o.hmode){
if(o.minX!=null){
o.minMouseX=e.clientX-x+o.minX;
}
if(o.maxX!=null){
o.maxMouseX=o.minMouseX+o.maxX-o.minX;
}
}else{
if(o.minX!=null){
o.maxMouseX=-o.minX+e.clientX+x;
}
if(o.maxX!=null){
o.minMouseX=-o.maxX+e.clientX+x;
}
}
if(o.vmode){
if(o.minY!=null){
o.minMouseY=e.clientY-y+o.minY;
}
if(o.maxY!=null){
o.maxMouseY=o.minMouseY+o.maxY-o.minY;
}
}else{
if(o.minY!=null){
o.maxMouseY=-o.minY+e.clientY+y;
}
if(o.maxY!=null){
o.minMouseY=-o.maxY+e.clientY+y;
}
}
document.onmousemove=Drag2.drag;
document.onmouseup=Drag2.end;
return false;
},drag:function(e){
e=Drag2.fixE(e);
var o=Drag2.obj;
var ey=e.clientY;
var ex=e.clientX;
var y=parseInt(o.vmode?o.root.style.top:o.root.style.bottom);
//var y=parseInt(o.root.style.bottom);
var x=parseInt(o.hmode?o.root.style.left:o.root.style.right);
//var x=parseInt(o.root.style.right);
var nx,ny;

if(o.minX!=null){
ex=o.hmode?Math.max(ex,o.minMouseX):Math.min(ex,o.maxMouseX);
}
if(o.maxX!=null){
ex=o.hmode?Math.min(ex,o.maxMouseX):Math.max(ex,o.minMouseX);
}
if(o.minY!=null){
ey=o.vmode?Math.max(ey,o.minMouseY):Math.min(ey,o.maxMouseY);
}
if(o.maxY!=null){
ey=o.vmode?Math.min(ey,o.maxMouseY):Math.max(ey,o.minMouseY);
}
nx=x+((ex-o.lastMouseX)*(o.hmode?1:-1));
ny=y+((ey-o.lastMouseY)*(o.vmode?1:-1));
//nx=x+((ex-o.lastMouseX));
//ny=y+((ey-o.lastMouseY));
if(o.xMapper){
nx=o.xMapper(y);
}else{
if(o.yMapper){
ny=o.yMapper(x);
}
}
Drag2.obj.root.style[o.hmode?"left":"right"]=nx+"px";
//Drag2.obj.root.style.right=nx+"px";
Drag2.obj.root.style[o.vmode?"top":"bottom"]=ny+"px";
//Drag2.obj.root.style.bottom=ny+"px";
Drag2.obj.lastMouseX=ex;
Drag2.obj.lastMouseY=ey;
Drag2.obj.root.onDrag(e,nx,ny);
return false;
},end:function(){
document.onmousemove=null;
document.onmouseup=null;
Drag2.obj.root.onDragEnd(parseInt(Drag2.obj.root.style[Drag2.obj.hmode?"left":"right"]),parseInt(Drag2.obj.root.style[Drag2.obj.vmode?"top":"bottom"]));
Drag2.obj=null;
},fixE:function(e){
if(typeof e=="undefined"){
e=window.event;
}
if(typeof e.layerX=="undefined"){
e.layerX=e.offsetX;
}
if(typeof e.layerY=="undefined"){
e.layerY=e.offsetY;
}
return e;
}};
function enable_select(){
if(!ie){
var _44=["input","textarea","select"];
_44=_44.join("|");
function disableselect(e){
if(_44.indexOf(e.target.tagName.toLowerCase())==-1){
return false;
}
}
function reEnable(){
return true;
}
if(typeof document.onselectstart!="undefined"){
document.onselectstart=new Function("return true");
}else{
document.onmousedown=reEnable;
document.onmouseup=reEnable;
}
}else{
document.body.onselectstart=function(){
return true;
};
}
}
function disable_select(){
if(!ie){
var _46=["input","textarea","select"];
_46=_46.join("|");
function disableselect(e){
if(_46.indexOf(e.target.tagName.toLowerCase())==-1){
return false;
}
}
function reEnable(){
return true;
}
if(typeof document.onselectstart!="undefined"){
document.onselectstart=new Function("return false");
}else{
document.onmousedown=disableselect;
document.onmouseup=reEnable;
}
}else{
document.body.onselectstart=function(){
return false;
};
}
}
var skin1={"Drager":["images/dicon.gif","19","18"],"toRight":["images/to_right2.gif","24","19"],"toLeft":["images/to_left2.gif","24","19"],"DragBackground":["#CCCCCC","color"]};
var skin2={"Drager":["images/skin2drager.gif","22","19"],"toRight":["images/to_right2.gif","24","19"],"toLeft":["images/to_left2.gif","24","19"],"DragBackground":["images/skin2bg.gif","gif"]};
var SliderX=Class.create();
SliderX.prototype={id:"",out_obj:null,action:"",is_ie:false,tx:0,ty:0,draw_htm:"",slider_width:150,slider_height:150,with_slide_but:true,init_left:0,max_val:100,min_val:0,current_val:0,interval:1,max_x:0,max_y:0,min_x:0,min_y:0,slider_tbl:null,slider_obj:null,skin:skin2,target_layer:"",drag_obj:null,draging:false,timeout:null,slider_cur_inst:null,getEvt:function(evt){
var e=evt?evt:window.event;
var src=((ie)?e.srcElement:e.target);
return [e,src];
},getOffset:function(obj,_4c){
var _4d=0;
while(obj!=null){
_4d+=obj["offset"+(_4c?"Left":"Top")];
obj=obj.offsetParent;
}
return _4d;
},initialize:function(_4e,_4f,_50,_51,_52,_53,_54){
this.transform_timeout=null;
this.img_plus=new Image(21,20);
this.img_plus.src="images/slider_img/z_b.gif";
this.img_minus=new Image(21,20);
this.img_minus.src="images/slider_img/z_t.gif";
this.parent=_4f;
this.margin_left=this.getOffset(this.parent.parent.container,true);
this.margin_top=this.getOffset(this.parent.parent.container,false);
this.target_layer=_4e;
this.is_ie=ie;
if(_51!=null){
this.max_val=_51;
}
if(_52!=null){
this.min_val=_52;
}
if(this.max_val<this.min_val){
var t_v=this.max_val;
this.max_val=this.min_val;
this.min_val=t_v;
}
this.slider_height=_50;
this.draw();
this.slider_tbl=$(this.target_layer.id+"_drag_container");
this.slider_obj=$(this.target_layer.id+"_drag_icon");
this.tx=this.getOffset(this.slider_tbl,true)-this.margin_left;
this.ty=this.getOffset(this.slider_tbl,false)-this.margin_top;
this.min_x=this.tx+2;
this.min_y=this.ty+8;
this.max_x=this.tx+2;
this.max_y=this.ty+parseInt(this.slider_tbl.offsetHeight)-parseInt(this.slider_obj.offsetHeight)-8;
Drag2.init(this.slider_obj,null,this.min_x,this.max_x,this.min_y,this.max_y);
this.slider_obj.onDragStart=this.onDragStartEvent.bind(this);
this.slider_obj.onDrag=this.onDragEvent.bind(this);
this.slider_obj.onDragEnd=this.onDragEndEvent.bind(this);
this.set_val(_54);
},onDragStartEvent:function(evt,ex,ey){
this.draging=true;
var e=this.getEvt(evt);
},onDragEvent:function(evt,ex,ey){
this.get_val();
},onDragEndEvent:function(ex,ey){
this.set_val(this.current_val);
this.parent.mapChangeZoomLevel(this.current_val);
},get_val:function(){
var l=this.getOffset(this.slider_obj,true)-this.margin_left;
var t=this.getOffset(this.slider_obj,false)-6-this.margin_top;
if(t>this.min_y){
var p1=((t-this.min_y)/(this.max_y-this.min_y));
}else{
var p1=0;
}
var p2=(this.max_val-this.min_val)*(p1);
var p3=this.min_val+p2;
if(p3%this.interval!=0){
this.current_val=p3+(this.interval-(p3%this.interval));
}else{
this.current_val=p3;
}
},afterSetVal:function(){
if((this.tmp_new_top+this.drag_icon_obj.offsetHeight)>(this.getOffset(this.parent.parent.container)+this.parent.parent.container.offsetHeight)){
this.drag_icon_obj.style.visibility="hidden";
}else{
this.drag_icon_obj.style.visibility="visible";
}
},set_val:function(val,_65){
var tv=parseInt(val);
if(tv<this.min_val){
tv=this.min_val;
}
if(tv>this.max_val){
tv=this.max_val;
}
var p1=(tv-this.min_val)/(this.max_val-this.min_val);
var p2=(this.max_y-this.min_y)*p1;
var p3=Math.floor(p2)+this.min_y;
this.tmp_new_top=p3;
this.current_val=tv;
this.transformLayer(this.getOffset(this.slider_obj,true),(this.tmp_new_top),this.slider_obj,10,10);
},reset_drager:function(){
this.margin_left=this.getOffset(this.parent.parent.container,true);
this.margin_top=this.getOffset(this.parent.parent.container,false);
$(this.target_layer.id+"_drag_icon").style.left=(this.getOffset($(this.target_layer.id+"_drag_container"),true)+2-this.margin_left)+"px";
$(this.target_layer.id+"_drag_icon").style.top=(this.getOffset($(this.target_layer.id+"_drag_container"),false)-this.margin_top)+"px";
this.set_val(this.current_val);
this.tx=this.getOffset(this.slider_tbl,true)-this.margin_left;
this.ty=this.getOffset(this.slider_tbl,false)-this.margin_top;
this.min_x=this.tx+2;
this.min_y=this.ty+8;
this.max_x=this.tx+2;
this.max_y=this.ty+parseInt(this.slider_tbl.offsetHeight)-parseInt(this.slider_obj.offsetHeight)-8;
this.slider_obj.minX=this.min_x;
this.slider_obj.minY=this.min_y;
this.slider_obj.maxX=this.max_x;
this.slider_obj.maxY=this.max_y;
},zoom_in:function(){
this.set_val(this.current_val+1);
this.parent.mapChangeZoomLevel(this.current_val);
},zoom_out:function(){
this.set_val(this.current_val-1);
this.parent.mapChangeZoomLevel(this.current_val);
},refreshPos:function(){
if(this.tout!=null){
clearTimeout(this.tout);
}
this.reset_drager();
},draw:function(){
if(typeof (this.target_layer)=="undefined"||this.target_layer==null){
return;
}
var str="";
var _6b=this.slider_height;
if(this.with_slide_but){
_6b=_6b+40;
}
str+="<table id=\""+this.target_layer.id+"_drag_table\" width=\"21\" height=\""+_6b+"\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
str+="  <tr>";
str+="    <td height=\"20px\"><img id=\""+this.target_layer.id+"_zoom_out\" src=\""+this.img_minus.src+"\" width=\"21\" height=\"20\"></td>";
str+="  </tr>";
str+="  <tr>";
str+="    <td height=\""+(_6b-40)+"px\" id=\""+this.target_layer.id+"_drag_container\" align=\"center\" valign=\"middle\" style=\"border: 1px #999999 solid; background-color:#FFFFFF; padding-top:5px;  padding-bottom:5px\">";
str+="\t<div style=\"background-color:#999999; width:25%; height:100%\">&nbsp;</div>";
str+="\t</td>";
str+="  </tr>";
str+="  <tr>";
str+="    <td height=\"20\"><img id=\""+this.target_layer.id+"_zoom_in\" src=\""+this.img_plus.src+"\" width=\"21\" height=\"20\"></td>";
str+="  </tr>";
str+="</table>";
this.draw_htm=str;
this.target_layer.innerHTML=str;
$(this.target_layer.id+"_zoom_out").onclick=this.zoom_out.bindAsEventListener(this);
$(this.target_layer.id+"_zoom_out").style.cursor="pointer";
$(this.target_layer.id+"_zoom_in").onclick=this.zoom_in.bindAsEventListener(this);
$(this.target_layer.id+"_zoom_in").style.cursor="pointer";
$(this.target_layer.id+"_drag_container").onclick=this.getClickAction.bindAsEventListener(this);
$(this.target_layer.id+"_drag_container").style.cursor="pointer";
this.drag_icon_obj=document.createElement("div");
this.drag_icon_obj.id=this.target_layer.id+"_drag_icon";
this.drag_icon_obj.style.position="absolute";
this.drag_icon_obj.style.cursor="pointer";
this.drag_icon_obj.style.overflow="hidden";
if(this.is_ie){
this.drag_icon_obj.style.width=(21-4)+"px";
}else{
this.drag_icon_obj.style.width=(21-6)+"px";
}
this.drag_icon_obj.style.height="10px";
this.drag_icon_obj.style.border="1px #999999 solid";
this.drag_icon_obj.style.zIndex="15000";
this.drag_icon_obj.style.backgroundColor="#FFD966";
this.drag_icon_obj.style.left=(this.getOffset($(this.target_layer.id+"_drag_container"),true)-this.margin_left+2)+"px";
this.drag_icon_obj.style.top="0px";
this.parent.parent.container.appendChild(this.drag_icon_obj);
},getClickAction:function(evt){
e=this.getEvt(evt);
var l=parseInt(e[0].clientX)-this.margin_left;
var t=parseInt(e[0].clientY)-6-this.margin_top;
if(t>this.min_y){
var p1=((t-this.min_y)/(this.max_y-this.min_y));
}else{
var p1=0;
}
var p2=(this.max_val-this.min_val)*(p1);
var p3=this.min_val+p2;
var _72=-100;
if(p3%this.interval!=0){
_72=p3+(this.interval-(p3%this.interval));
}else{
_72=p3;
}
this.set_val(_72,true);
this.parent.mapChangeZoomLevel(this.current_val);
},transformLayer:function(x,y,obj,_76,_77){
if(this.transform_timeout!=null){
clearTimeout(this.transform_timeout);
}
this.x1=obj.offsetLeft;
this.y1=obj.offsetTop;
this.x2=(this.x1+parseInt(obj.offsetWidth));
this.y2=(this.y1+parseInt(obj.offsetHeight));
stepDuration=Math.round(_76/_77);
tx1=this.x1;
ty1=this.y1;
x=(x)?x:tx1;
y=(y)?y:ty1;
difX=(x-tx1)/_77;
difY=(y-ty1)/_77;
tx1+=difX;
ty1+=difY;
if(!isNaN(tx1)&&!isNaN(ty1)&&tx1!="Infinity"&&ty1!="Infinity"&&tx1!="-Infinity"&&ty1!="-Infinity"){
obj.style.top=ty1+"px";
}
_76=(_76-stepDuration);
_77--;
if(_77>=0){
this.transform_timeout=setTimeout((function(){
this.transformLayer(x,y,obj,_76,_77);
}).bind(this),stepDuration);
}else{
if(this.transform_timeout!=null){
clearTimeout(this.transform_timeout);
}
this.afterSetVal(this.tmp_new_top);
}
return true;
}};

//var CONST_MAP_TILE_LIB = ["http://map.hongkonghomes.com/map2/util/get_tile.php","http://map.hongkonghomes.com:81/map_tile/util/get_tile.php"];
var CONST_MAP_TILE_LIB = ["http://map.hongkonghomes.com/map2/util/get_tile_test.php"];
var DEFAULT_MAP_ICON_IMG = new Image(22,22);
DEFAULT_MAP_ICON_IMG.src=CONST_IMG_PATH+"images/default_map_point.gif";

Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
}
Array.prototype.max = function(){
	return Math.max.apply({},this)
}
Array.prototype.min = function(){
	return Math.min.apply({},this)
}

function __set_obj_status (obj)
{
	try{
		obj.blur();
		obj.focus();
	}catch(e){}
}
var OverlayInfoWindowTab = Class.create();
OverlayInfoWindowTab.prototype = {
	header : null,
	content : null,
	initialize : function (header, content)
	{

		if(header == null || header == "" || content == null)
			return false;

		this.header = header;
		this.content = content;

		this.content_div = document.createElement("DIV");
		this.content_div.style.overflow = "visible";
		this.content_div.style.display = "none";
		this.content_div.innerHTML = content;
		this.content_div.draggable = false;
	},
	setContent : function (content)
	{
		this.content = content;
		this.content_div.innerHTML = this.content;
	},
	setHeader : function (header)
	{
		this.header = header;
	}
}

var OverlayInfoWindow = Class.create();
OverlayInfoWindow.prototype = {
	div : null,
	tabs : null,
	initialize : function (width, height, map_obj, opt)
	{
	try{
		this.initialized = false;
		this.show_tab = true;
		this.map = null;
		this.auto_focus = true;
		this.opt = null;
		if(opt != null)
			this.opt = opt;

		if(typeof(map) != "undefined" && map instanceof Map2)
			this.map = map;
		if(map_obj instanceof Map2)
			this.map = map_obj;

		this.tabs = [];
		this.current_tab = -1;

		this.overlay = null;

		this.min_width = 150;
		this.min_height = 150;

		this.max_width = 600;
		this.max_height = 600;

		this.iframe_listener_added = false;
		if(width != null && !isNaN(width))
			this.width = width;
		else
			this.width = 250;

		if(height != null && !isNaN(height))
			this.height = height;
		else
			this.height = 250;

		if(this.width > this.max_width)
			this.width = this.max_width;
		if(this.width < this.min_width)
			this.width = this.min_width;

		if(this.height > this.max_height)
			this.height = this.max_height;
		if(this.height < this.min_height)
			this.height = this.min_height;

		this.tpl = document.createElement("IMG");
		this.tpl.src = CONST_IMG_PATH+"images/info_window_tpl.gif";
		if(this.opt != null && this.opt.background != null)
			this.tpl.src = this.opt.background;

		this.div = document.createElement("DIV");
		this.div.style.cursor = "default";
		this.div.style.overflow = "visible";
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";
		this.div.style.zIndex = "200";
		this.div.style.display = "block";

		this.sub_div = [];
		this.sub_div[0] = document.createElement("DIV");
		this.sub_div[0].style.width = "25px";
		this.sub_div[0].style.height = "25px";
		this.sub_div[0].style.left = "0px";
		this.sub_div[0].style.top = "0px";
		this.sub_div[0].style.overflow = "hidden";
		this.sub_div[0].style.position = "absolute";
		this.sub_div[0].innerHTML = '<img src="'+this.tpl.src+'" style="left:0px;top:0px;position:absolute;">';

		this.sub_div[1] = document.createElement("DIV");
		this.sub_div[1].style.width = this.width+"px";
		this.sub_div[1].style.height = "25px";
		this.sub_div[1].style.overflow = "hidden";
		this.sub_div[1].style.position = "absolute";
		this.sub_div[1].style.left = "25px";
		this.sub_div[1].style.top = "0px";
		this.sub_div[1].style.borderTop = "1px solid rgb(171, 171, 171)";
		this.sub_div[1].style.backgroundColor = "#FFFFFF";

		this.sub_div[2] = document.createElement("DIV");
		this.sub_div[2].style.width = "25px";
		this.sub_div[2].style.height = "25px";
		this.sub_div[2].style.overflow = "hidden";
		this.sub_div[2].style.position = "absolute";
		this.sub_div[2].style.left = (this.width+25)+"px";
		this.sub_div[2].style.top = "0px";
		this.sub_div[2].innerHTML = '<img src="'+this.tpl.src+'" style="left:-665px;top:0px;position:absolute;">';

		this.sub_div[3] = document.createElement("DIV");
		this.sub_div[3].style.width = "25px";
		this.sub_div[3].style.height = this.height+"px";
		this.sub_div[3].style.overflow = "hidden";
		this.sub_div[3].style.position = "absolute";
		this.sub_div[3].style.left = "0px";
		this.sub_div[3].style.top = "25px";
		this.sub_div[3].style.borderLeft = "1px solid rgb(171, 171, 171)";
		this.sub_div[3].style.backgroundColor = "#FFFFFF";

		this.sub_div[4] = document.createElement("DIV");

		this.sub_div[4].style.overflow = "visible";
		this.sub_div[4].style.position = "absolute";
		this.sub_div[4].style.left = "25px";
		this.sub_div[4].style.top = "25px";
		this.sub_div[4].draggable = false;
		this.sub_div[4].style.backgroundColor = "#FFFFFF";

		this.sub_div[5] = document.createElement("DIV");
		if(is_ie)
			this.sub_div[5].style.width = "24px";
		else
			this.sub_div[5].style.width = "24px";
		this.sub_div[5].style.height = this.height+"px";
		this.sub_div[5].style.overflow = "hidden";
		this.sub_div[5].style.position = "absolute";
		this.sub_div[5].style.left = (this.width+25)+"px";
		this.sub_div[5].style.top = "25px";
		this.sub_div[5].style.borderRight = "1px solid rgb(171, 171, 171)";
		this.sub_div[5].style.backgroundColor = "#FFFFFF";

		this.sub_div[6] = document.createElement("DIV");
		this.sub_div[6].style.width = "25px";
		this.sub_div[6].style.height = "25px";
		this.sub_div[6].style.overflow = "hidden";
		this.sub_div[6].style.position = "absolute";
		this.sub_div[6].style.left = "0px";
		this.sub_div[6].style.top = (25+this.height)+"px";
		this.sub_div[6].innerHTML = '<img src="'+this.tpl.src+'" style="left:0px;top:-665px;position:absolute;">';

		this.sub_div[7] = document.createElement("DIV");
		this.sub_div[7].style.width = this.width+"px";
		if(is_ie)
			this.sub_div[7].style.height = "25px";
		else
			this.sub_div[7].style.height = "24px";
		this.sub_div[7].style.overflow = "hidden";
		this.sub_div[7].style.position = "absolute";
		this.sub_div[7].style.left = "25px";
		this.sub_div[7].style.top = (25+this.height)+"px";
		this.sub_div[7].style.borderBottom = "1px solid rgb(171, 171, 171)";
		this.sub_div[7].style.backgroundColor = "#FFFFFF";

		this.sub_div[8] = document.createElement("DIV");
		this.sub_div[8].style.width = "25px";
		this.sub_div[8].style.height = "25px";
		this.sub_div[8].style.overflow = "hidden";
		this.sub_div[8].style.position = "absolute";
		this.sub_div[8].style.left = (this.width+25)+"px";
		this.sub_div[8].style.top = (25+this.height)+"px";
		this.sub_div[8].innerHTML = '<img src="'+this.tpl.src+'" style="left:-665px;top:-665px;position:absolute;">';

		this.sub_div[9] = document.createElement("DIV");
		this.sub_div[9].style.width = "98px";
		this.sub_div[9].style.height = "96px";
		this.sub_div[9].style.overflow = "hidden";
		this.sub_div[9].style.position = "absolute";
		this.sub_div[9].style.left = ((this.width/2))+"px";
		this.sub_div[9].style.top = (25+this.height)+"px";
		this.sub_div[9].innerHTML = '<img src="'+this.tpl.src+'" style="left:0px;top:-690px;position:absolute;">';
		if(is_ie)
			var sheight = 23;
		else
			var sheight = 22;
		this.sub_div[10] = document.createElement("DIV");
		this.sub_div[10].innerHTML = '<div style="position:absolute;left:15px;top:5px;font-size:11px;color:rgb(171, 171, 171);">Close</div>';
		this.sub_div[10].style.width = "50px";
		this.sub_div[10].style.height = "22px";
		this.sub_div[10].style.overflow = "hidden";
		this.sub_div[10].style.position = "absolute";
		this.sub_div[10].style.left = (this.width)+"px";
		this.sub_div[10].style.top = "0px";
		this.sub_div[10].style.cursor = "pointer";
		this.sub_div[10].onclick = this.hide.bindAsEventListener(this);

		this.sub_div[11] = document.createElement("DIV");
		this.sub_div[11].style.height = "30px";
		this.sub_div[11].style.left = "0px";
		this.sub_div[11].style.top = "-25px";
		this.sub_div[11].style.overflow = "hidden";
		this.sub_div[11].style.position = "absolute";
		this.sub_div[11].style.display = "none";
		this.sub_div[11].innerHTML = "";
		//alert("c");
		for(var i=0; i < this.sub_div.length; i++)
		{
			this.div.appendChild(this.sub_div[i]);
		}
		this.last_tab = -1;
		this.current_tab = 0;
		this.div.style.display = "none";
		this.flag = false;
		this.initialized = true;
		//alert("c2");
	}catch(e)
	{
		//alert(e.message);
	}
	},
	setTabPosition : function ()
	{
		var zIndex = 65;
		var width_margin = (this.tabs.length*102)-(this.sub_div[11].offsetWidth);
		if(width_margin > 0)
		{
			var width_ratio = Math.floor(width_margin/(this.tabs.length-1));
			for(var i=0; i < this.tabs.length; i++)
			{
				if(i > 0)
					this.tabs[i].div.style.left = (this.tabs[i-1].div.offsetLeft+(102-width_ratio))+"px";
				else
					this.tabs[i].div.style.left = "0px";

				if(this.current_tab == i)
				{
					this.tabs[i].div.style.zIndex = "68";
				}
				else
				{
					this.tabs[i].div.style.zIndex = zIndex;
					if(this.current_tab == 0)
						zIndex--
					else
						zIndex++;
				}
			}

		}
		else
		{
			for(var i=0; i < this.tabs.length; i++)
			{
				this.tabs[i].div.style.left = (i*102)+"px";
				this.tabs[i].div.style.zIndex = zIndex;
				if(this.current_tab == i)
				{
					this.tabs[i].div.style.zIndex = "69";
				}
				else
				{
					this.tabs[i].div.style.zIndex = zIndex;
					if(this.current_tab == 0)
						zIndex--
					else
						zIndex++;
				}
			}
		}
	},
	setShowTab : function (bool)
	{
		this.show_tab = bool;
	},
	addTab : function(header, content)
	{
	try{
		if(this.overlay == null)
			return false;

		if(header == null || header == "" || content == null || this.tabs.length > 2)
			return false;

		var tmp_tab = new OverlayInfoWindowTab(header, content);

		if(tmp_tab.content_div.childNodes.length > 0 && typeof(tmp_tab.content_div.childNodes[0]) == "object")
		{
			try{
				tmp_tab.content_div.childNodes[0].bubble_obj = this;
				tmp_tab.content_div.childNodes[0].tab_position = this.tabs.length;
			}
			catch(e)
			{}
		}

		if(!is_ie)
		{
			var inputs = tmp_tab.content_div.getElementsByTagName("INPUT");
			for(var i=0; i < inputs.length; i++)
			{
				inputs[i].draggable = false;
				if(inputs[i].type == "text")
				{
					Event.observe(inputs[i],"click",__set_obj_status.bind(null, inputs[i]));
				}
			}
			var inputs = tmp_tab.content_div.getElementsByTagName("TEXTAREA");
			for(var i=0; i < inputs.length; i++)
			{
				inputs[i].draggable = false;
				Event.observe(inputs[i],"click",__set_obj_status.bind(null, inputs[i]));
			}
		}

		this.tabs[this.tabs.length] = tmp_tab;

		while(this.sub_div[11].childNodes.length > 0)
			this.sub_div[11].removeChild(this.sub_div[11].childNodes[0]);

		for(var i=0; i < this.tabs.length; i++)
		{
			if(this.tabs[i].div == null)
			{
				this.tabs[i].div = document.createElement("DIV");
				this.tabs[i].div.style.width = "102px";
				this.tabs[i].div.style.height = "25px";
				this.tabs[i].div.style.overflow = "hidden";
				this.tabs[i].div.style.position = "absolute";
				this.tabs[i].div.style.cursor = "pointer";
				this.tabs[i].div.onclick = this.switchTab.bind(this, i);
				this.tabs[i].div.style.top = "0px";
				this.tabs[i].div.innerHTML = '<img src="'+this.tpl.src+'" style="left:-200px;top:-690px;position:absolute;">';
				this.tabs[i].header_div = document.createElement("DIV");
				this.tabs[i].header_div.style.width = "102px";
				this.tabs[i].header_div.style.height = "22px";
				this.tabs[i].header_div.style.overflow = "hidden";
				this.tabs[i].header_div.style.position = "absolute";
				this.tabs[i].header_div.style.left = "0px";
				//this.tabs[i].header_div.style.paddingLeft = "5px";
				this.tabs[i].header_div.style.top = "5px";
				this.tabs[i].header_div.align = "center";
				this.tabs[i].header_div.style.fontSize = "11px";
				this.tabs[i].header_div.style.color = "#333333";
				this.tabs[i].header_div.innerHTML = this.tabs[i].header;
				this.tabs[i].div.title = this.tabs[i].header;
				this.tabs[i].div.appendChild(this.tabs[i].header_div);

				//this.tabs[i].div.innerHTML = this.tabs[i].header;
			}
			else
			{
				this.tabs[i].header_div.innerHTML = this.tabs[i].header;
				//this.tabs[i].div.innerHTML = this.tabs[i].header;
			}
			/*switch(i)
			{
				case 0:
					this.tabs[i].div.style.left = "0px";
					break;
				case 1:
					this.tabs[i].div.style.left = "50px";
					break;
				case 2:
					this.tabs[i].div.style.left = "100px";
					break;

			}*/
			this.sub_div[11].appendChild(this.tabs[i].div);
		}

		if(is_gecko != null && is_gecko)
		{
			if(this.tabs[(this.tabs.length-1)].content.indexOf("<iframe") != -1)
			{
				if(!this.iframe_listener_added)
				{
					if(this.overlay.map != null)
					{
						this.overlay.map.addOnDragStartListener(this.onDragStartListener.bind(this));
						this.overlay.map.addOnDragEndListener(this.onDragEndListener.bind(this));
					}
					this.iframe_listener_added = true;
				}
			}
		}
	}
	catch(e)
	{
	//		if(debug)
				alert(e.message);
	}
	},
	switchTab : function (pos)
	{
		if(pos >= this.tabs.length)
			return;

		//if(this.last_tab != -1)
		//	this.tabs[this.current_tab].content = this.sub_div[4].innerHTML;

		this.current_tab = pos;
		var old_width = this.sub_div[4].offsetWidth;

		/*this.last_tab = pos;

		this.sub_div[4].innerHTML = this.tabs[pos].content;
		if(this.sub_div[4].childNodes.length > 0 && typeof(this.sub_div[4].childNodes[0]) == "object")
		{
			this.sub_div[4].childNodes[0].bubble_obj = this;
			this.sub_div[4].childNodes[0].tab_position = pos;
		}*/
		while(this.sub_div[4].childNodes.length > 0)
		{
			this.sub_div[4].removeChild(this.sub_div[4].childNodes[0]);
		}

		var zIndex = "65";
		for(var i=0; i < this.tabs.length; i++)
		{
			if(i == pos)
			{
				this.sub_div[4].appendChild(this.tabs[i].content_div);
				this.tabs[i].content_div.style.display = "block";
				this.tabs[i].div.style.zIndex = "68";
				this.tabs[i].div.childNodes[0].style.left = "-100px";
			}
			else
			{
				this.tabs[i].content_div.style.display = "none";
				this.tabs[i].div.style.zIndex = zIndex;
				this.tabs[i].div.childNodes[0].style.left = "-200px";
				if(pos == 0)
					zIndex--
				else
					zIndex++;
			}
		}

		this.setComponentPosition();
		if(old_width != this.sub_div[4].offsetWidth)
		{
			this.setTabPosition();
		}
		if(this.overlay != null && this.overlay.auto_focus)
			this.checkEdge();
	},
/*	setContent : function (html)
	{
		if(typeof(this.initialized) == "undefined" || !this.initialized || this.content == null)
			return false
		if(html != null)
			this.content = html
		this.sub_div[4].innerHTML = this.content;

	},*/
	setOverlay : function (overlay)
	{
		if(overlay != null)
		{
			this.overlay = overlay;
		}
		//this.setContent();
	},
	onDragStartListener : function ()
	{

		if(this.div.style.display == "none")
			return;
		var iframe = this.div.getElementsByTagName("iframe");
		for(var i=0; i < iframe.length; i++)
		{
			iframe[i].style.visibility = "hidden";
		}
	},
	onDragEndListener : function ()
	{
		if(this.div.style.display == "none")
			return;
		var iframe = this.div.getElementsByTagName("iframe");
		for(var i=0; i < iframe.length; i++)
		{
			iframe[i].style.visibility = "visible";
		}
	},
	setComponentPosition : function ()
	{
		var margin_top = 0;

		if(this.tabs.length > 0 && this.show_tab)
		{
			this.sub_div[11].style.display = "block";
			if(this.sub_div[4].childNodes.length > 0)
				this.sub_div[11].style.width = this.sub_div[4].childNodes[0].offsetWidth+"px";
			else
				this.sub_div[11].style.width = this.sub_div[4].offsetWidth+"px";
			this.sub_div[11].style.left = "25px";
			this.sub_div[11].style.top = "0px";
			margin_top = 24;
		}
		else
			this.sub_div[11].style.display = "none";

		this.sub_div[0].style.top = (0)+"px";
		this.sub_div[1].style.top = (0)+"px";
		this.sub_div[2].style.top = (0)+"px";
		this.sub_div[3].style.top = (25)+"px";
		this.sub_div[4].style.top = (25)+"px";
		this.sub_div[5].style.top = (25)+"px";
		this.sub_div[10].style.top = (1)+"px";

		//alert(this.sub_div[4].style.display);
		this.sub_div[3].style.height = this.sub_div[4].offsetHeight+"px";
		this.sub_div[5].style.height = this.sub_div[4].offsetHeight+"px";
		if(this.sub_div[4].childNodes.length > 0 && typeof(this.sub_div[4].childNodes[0]) == "object")
		{
			this.sub_div[3].style.height = this.sub_div[4].childNodes[0].offsetHeight+"px";
			this.sub_div[5].style.height = this.sub_div[4].childNodes[0].offsetHeight+"px";
		}
		this.sub_div[6].style.top = (25+this.sub_div[4].offsetHeight)+"px";
		this.sub_div[7].style.top = (25+this.sub_div[4].offsetHeight)+"px";
		this.sub_div[8].style.top = (25+this.sub_div[4].offsetHeight)+"px";
		this.sub_div[9].style.top = (25+this.sub_div[4].offsetHeight)+"px";
		//alert(this.sub_div[1].offsetWidth+" , "+this.sub_div[4].offsetWidth+" "+this.sub_div[4].childNodes[0].offsetWidth);
		//if(this.sub_div[4].childNodes.length > 0)
			//this.sub_div[4].style.width = this.sub_div[4].childNodes[0].offsetWidth+"px";

		this.sub_div[1].style.width = (this.sub_div[4].offsetWidth)+"px";
		this.sub_div[7].style.width = (this.sub_div[4].offsetWidth)+"px";
		this.sub_div[2].style.left = (25+this.sub_div[4].offsetWidth)+"px";
		this.sub_div[5].style.left = (25+this.sub_div[4].offsetWidth)+"px";
		this.sub_div[8].style.left = (25+this.sub_div[4].offsetWidth)+"px";
		this.sub_div[10].style.left = (this.sub_div[4].offsetWidth)+"px";
		this.sub_div[3].style.height = this.sub_div[4].offsetHeight+"px";
		this.sub_div[5].style.height = this.sub_div[4].offsetHeight+"px";
		if(margin_top > 0)
		{
			for(var i=0; i < this.sub_div.length-1; i++)
			{
				this.sub_div[i].style.top = (this.sub_div[i].offsetTop+margin_top)+"px";
			}
		}
		this.div.style.left = (((this.sub_div[4].offsetWidth/2)-10)*(-1))+"px";
		this.sub_div[9].style.left = ((this.sub_div[4].offsetWidth/2))+"px";

		var top = ((this.sub_div[4].offsetHeight+25+this.sub_div[9].offsetHeight)*(-1));
		if(margin_top > 0)
		{
			top-=(margin_top-2);
		}
		this.div.style.top = (top)+"px";
		//alert(this.sub_div[4].offsetWidth);
	},
	checkEdge : function ()
	{

		var left_margin = (this.overlay.map.__getOffset(this.overlay.map.div,true)-this.overlay.map.__getOffset(this.div,true));
		var top_margin = (this.overlay.map.__getOffset(this.overlay.map.div,false)-this.overlay.map.__getOffset(this.div,false));
		var left_margin2 = ((this.overlay.map.__getOffset(this.overlay.map.div,true)+this.overlay.map.div.offsetWidth)-(this.overlay.map.__getOffset(this.div,true)+(this.sub_div[0].offsetWidth+this.sub_div[1].offsetWidth+this.sub_div[2].offsetWidth)));

		var move_x = 0;
		var move_y = 0;
		if(left_margin > 0)
		{
			var move_x = left_margin+10;
		}
		else if(left_margin2 < 0)
		{
			var move_x = left_margin2-10;
		}
		if(top_margin > 0)
		{
			var move_y = top_margin+10;
		}
		this.overlay.map.moveToByXY(move_x, move_y);
	},
	show : function ()
	{
		if(this.overlay == null)
			return false;
		this.overlay.div.style.zIndex = "60";
		this.div.style.display = "block";
		this.div.style.top = "-1000px";

		this.switchTab(this.current_tab);
		//if(this.sub_div[4].offsetWidth < this.min_width)
		//	this.sub_div[4].style.width = this.min_width+"px";

		if(this.sub_div[4].childNodes.length > 0 && this.sub_div[4].childNodes[0].offsetWidth < this.min_width)
			this.sub_div[4].childNodes[0].style.width = this.min_width+"px";
		else
			this.sub_div[4].childNodes[0].style.width = this.sub_div[4].childNodes[0].offsetWidth+"px";

		this.setComponentPosition();

		this.setTabPosition();
		if(this.overlay != null && this.overlay.auto_focus)
			this.checkEdge();
	},
	update : function ()
	{
		/*if(this.sub_div[4].childNodes.length > 0)
		{
			this.sub_div[4].childNodes[0].style.width = "";
			this.sub_div[4].childNodes[0].style.height = "";
		}


		if(this.sub_div[4].childNodes.length > 0 && this.sub_div[4].childNodes[0].offsetWidth < this.min_width)
			this.sub_div[4].childNodes[0].style.width = this.min_width+"px";
		if(this.sub_div[4].childNodes.length > 0 && this.sub_div[4].childNodes[0].offsetHeight < this.min_height)
			this.sub_div[4].childNodes[0].style.height = this.min_height+"px";
		this.setComponentPosition();*/
		this.hide();
		this.show();
		
	},
	hide : function ()
	{
		if(this.overlay == null)
			return false;
		this.div.style.display = "none";
	},
	toJSON : function ()
	{
		var obj = {};
		obj.width = this.width;
		obj.height = this.height;
		var tab_json = [];
		for(var i=0; i < this.tabs.length; i++)
		{
			//tab_json[i] = Object.toJSON(this.tabs[i]);
			tab_json[i] = this.tabs[i];
		}
		obj.tab_list = tab_json;
		return Object.toJSON(obj);
	}
	/*,
	getJSON : function ()
	{
		alert(Object.toJSON(this));
	}*/
}

var MapPointIcon = Class.create();
MapPointIcon.prototype = {
	image : null,
	width : null,
	height : null,
	initialize : function (img_src, width, height)
	{
		if(typeof(img_src) == "undefined" || img_src == null)
			return false;

		this.image = document.createElement("IMG");
		this.image.onload = this.imageOnload.bindAsEventListener(this);
		this.image.src = img_src;
		if(width != null && !isNaN(width) && width != 0)
			this.image.style.width = width+"px";
		if(height != null && !isNaN(height) && height != 0)
			this.image.style.height = height+"px";
	},
	imageOnload : function ()
	{
		this.width = this.image.offsetWidth;
		this.height = this.image.offsetHeight;
	}
}

var MapPoint = Class.create();
MapPoint.prototype = {
	opt : null,
	draggable : false,
	ln : null,
	la : null,
	initialize : function(ln, la, opt)
	{
		this.auto_focus = true;
		this.bounce = 0;
		this.first_set_pos = true;
		this.added = false;
		this.initialized = false;
		this.initialized_obj = false;

		this.external_onclick_listener = [];
		this.external_ondragend_listener = [];

		if(ln == null || la == null)
			return false;

		this.ln = ln;
		this.la = la;

		if(typeof(opt) == "undefined" || opt == null)
			this.opt = {};
		else
			this.opt = opt;

		if(typeof(this.opt.icon) == "undefined" || !(this.opt.icon instanceof MapPointIcon))
		{
			this.opt.icon = new MapPointIcon(DEFAULT_MAP_ICON_IMG.src, 22, 22);
			if(typeof(this.opt.title) != "undefined")
			{
				this.opt.icon.image.title = this.opt.title;
			}
		}

		this.drag_cross = document.createElement("IMG");
		this.drag_cross.src = CONST_IMG_PATH+"images/drag_cross.png";
		this.drag_cross.width = "16";
		this.drag_cross.height = "16";
		this.drag_cross.style.width = "16px";
		this.drag_cross.style.height = "16px";
		this.drag_cross.style.position = "relative";
		this.drag_cross.style.display = "none";

		this.standard_zIndex = 55;
		this.top_zIndex = 56;

		this.tmp = 0;
		this.dragging = false;
		this.initialized = true;
		/*if(map != null)
		{

			this.map = map;
			this.initializeObject(this.map);
		}*/
		this.initializeObject();
	},
	initializeObject : function()
	{
		this.div = document.createElement("DIV");
		this.div.className = "map_overlay";
		this.opt.icon.image.style.position = "relative";
		this.div.appendChild(this.opt.icon.image);
		if(this.opt.icon.width != null && this.opt.icon.height != null)
		{
			this.div.style.width = this.opt.icon.width+"px";
			this.div.style.height = this.opt.icon.height+"px";
		}
		this.div.style.left = "-1000px";
		this.div.style.position = "absolute";
		this.div.style.zIndex = this.standard_zIndex;
		this.div.style.cursor = "pointer";
		this.div.appendChild(this.drag_cross);

		this.div.onmouseover = this.mouseoverListener.bindAsEventListener(this);
		this.div.onmouseout = this.mouseoutListener.bindAsEventListener(this);

		this.div.onclick = this.clickListener.bindAsEventListener(this);
		this.div.ondblclick = this.dblClickListener.bindAsEventListener(this);
		this.initialized_obj = true;
	},
	/*
	initializeObject : function(map)
	{
		if(typeof(map) == "undefined" || !(map instanceof Map2) || !this.initialized)
			return false;

		this.map = map;

		this.div = document.createElement("DIV");
		this.div.className = "map_overlay";
		this.opt.icon.image.style.position = "relative";
		this.div.appendChild(this.opt.icon.image);
		if(this.opt.icon.width != null && this.opt.icon.height != null)
		{
			this.div.style.width = this.opt.icon.width+"px";
			this.div.style.height = this.opt.icon.height+"px";
		}
		this.div.style.left = "-1000px";
		this.div.style.position = "absolute";
		this.div.style.zIndex = this.standard_zIndex;
		this.div.style.cursor = "pointer";
		this.div.appendChild(this.drag_cross);

		this.div.onmouseover = this.mouseoverListener.bindAsEventListener(this);
		this.div.onmouseout = this.mouseoutListener.bindAsEventListener(this);

		this.div.onclick = this.clickListener.bindAsEventListener(this);
		this.div.ondblclick = this.dblClickListener.bindAsEventListener(this);
		this.initialized_obj = true;
	},*/
	addOnDragEndListener : function (f)
	{
		if(typeof(f) != "function")
			return false;
		this.external_ondragend_listener.push(f);
	},
	removeOnDragEndListener : function (f)
	{
		if(typeof(f) != "function")
			return false;
		var pos = -1;
		for(var i=0; i < this.external_ondragend_listener.length; i++)
		{
			if(f == this.external_ondragend_listener[i])
			{
				pos = i;
				break;
			}
		}
		if(pos != -1)
		{
			this.external_ondragend_listener.splice(pos , 1);
		}	
	},
	addOnClickListener : function (f)
	{
		if(typeof(f) != "function")
			return false;
		this.external_onclick_listener.push(f);
	},
	removeOnClickListener : function(f)
	{
		if(typeof(f) != "function")
			return false;
		var pos = -1;
		for(var i=0; i < this.external_onclick_listener.length; i++)
		{
			if(f == this.external_onclick_listener[i])
			{
				pos = i;
				break;
			}
		}
		if(pos != -1)
		{
			this.external_onclick_listener.splice(pos , 1);
		}
	},
	mouseoverListener : function ()
	{
		this.div.style.zIndex = this.top_zIndex;
		if(this.opt.info_bubble != null && this.opt.info_bubble instanceof OverlayInfoWindow && this.opt.info_bubble.div.style.display != "none")
		{
			this.div.style.zIndex = 60;
		}
	},
	mouseoutListener : function ()
	{
		this.div.style.zIndex = this.standard_zIndex;
		if(this.opt.info_bubble != null && this.opt.info_bubble instanceof OverlayInfoWindow && this.opt.info_bubble.div.style.display != "none")
		{
			this.div.style.zIndex = 60;
		}		
	},
	clickListener : function (evt)
	{
		if(this.map == null)
			return false;

		var e = this.map.__getEvt(evt);
		if(e[1] != this.opt.icon.image)
			return false;

		if(this.dragging)
		{
			this.dragging = false;
			return false;
		}
		this.toggleInfoBubble();

		for(var i=0; i < this.external_onclick_listener.length; i++)
		{
			this.external_onclick_listener[i](evt);
		}
		this.tmp++;
	},
	dblClickListener : function ()
	{
		this.tmp++;
	},
	enableDrag : function ()
	{
		if(this.draggable || this.div == null)
			return false;
		this.standard_zIndex+=2;
		this.top_zIndex+=2;
		Drag.init($(this.opt.icon.image),$(this.div));
		this.div.onDragStart = this.onDragStartListener.bind(this);
		this.div.onDrag = this.onDragListener.bind(this);
		this.div.onDragEnd = this.onDragEndListener.bind(this);
		this.draggable = true;
	},
	disableDrag : function ()
	{
		this.standard_zIndex-=2;
		this.top_zIndex-=2;
		this.draggable = false;
	},
	onDragStartListener : function ()
	{
		if(this.map == null)
			return false;

		if(this.veffect != null)
		{
			this.veffect = null;
			this.opt.icon.image.style.top = "0px";
		}
		this.drag_init = false;
		this.map.disableDrag();
	},
	onDragListener : function ()
	{
		if(!this.drag_init)
		{
			this.drag_cross.style.display = "block";
			this.veffect = new Effect.Move (this.opt.icon.image,{ y: -15, mode: 'absolute', duration:0.2});
			this.drag_cross.style.left = Math.ceil((this.opt.icon.image.width/2)-(8))+"px";
			this.drag_cross.style.top = (-10)+"px";
			this.hideInfoBubble();
			this.drag_init = true;
		}
		this.dragging = true;
	},
	onDragEndListener : function ()
	{
		if(this.veffect != null)
		{
			this.veffect = null;
			this.opt.icon.image.style.top = "-15px";
		}
		this.drag_cross.style.display = "none";
		this.veffect = new Effect.Move (this.opt.icon.image,{ y: 0, mode: 'absolute', duration:0.5, transition:Effect.Transitions.Bounce, afterFinish:this.afterBouncing.bind(this)});
		
		this.map.enableDrag();
		this.dragging = false;
	},
	afterBouncing : function ()
	{
		this.veffect = null;

		var left = this.map.__getOffset(this.opt.icon.image, true)+(this.opt.icon.image.width/2);

		var top = this.map.__getOffset(this.opt.icon.image, false)+(this.opt.icon.image.height);
		var coor = this.map.__getCoorByClientXY2(left,top);
		for(var i=0; i < coor.length; i++)
			coor[i] = Math.floor(coor[i]);
		var changed = false;
		this.prev_ln = this.ln;
		this.prev_la = this.la;
		if(Math.abs(this.ln-coor[0]) > 2 && Math.abs(this.la-coor[1]) > 2)
			changed = true;
		this.ln = coor[0];
		this.la = coor[1];
		for(var i=0; i < this.external_ondragend_listener.length; i++)
		{
			this.external_ondragend_listener[i](this, changed);
		}		
	},
	restorePositon : function ()
	{
		if(this.prev_ln != null && this.prev_la != null)
		{
			this.ln = this.prev_ln;
			this.la = this.prev_la;
			this.setPosition();
		}
	},
	setPosition : function ()
	{
		if(this.map == null)
			return false;
		var pos = this.map.__getClientXYByCoor(this.ln, this.la);
		var left = Math.floor(pos[0])-Math.floor(this.opt.icon.image.width/2);
		var top = Math.floor(pos[1])-(this.opt.icon.image.height);
		//alert(left+" "+top);
		if(this.first_set_pos && this.bounce > 0)
		{
			this.div.style.left = Math.floor(left)+"px";
			this.div.style.top = (Math.floor(top)-200)+"px";
			this.veffect = new Effect.Move (this.div,{ x: left, y: top, mode: 'absolute', duration:this.bounce, transition:Effect.Transitions.Bounce});
		}
		else
		{
			this.div.style.left = Math.floor(left)+"px";
			this.div.style.top = Math.floor(top)+"px";
		}
		this.first_set_pos = false;
	},
	show : function ()
	{
		this.div.style.display = "block";
	},
	hide : function ()
	{
		this.div.style.display = "none";
	},
	__export : function ()
	{
		return false;
	},
	__import : function ()
	{
		return false;
	},
	setIcon : function (icon)
	{
		return true;
	},
	addBubbleTab : function (header, content)
	{
		if(this.opt.info_bubble != null)
			this.opt.info_bubble.addTab(header, content);
	},
	addInfoBubbleWithWidthHeight : function (width, height, opt)
	{
		var tmp = new OverlayInfoWindow(width, height, null, opt);
		this.setInfoBubble(tmp);
	},
	setInfoBubble : function (info_bubble)
	{
		if(typeof(info_bubble) != "undefined" && typeof(info_bubble.setOverlay) == "function")
		{
			this.opt.info_bubble = info_bubble;
			this.opt.info_bubble.setOverlay(this);
			this.div.appendChild(this.opt.info_bubble.div);
		}
	},
	setShowTab : function (bool)
	{
		if(typeof(this.opt.info_bubble) != "undefined" && this.opt.info_bubble instanceof OverlayInfoWindow)
		{
			this.opt.info_bubble.setShowTab(bool);
		}
	},
	showInfoBubble : function ()
	{
		if(typeof(this.opt.info_bubble) != "undefined" && this.opt.info_bubble instanceof OverlayInfoWindow)
		{
			this.opt.info_bubble.show();
		}
	},
	hideInfoBubble : function ()
	{
		if(typeof(this.opt.info_bubble) != "undefined" && this.opt.info_bubble instanceof OverlayInfoWindow)
		{
			this.opt.info_bubble.hide();
		}
	},
	toggleInfoBubble : function ()
	{
		if(typeof(this.opt.info_bubble) != "undefined" && this.opt.info_bubble instanceof OverlayInfoWindow)
		{
			if(this.opt.info_bubble.div.style.display == "none")
				this.showInfoBubble();
			else
				this.hideInfoBubble();

		}
	},
	toJSON : function ()
	{
		var obj = {};
		obj.ln = this.ln;
		obj.la = this.la;
		obj.icon = this.opt.icon.image.src;
		obj.icon_width = this.opt.icon.width;
		obj.icon_height = this.opt.icon.height;
		if(this.draggable)
			obj.draggable = 1;
		else
			obj.draggable = 0;
		obj.bounce = this.bounce;
		//obj.tabs = Object.toJSON(this.opt.info_bubble);
		obj.tabs = this.opt.info_bubble;
		return Object.toJSON(obj);
	},
	getSnap : function ()
	{
		return this.toJSON();
	},
	parseSnap : function (str)
	{
		var obj = null;
		eval("obj = "+str);
		var tab_obj = null;
		eval("tab_obj = "+obj.tabs);

		this.ln = obj.ln;
		this.la = obj.la;

		this.opt.icon.image.src = obj.icon;
		if(obj.icon_width != null && obj.icon_height != null)
		{
			this.opt.icon.image.width = obj.icon_width;
			this.opt.icon.image.height = obj.icon_height;
		}
		if(tab_obj != null && tab_obj.width != null && tab_obj.height != null)
		{
			var info_bubble = new OverlayInfoWindow(tab_obj.width, tab_obj.height);
			this.setInfoBubble(info_bubble);

			var tmp = null;
			for(var i=0; i < tab_obj.tabs.length; i++)
			{
				eval("tmp = "+tab_obj.tabs[i]);
				info_bubble.addTab(tmp.header, tmp.content);
			}
		}
	}
}
/*
var MapSVGController = Class.create();
MapSVGController.prototype = {
	initialized : false,
	initialize : function ()
	{

	}
}
*/

var MapPolyline = Class.create();
MapPolyline.prototype = {
	initialized : false,
	/*initialize : function (map_drawing, opt)
	{
		if(map_drawing == null || !(map_drawing instanceof MapDrawing))
			return false;

		this.map_drawing = map_drawing;
		this.opt = opt;
		this.group = "default";

		if(opt != null && opt.group != null)
		{
			this.group = opt.group;
		}

		//this.__initializeObject();
	},*/
	initialize : function (opt)
	{
/*		if(map == null || !(map_drawing instanceof MapDrawing))
			return false;

		this.map_drawing = map_drawing;*/
		this.opt = opt;
		this.group = "default";

		if(opt != null && opt.group != null)
		{
			this.group = opt.group;
		}

		//this.__initializeObject();
	},
	__initializeObject : function (map_drawing)
	{
		if(map_drawing == null || !(map_drawing instanceof MapDrawing))
			return false;

		this.map_drawing = map_drawing;

		this.renderer = this.map_drawing.getRender();

		this.tmp_id = this.__getTmpId();

		this.obj = this.__createSVGComponentObj();
		this.obj.setStroke({r: 0, g: 0, b: 255, a: 128, w: 5 });
		this.renderer.add(this.obj);
		this.points = [];
		this.point_x = [];
		this.point_y = [];
		this.coors = [];

		this.create = this.__create.bind(this);
		this.end = this.__end.bind(this);

		this.click_listener = this.__click.bindAsEventListener(this);
		this.move_listener = this.__move.bindAsEventListener(this);
		this.dblclick_listener = this.__dblclick.bindAsEventListener(this);
		this.mouseover_listener = this.__mouseover.bindAsEventListener(this);
		this.mouseout_listener = this.__mouseout.bindAsEventListener(this);

		Event.observe(this.obj.element, "mouseover", this.mouseover_listener);
		Event.observe(this.renderer.element, "mouseout", this.mouseout_listener);

		this.is_mousedown = false;
		this.is_moved = false;
		this.current_point = null;
		this.first_point = null;
		this.mappoint = null;

		this.__create();

		this.edit_div = null;
		this.editable = false;

		if(Graphic.rendererSupported("VML"))
		{
			this.obj.element.style.position = "absolute";
		}
		else
		{
			this.renderer.element.style.position = "absolute";
			this.renderer.element.style.overflow = "visible";
		}
		this.renderer.element.style.zIndex = "54";
		this.obj.element.style.zIndex = "54";

		this.enableStrokeEdit();
		this.enableFillEdit();

		this.path_editable = false;
		//this.edit_div = null;
		this.edit_div_children = [];

		this.finished = false;

		this.current_left = 0;
		this.current_top = 0;

		this.edit_dragging = false;
		this.edit_over = false;

		this.close_set = false;

		this.initialized = true;
	},
	__getTmpId : function ()
	{
		return this.map_drawing.polyline_lib.length;
	},
	__createSVGComponentObj : function ()
	{
		return new Graphic.Polyline(this.renderer);
	},
	__endParent : function ()
	{
		this.map_drawing.endOfAddPolyline();
	},
	destory : function ()
	{
		if (Graphic.rendererSupported("VML"))
		{
			this.map_drawing.controller.map.tile_controller.div.removeChild(this.obj.element);
		}
		else
		{
			this.map_drawing.controller.map.tile_controller.div.removeChild(this.renderer.element);
		}
		if(this.mappoint != null)
			this.map_drawing.controller.map.removeMapPoint(this.mappoint);

		if(this.edit_div != null)
			this.map_drawing.controller.map.tile_controller.div.removeChild(this.edit_div);

		return true;
	},
	getCoor : function ()
	{
		return this.coors;
	},
	setCoor : function (coor_arr)
	{
		if(coor_arr == null)
			return;

	},
	__updateCoor : function ()
	{

	},
	enableStrokeEdit : function ()
	{
		this.stoke_editable = true;
	},
	disableStrokeEdit : function ()
	{
		this.stoke_editable = false;
	},
	enableFillEdit : function ()
	{
		this.fill_editable = true;
	},
	disableFillEdit : function ()
	{
		this.fill_editable = false;
	},
	enablePathEdit : function ()
	{
		this.path_editable = true;
		if(this.edit_div == null)
		{
			this.edit_div = document.createElement("DIV");
			this.edit_div.style.display = "none";
			this.edit_div.style.position = "absolute";
			this.edit_div.style.overflow = "visible";
			this.edit_div.style.left = "0px";
			this.edit_div.style.top = "0px";
			this.edit_div.style.zIndex = "2000";

			this.map_drawing.controller.map.tile_controller.div.appendChild(this.edit_div);

			for(var i=0; i < this.obj.points.length; i++)
			{
				this.edit_div_children[i] = document.createElement("DIV");
				this.edit_div_children[i].style.position = "absolute";
				this.edit_div_children[i].style.left = "0px";
				this.edit_div_children[i].style.top = "0px";
				this.edit_div_children[i].style.fontSize = "1%";
				this.edit_div_children[i].style.width = "10px";
				this.edit_div_children[i].style.display = "none";
				this.edit_div_children[i].style.height = "10px";
				this.edit_div_children[i].style.border = "1px rgb(0,0,255) solid";
				this.edit_div_children[i].style.backgroundImage = "url("+CONST_IMG_PATH+"images/nbsp.gif)";
				this.edit_div_children[i].style.zIndex = "2000";
				this.edit_div.appendChild(this.edit_div_children[i]);
			}
		}
	},
	disablePathEdit : function ()
	{
		this.path_editable = false;
		if(this.edit_div != null)
		{
			var children = this.edit_div.getElementsByTagName("DIV");
			for(var i=0; i < children.length; i++)
			{
				children[i].style.display = "none";
			}
		}
	},
	setStrokeColor : function (rv,gv,bv)
	{
		if(!this.stoke_editable)
			return false;

		if(rv < 0 || rv > 255 || gv < 0 || gv > 255 || bv < 0 || bv > 255 )
		{
			return false;
		}

		this.obj.setStroke({r: rv, g: gv, b: bv});
	},
	setStrokeWidth : function (wv)
	{
		if(!this.stoke_editable)
			return false;

		if( wv < 0 || wv > 10 )
			return false;
		this.obj.setStroke({w:wv});
	},
	setStrokeOpacity : function (ov)
	{
		if(!this.stoke_editable)
			return false;

		if(ov > 1 || ov < 0)
			return false;

		this.obj.setStroke({a:Math.ceil(ov*255)});
	},
	setStroke : function (rv,gv,bv,ov,wv)
	{
		if(!this.stoke_editable)
			return false;

		if(rv < 0 || rv > 255 || gv < 0 || gv > 255 || bv < 0 || bv > 255 )
			return false;

		if(ov == null)
			ov = 0.5;

		if(ov > 1 || ov < 0)
			return false;

		if(wv == null)
			wv = 5;

		this.obj.setStroke({r: rv, g: gv, b: bv, a:Math.ceil(ov*255), w:wv});
	},
	setFillColor : function (rv,gv,bv)
	{
		if(!this.fill_editable)
			return false;

		if(rv < 0 || rv > 255 || gv < 0 || gv > 255 || bv < 0 || bv > 255 )
		{
			return false;
		}

		this.obj.setFill({r: rv, g: gv, b: bv});
	},
	setFillOpacity : function (ov)
	{
		if(!this.fill_editable)
			return false;

		if(ov > 1 || ov < 0)
			return false;

		this.obj.setFill({a:Math.ceil(ov*255)});
	},
	setFill : function (rv,gv,bv,ov)
	{
		if(!this.fill_editable)
			return false;

		if(rv < 0 || rv > 255 || gv < 0 || gv > 255 || bv < 0 || bv > 255 )
			return false;

		if(ov > 1 || ov < 0)
			return false;

		this.obj.setFill({r: rv, g: gv, b: bv, a:Math.ceil(ov*255)});
	},
	removeFillColor : function ()
	{
		if(!this.fill_editable)
			return false;

		this.obj.setFill({});
	},
	removeFill : function ()
	{
		if(!this.fill_editable)
			return false;

		this.obj.setFill({});
	},
	__mouseover : function (evt)
	{
		if(!this.path_editable)
			return;

		if(!this.finished)
			return;

		if(this.edit_dragging)
			return;

		//this.map_drawing.controller.map.disableDrag();
		this.edit_div.style.display = "block";
		this.edit_div.xtype = "ok"

		for(var i=0; i < this.obj.points.length; i++)
		{
			//this.edit_div.childNodes[i].id = "edit_"+i;
			this.edit_div.childNodes[i].pos = i;
			//this.edit_div.childNodes[i].xtype = "ok";
			this.edit_div.childNodes[i].style.display = "block";
			var xy = this.map_drawing.controller.map.__getClientXYByCoor(this.coors[i][0], this.coors[i][1]);
			this.edit_div.childNodes[i].style.left = (xy[0]-5)+"px";
			this.edit_div.childNodes[i].style.top = (xy[1]-5)+"px";
		}
	},
	__mouseout : function (evt)
	{
		if(!this.path_editable)
			return;

		if(!this.finished)
			return;

		var e = this.map_drawing.controller.map.__getEvt(evt);

		if(e[1].tagName == "polyline" || e[1].tagName == "shape" || e[1].tagName == "polygon")
			return;

		if(this.edit_dragging)
			return;

		if(this.edit_over)
			return;

		//this.map_drawing.controller.map.enableDrag();

		this.edit_div.style.display = "none";
		for(var i=0; i < this.edit_div.childNodes.length; i++)
		{
			this.edit_div.childNodes[i].style.display = "none";
		}
	},
	__create : function ()
	{
		this.map_drawing.controller.map.disableDoubleClick();
		Event.observe(this.map_drawing.controller.map.div, "click", this.click_listener);
		Event.observe(this.map_drawing.controller.map.div, "dblclick", this.dblclick_listener);
		Event.observe(this.map_drawing.controller.map.div, "mousemove", this.move_listener);
	},
	__end : function ()
	{
		Event.stopObserving(this.map_drawing.controller.map.div, "click", this.click_listener);
		Event.stopObserving(this.map_drawing.controller.map.div, "dblclick", this.dblclick_listener);
		Event.stopObserving(this.map_drawing.controller.map.div, "mousemove", this.move_listener);
		this.map_drawing.controller.map.enableDoubleClick();
	},
	__addPoint : function (x,y)
	{
		var margin_x = this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,true);
		var margin_y = this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,false);

		var new_x = x-margin_x;
		var new_y = y-margin_y;

		this.point_x.push(new_x);
		this.point_y.push(new_y);

		this.coors.push(this.map_drawing.controller.map.__getCoorByClientXY(x,y));
		this.points.push([x,y]);
		this.obj.addPoint(new_x,new_y);

		if(this.obj.points.length > this.edit_div_children.length && this.path_editable)
		{
			var tmp = document.createElement("DIV");
			tmp.style.position = "absolute";
			tmp.style.left = "0px";
			tmp.style.top = "0px";
			tmp.style.fontSize = "1%";
			tmp.style.display = "none";
			tmp.style.width = "10px";
			tmp.style.height = "10px";
			tmp.style.border = "1px #333333 solid";
			tmp.style.backgroundImage = "url("+CONST_IMG_PATH+"images/nbsp.gif)";
			tmp.onmouseover = this.__editOver.bind(this);
			tmp.onmouseout = this.__editOut.bind(this);
			Drag2.init(tmp,null);
			tmp.onDragStart = this.__editDragStart.bind(this);
			tmp.onDragEnd = this.__editDragEnd.bind(this);
			tmp.onDrag = this.__editDrag.bindAsEventListener(this);
			this.edit_div.appendChild(tmp);
			this.edit_div_children.push(tmp);
		}
	},

	__editOver : function ()
	{
		this.edit_over = true;
	},
	__editOut : function ()
	{
		this.edit_over = false;
	},
	__editDrag : function (evt)
	{
		if(Drag2.obj.pos == null)
			return;
		var e = this.map_drawing.controller.map.__getEvt(evt);

		var pos2 = parseInt(Drag2.obj.pos);
		var pos1 = pos2-1;

		var pos3 = pos2+1;
		this.arr_pos_arr = [];
		this.pos_arr = [];
		if(pos1 >= 0)
		{
			this.pos_arr.push([this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos1],true), this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos1], false)]);
		}
		this.pos_arr.push([e[0].clientX, e[0].clientY]);
		this.arr_pos_arr.push(pos2, [e[0].clientX, e[0].clientY]);
		if(pos3 < this.obj.points.length)
		{
			this.pos_arr.push([this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos3],true), this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos3], false)]);
		}
		this.map_drawing.setDot(this.pos_arr);
	},
	__editDragStart : function (evt)
	{
		this.edit_dragging = true;
		this.map_drawing.controller.map.disableDrag();
		var e = this.map_drawing.controller.map.__getEvt(evt);
		this.init_x = e[0].clientX;
		this.init_y = e[0].clientY;
	},
	__editDragEnd : function ()
	{
		this.edit_dragging = false;
		this.map_drawing.cleanDot();
		var coor = this.map_drawing.controller.map.__getCoorByClientXY(this.arr_pos_arr[1][0], this.arr_pos_arr[1][1]);
		//$("script_area").value = coor;
		this.coors[this.arr_pos_arr[0]] = coor;
		this.onAfterZoomUpdate();
		this.map_drawing.controller.map.enableDrag();
		/*var margin_x = this.arr_pos_arr[1][0]-this.init_x;
		var margin_y = this.arr_pos_arr[1][1]-this.init_y;
		this.__setPoint(this.obj.points[this.arr_pos_arr[0]][0]+margin_x, this.obj.points[this.arr_pos_arr[0]][1]+margin_y, this.arr_pos_arr[0]);
		this.edit_dragging = false;
		//alert(this.obj.points[this.arr_pos_arr[0]]+" "+this.arr_pos_arr[1][0]+" , "+this.arr_pos_arr[1][1]+" "+this.init_x+" , "+this.init_y+" "+this.current_left+" , "+this.current_top);
		//alert();
		//this.obj._updatePath();
		this.redraw();*/
	},
	__setPoint : function (x, y, index)
	{
		var new_x = x;
		var new_y = y;

		this.point_x[index] = new_x;
		this.point_y[index] = new_y;
		this.obj.setPoint(new_x,new_y,index);
	},
	__click : function (evt)
	{
		if(this.is_moved)
		{
			this.is_moved = false;
			return;
		}

		var e = this.map_drawing.controller.map.__getEvt(evt);
		var FixedClientX = e[0].clientX+document.body.scrollLeft;
		var FixedClientY = e[0].clientY+document.body.scrollTop;

		this.last_point = this.current_point;
		this.current_point = [FixedClientX, FixedClientY];
		this.__addPoint(this.current_point[0],this.current_point[1]);
		this.redraw();
	},
	__move : function (evt)
	{
		if(this.map_drawing.dragged)
		{
			this.is_moved = true;
			return;
		}

		if(this.obj.points.length > 0)
		{
			var e = this.map_drawing.controller.map.__getEvt(evt);
			var FixedClientX = e[0].clientX+document.body.scrollLeft;
			var FixedClientY = e[0].clientY+document.body.scrollTop;

			var x = this.obj.points[this.obj.points.length-1][0]+this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,true);
			//var x = this.point_x[this.point_x.length-1]+this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,true);
			var y = this.obj.points[this.obj.points.length-1][1]+this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,false);
			//var y = this.point_y[this.point_y.length-1]+this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,false);
			this.map_drawing.setDot([[x,y], [FixedClientX, FixedClientY]]);
		}
	},

	__dblclick : function ()
	{
	try{
		if(
			this.obj.points[this.obj.points.length-1][0] == this.obj.points[this.obj.points.length-2][0]
			&&
			this.obj.points[this.obj.points.length-1][1] == this.obj.points[this.obj.points.length-2][1]
		)
		{
			this.point_x.pop();
			this.point_y.pop();
			this.coors.pop();
			this.points.pop();
			this.obj.points.pop();
			this.edit_div_children.pop();
			this.obj._updatePath();
		}

		this.map_drawing.cleanDot();
		this.__end();

		this.__endParent();

		this.redraw(true);

		this.mappoint = new MapPoint(this.coors[0][0], this.coors[0][1], {icon:new MapPointIcon("images/man.png")});
		this.mappoint.opt.group = "svg_ref";
		this.map_drawing.controller.map.addMapPoint(this.mappoint);
/*
		this.mappoint.setInfoBubble(new OverlayInfoWindow(200, 50));
		this.mappoint.opt.info_bubble.addTab("Edit", "<div style='width:200px;height:50px;'><input type='button' name='Remove' value='Remove'></div>");
		//alert(this.mappoint.opt.info_bubble.div.innerHTML);
		this.mappoint.addOnClickListener(this.__mapPointClickListener.bind(this));*/
	}catch(e){}
	},
	__mapPointClickListener : function ()
	{
		var inputs = this.mappoint.opt.info_bubble.tabs[this.mappoint.opt.info_bubble.current_tab].content_div.getElementsByTagName("input");
		//.tabs[this.current_tab].content_div.innerHTML
		//$("script_area").value = this.mappoint.opt.info_bubble.tabs[this.mappoint.opt.info_bubble.current_tab].content_div.innerHTML;
	},
	redraw : function (finish)
	{
		if(!this.finished)
		{
			if(finish != null && finish)
				this.finished = true;
			else
				this.finished = false;
		}
		var margin = 10;
		if(is_ie)
			margin=0;

		var min_x = this.point_x.min()-margin;
		var max_x = this.point_x.max()+margin;
		var min_y = this.point_y.min()-margin;
		var max_y = this.point_y.max()+margin;

	    if (Graphic.rendererSupported("VML"))
		{
			this.obj.element.style.width = (max_x-min_x)+"px";
			this.obj.element.style.height = (max_y-min_y)+"px";
			this.obj.element.setAttribute("coordsize", ((max_x-min_x) + ", " + (max_y-min_y)));
	    	this.obj.element.setAttribute("coordorigin", "0,0");
		}
	    else
		{
			this.renderer.element.setAttribute("width", (max_x-min_x)+"px");
			this.renderer.element.setAttribute("height", (max_y-min_y)+"px");
			this.renderer.element.setAttribute("viewBox", (min_x)+" "+min_y+" "+(max_x-min_x)+" "+(max_y-min_y));
		}

		if(Graphic.rendererSupported("VML"))
		{
			if(finish != null && finish)
			{
				for(var i=0; i < this.obj.points.length; i++)
				{
					this.obj.points[i][0] -= min_x;
					this.obj.points[i][1] -= min_y;
				}
				this.obj._updatePath();

				this.obj.element.style.left = (min_x)+"px";
				this.obj.element.style.top = (min_y)+"px";
			}
			else
			{
				this.obj.element.style.left = (0)+"px";
				this.obj.element.style.top = (0)+"px";
			}
		}
		else
		{
			if(finish != null && finish)
			{
				this.renderer.element.style.left = (min_x)+"px";
				this.renderer.element.style.top = (min_y)+"px";
				for(var i=0; i < this.obj.points.length; i++)
				{
					this.obj.points[i][0] -= min_x;
					this.obj.points[i][1] -= min_y;
				}
				this.obj._updatePath();
				this.renderer.element.setAttribute("viewBox", "0 0 "+(max_x-min_x)+" "+(max_y-min_y));
			}
			else
			{

				this.renderer.element.style.left = (min_x)+"px";
				this.renderer.element.style.top = (min_y)+"px";

				if(agt.indexOf("safari") != -1)
				{
					this.map_drawing.controller.map.moveToByXYs(1,1);
					this.map_drawing.controller.map.moveToByXYs(-1,-1);
					this.renderer.element.setAttribute("width", (max_x-min_x+min_x)+"px");
					this.renderer.element.setAttribute("height", (max_y-min_y+min_y)+"px");
					this.renderer.element.setAttribute("viewBox", "0 0 "+(max_x-min_x)+" "+(max_y-min_y));
					this.renderer.element.style.left = (min_x-this.renderer.element.offsetLeft)+"px";
					this.renderer.element.style.top = (min_y-this.renderer.element.offsetTop)+"px";
				}
			}
		}
		this.current_left = min_x;
		this.current_top = min_y;
		//if(agt.indexOf("safari") != -1 && (finish == null || !finish) )
		//{
			/*this.renderer.element.style.border = "2px #000000 solid";
			this.obj.element.style.border =  "2px #000000 solid";
			if(this.obj.points.length%2 == 0)
				this.map_drawing.controller.map.moveToByXYs(1,1);
			else
				this.map_drawing.controller.map.moveToByXYs(-1,-1);

			this.renderer.element.setAttribute("width", (max_x-min_x+min_x)+"px");
			this.renderer.element.setAttribute("height", (max_y-min_y+min_y)+"px");
			this.renderer.element.setAttribute("viewBox", (min_x-this.renderer.element.offsetLeft)+" "+(min_y-this.renderer.element.offsetTop)+" "+(max_x-min_x+min_x)+" "+(max_y-min_y+min_y));
			this.renderer.element.style.left = (min_x-this.renderer.element.offsetLeft)+"px";
			this.renderer.element.style.top = (min_y-this.renderer.element.offsetTop)+"px";
			//this.renderer.element.setAttribute("viewBox", (min_x)+" "+min_y+" "+(max_x-min_x)+" "+(max_y-min_y));
			//$("script_area").innerHTML = "Hello World2 - "+(max_x+" "+max_y+" "+(max_x-min_x)+" "+(max_y-min_y))+"\n";
			$("script_area").innerHTML = (min_x-this.renderer.element.offsetLeft)+" "+min_x+" "+this.renderer.element.offsetLeft+" "+min_y+" "+this.renderer.element.offsetTop+" -> "+(min_x-this.renderer.element.offsetLeft)+" "+(min_y-this.renderer.element.offsetTop)+" "+(max_x-min_x)+" "+(max_y-min_y);
			*/
		//}
		//else
		//	$("script_area").innerHTML = "stop";

		this.renderer.draw();
	},
	onAfterZoomUpdate : function ()
	{

		this.mappoint.ln = this.coors[0][0];
		this.mappoint.la = this.coors[0][1];
		this.mappoint.setPosition();
		if(Graphic.rendererSupported("VML"))
		{
			var min_ln = null;
			var min_la = null;
			var max_ln = null;
			var max_la = null;
			for(var i=0; i < this.coors.length; i++)
			{
				if(min_ln == null || this.coors[i][0] < min_ln)
					min_ln = this.coors[i][0];
				if(min_la == null || this.coors[i][1] > min_la)
					min_la = this.coors[i][1];
				if(max_ln == null || this.coors[i][0] > max_ln)
					max_ln = this.coors[i][0];
				if(max_la == null || this.coors[i][1] < max_la)
					max_la = this.coors[i][1];
			}

			var min_xy = this.map_drawing.controller.map.__getClientXYByCoor(min_ln, min_la);

			var max_xy = this.map_drawing.controller.map.__getClientXYByCoor(max_ln, max_la);


			this.obj.element.style.left = (min_xy[0])+"px";
			this.obj.element.style.top = (min_xy[1])+"px";
			this.obj.element.style.width = (max_xy[0]-min_xy[0])+"px";
			this.obj.element.style.height = (max_xy[1]-min_xy[1])+"px";
			this.obj.element.setAttribute("coordsize", ((max_xy[0]-min_xy[0]) + ", " + (max_xy[1]-min_xy[1])));
	    	//this.obj.element.setAttribute("coordorigin", "0,0");

			for(var i=0; i < this.coors.length; i++)
			{
				var ln_rate = (this.coors[i][0]-min_ln)/(max_ln-min_ln);
				var la_rate = (min_la-this.coors[i][1])/(min_la-max_la);
				this.obj.points[i][0] = Math.round((max_xy[0]-min_xy[0])*ln_rate);
				this.obj.points[i][1] = Math.round((max_xy[1]-min_xy[1])*la_rate);
			}
			this.obj._updatePath();
		}
		else
		{
			var min_ln = null;
			var min_la = null;
			var max_ln = null;
			var max_la = null;
			for(var i=0; i < this.coors.length; i++)
			{
				if(min_ln == null || this.coors[i][0] < min_ln)
					min_ln = this.coors[i][0];
				if(min_la == null || this.coors[i][1] > min_la)
					min_la = this.coors[i][1];
				if(max_ln == null || this.coors[i][0] > max_ln)
					max_ln = this.coors[i][0];
				if(max_la == null || this.coors[i][1] < max_la)
					max_la = this.coors[i][1];
			}

			var min_xy = this.map_drawing.controller.map.__getClientXYByCoor(min_ln, min_la);

			var max_xy = this.map_drawing.controller.map.__getClientXYByCoor(max_ln, max_la);
			this.renderer.element.style.left = (min_xy[0]-10)+"px";
			this.renderer.element.style.top = (min_xy[1]-10)+"px";

			this.renderer.element.setAttribute("width", (max_xy[0]-min_xy[0]+20)+"px");
			this.renderer.element.setAttribute("height", (max_xy[1]-min_xy[1]+20)+"px");
			this.renderer.element.setAttribute("viewBox", "0 0 "+(max_xy[0]-min_xy[0]+20)+" "+(max_xy[1]-min_xy[1]+20));
			for(var i=0; i < this.coors.length; i++)
			{
				var ln_rate = (this.coors[i][0]-min_ln)/(max_ln-min_ln);
				var la_rate = (min_la-this.coors[i][1])/(min_la-max_la);

				this.obj.points[i][0] = Math.ceil((max_xy[0]-min_xy[0])*ln_rate)+10;
				this.obj.points[i][1] = Math.ceil((max_xy[1]-min_xy[1])*la_rate)+10;
			}
			this.obj._updatePath();
		}
		//this.map_drawing.cleanDot();
		if(this.edit_div != null)
			this.edit_div.style.display = "none";
	},
	toJSON : function ()
	{
		var obj = {};
		obj.coor = this.coors;
		obj.mappoint = this.mappoint;
		return Object.toJSON(obj);
	},
	getSnap : function ()
	{
		return this.toJSON();
	},
	parseSnap : function (str)
	{
		if(str == null || str == "")
			return false;

		var obj = null;
		eval("obj = "+str);
		if(obj.coor == null)
			return;
//		this.coors = obj.coor;
		var margin_x = this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,true);
		var margin_y = this.map_drawing.controller.map.__getOffset(this.map_drawing.controller.div,false);
		for(var i=0; i<obj.coor.length; i++)
		{
			//alert(obj.coor[i]);
			var xy = this.map_drawing.controller.map.__getClientXYByCoor(obj.coor[i][0], obj.coor[i][1]);
			this.__addPoint(xy[0]+margin_x, xy[1]+margin_y);
			this.redraw();
		}
		//this.redraw(true);
		/*alert("a");
		this.redraw(true);
		alert("b");*/
		this.__dblclick();
/*
			var min_ln = null;
			var min_la = null;
			var max_ln = null;
			var max_la = null;
			for(var i=0; i < this.coors.length; i++)
			{
				if(min_ln == null || this.coors[i][0] < min_ln)
					min_ln = this.coors[i][0];
				if(min_la == null || this.coors[i][1] > min_la)
					min_la = this.coors[i][1];
				if(max_ln == null || this.coors[i][0] > max_ln)
					max_ln = this.coors[i][0];
				if(max_la == null || this.coors[i][1] < max_la)
					max_la = this.coors[i][1];
			}

			var min_xy = this.map_drawing.controller.map.__getClientXYByCoor(min_ln, min_la);

			var max_xy = this.map_drawing.controller.map.__getClientXYByCoor(max_ln, max_la);
			this.renderer.element.style.left = (min_xy[0]-10)+"px";
			this.renderer.element.style.top = (min_xy[1]-10)+"px";*/
		//this.onAfterZoomUpdate();
		/*
		if(obj.mappoint != null)
		{
			this.mappoint = new MapPoint(0,0);
			this.mappoint.parseSnap(obj.mappoint);
			this.mappoint.opt.group = "svg_ref";
			this.map_drawing.controller.map.addMapPoint(this.mappoint);
		}
		*/
	}
}

var MapPolygon = Class.create();
Object.extend(Object.extend(MapPolygon.prototype, MapPolyline.prototype), {
	__createSVGComponentObj : function ()
	{
		return new Graphic.Polygon(this.renderer);
	},
	__getTmpId : function ()
	{
		return this.map_drawing.polygon_lib.length;
	},
	__endParent : function ()
	{
		this.map_drawing.endOfAddPolygon();
	},
	__editDrag : function (evt)
	{
		try{
		if(Drag2.obj.pos == null)
			return;
		var e = this.map_drawing.controller.map.__getEvt(evt);

		var pos2 = parseInt(Drag2.obj.pos);
		var pos1 = pos2-1;

		var pos3 = pos2+1;
		this.arr_pos_arr = [];
		this.pos_arr = [];
		if(pos1 >= 0)
		{
			this.pos_arr.push([this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos1],true), this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos1], false)]);
		}
		else
		{
			this.pos_arr.push([this.map_drawing.controller.map.__getOffset(this.edit_div_children[this.edit_div_children.length-1],true), this.map_drawing.controller.map.__getOffset(this.edit_div_children[this.edit_div_children.length-1], false)]);
		}
		this.pos_arr.push([e[0].clientX, e[0].clientY]);
		this.arr_pos_arr.push(pos2, [e[0].clientX, e[0].clientY]);
		if(pos3 < this.obj.points.length)
		{
			this.pos_arr.push([this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos3],true), this.map_drawing.controller.map.__getOffset(this.edit_div_children[pos3], false)]);
		}
		else
		{
			this.pos_arr.push([this.map_drawing.controller.map.__getOffset(this.edit_div_children[0],true), this.map_drawing.controller.map.__getOffset(this.edit_div_children[0], false)]);
		}
		this.map_drawing.setDot(this.pos_arr);
		}catch(e){}
	}
});
/*
var MapPolygon = MapPolyline.extend({
	__createSVGComponentObj : function ()
	{
		return new Graphic.Polygon(this.renderer);
	}
});
*/
var MapDrawing = Class.create();
MapDrawing.prototype = {
	initialized : false,
	initialize : function (controller)
	{
		if(controller == null || !(controller instanceof OverlayController))
			return false;

		this.controller = controller;

		this.current_working_obj = null;

		this.polyline_lib = [];
		this.polygon_lib = [];
		this.drawing_point_lib = [];

		this.dot_div = document.createElement("DIV");
		this.controller.div.appendChild(this.dot_div);
		this.dot_div.style.position = "absolute";
		this.dot_div.style.display = "block";

		this.dragged = false;
		this.controller.map.addPolyline = this.addPolyline.bind(this);
		//this.controller.map.addPolyline2 = this.addPolyline2.bind(this);
		this.controller.map.removePolyline = this.removePolyline.bind(this);

		this.controller.map.addPolygon = this.addPolygon.bind(this);
		this.controller.map.removePolygon = this.removePolygon.bind(this);

		this.controller.map.addOnDragStartListener(this.dragStartListener.bind(this));
		this.controller.map.addOnDragEndListener(this.dragEndListener.bind(this));
		this.controller.map.addOnZoomListener(this.zoomListener.bind(this));
		this.initialized = true;
	},
	zoomListener : function ()
	{
		for(var i=0; i < this.polyline_lib.length; i++)
		{
			this.polyline_lib[i].onAfterZoomUpdate();
		}
		for(var i=0; i < this.polygon_lib.length; i++)
		{
			this.polygon_lib[i].onAfterZoomUpdate();
		}
	},
	dragStartListener : function ()
	{
		this.cleanDot();
		this.dragged = true;
	},
	dragEndListener : function ()
	{
		this.dragged = false;
	},
	getRender : function ()
	{
		var tmp = null;
	    if (Graphic.rendererSupported("VML"))
			tmp = new Graphic.VMLRenderer(this.controller.map.tile_controller.div);
	    else if (Graphic.rendererSupported("SVG"))
	      	tmp = new Graphic.SVGRenderer(this.controller.map.tile_controller.div);
	    else if (Graphic.rendererSupported("Canvas"))
			tmp = new Graphic.CanvasRenderer(this.controller.map.tile_controller.div);

		return tmp;
	},
	addDrawingPoint : function ()
	{

	},
	addPolyline : function (polyline)
	{
		if(polyline == null || !(polyline instanceof MapPolyline) || typeof(polyline.__initializeObject) != "function")
			return false;
		polyline.__initializeObject(this);
		this.polyline_lib.push(polyline);
		this.current_working_obj = this.polyline_lib[this.polyline_lib.length-1];
		return this.polyline_lib[this.polyline_lib.length-1];
	},
	/*
	addPolyline : function ()
	{
		if(this.current_working_obj != null)
			return;

		var tmp = new MapPolyline(this);
		this.polyline_lib.push(tmp);
		this.current_working_obj = this.polyline_lib[this.polyline_lib.length-1];
		return this.polyline_lib[this.polyline_lib.length-1];
	},
	*/
	endOfAddPolyline : function ()
	{
		this.current_working_obj = null;
	},
	removePolylineByGroup : function (name)
	{

	},
	removePolyline : function (polyline)
	{
		if(polyline.tmp_id == null || polyline.tmp_id > this.polyline_lib.length)
			return false;

		this.polyline_lib[polyline.tmp_id].destory();
		this.polyline_lib.splice(polyline.tmp_id, 1);
	},
	/*addPolygon : function ()
	{
		if(this.current_working_obj != null)
			return;

		var tmp = new MapPolygon(this);
		this.polygon_lib.push(tmp);
		this.current_working_obj = this.polygon_lib[this.polygon_lib.length-1];
		return this.polygon_lib[this.polygon_lib.length-1];
	},*/
	addPolygon : function (polygon)
	{
		if(polygon == null || !(polygon instanceof MapPolygon) || typeof(polygon.__initializeObject) != "function")
			return false;
		polygon.__initializeObject(this);
		this.polygon_lib.push(polygon);
		this.current_working_obj = this.polygon_lib[this.polygon_lib.length-1];
		return this.polygon_lib[this.polygon_lib.length-1];
	},
	endOfAddPolygon : function ()
	{
		this.current_working_obj = null;
	},
	removePolygon : function (polygon)
	{
		if(polygon.tmp_id == null || polygon.tmp_id > this.polygon_lib.length)
			return false;

		this.polygon_lib[polygon.tmp_id].destory();
		this.polygon_lib.splice(polygon.tmp_id, 1);
	},
	/*setDot : function (x1, y1, x2, y2)
	{
		var l = Math.sqrt((Math.pow(x2-x1,2)+Math.pow(y2-y1,2)));
		var n = ((l/5)/2);
		var d = this.dot_div.getElementsByTagName("DIV");
		if(d.length < n)
		{
			for(var i=0; i < (b-d.length); i++)
			{
				var e = document.createElement("DIV");
				e.style.position = "absolute";
				e.style.width = "5px";
				e.style.height = "5px";
				e.style.fontSize = "1%";
				e.style.backgroundColor = "rgb(0,0,255)";
				this.dot_div.appendChild(e);
			}
		}

		var d = this.dot_div.getElementsByTagName("DIV");
		var angle = Math.atan(Math.abs(y2-y1)/Math.abs(x2-x1));
		var pos = 0;
		for(var i=0; i < n; i++)
		{
			pos += 5;
			var left_dist = (Math.cos(angle)*pos)+x1;
			var top_dist = (Math.sin(angle)*pos)+y1;

			d[i].style.left = left_dist+"px";
			d[i].style.top = top_dist+"px";
			d[i].style.display = "block";
		}
		for(var j=i; j < d.length; j++)
		{
			d[j].style.display = "none";
		}
	},*/
	setDot : function (points)
	{
		if(points == null)
			return;

		var points_added = 0;
		var dots = this.dot_div.getElementsByTagName("DIV");
		for(var i=0; i < (points.length-1); i++)
		{

			var length = Math.sqrt((Math.pow((points[i+1][0]-points[i][0]),2)+Math.pow((points[i+1][1]-points[i][1]),2)));
			var num_of_dot = ((length/5)/4);
			var with_end_dot = false;
			if(i == (points.length-2))
			{
				with_end_dot = true;
				num_of_dot++;
			}
			var angle = Math.atan(Math.abs(points[i+1][1]-points[i][1])/Math.abs(points[i+1][0]-points[i][0]));
			var angle2 = 1;
			if(points[i+1][0] < points[i][0])
			{
				//angle = angle*(-1);
				angle2 = -1;
			}
			if(points[i+1][1] < points[i][1])
			{
				angle = angle*(-1);
			}

			var pos = 0;
			for(var x=0; x < num_of_dot; x++)
			{
				if(points_added >= (dots.length-1))
				{
					var e = document.createElement("DIV");
					e.style.position = "absolute";
					e.style.width = "5px";
					e.style.height = "5px";
					e.style.fontSize = "1%";
					e.style.backgroundColor = "#333333";
					this.dot_div.appendChild(e);
					dots = this.dot_div.getElementsByTagName("DIV");
				}
				if(with_end_dot && x == 0)
				{
					dots[points_added].style.left = (points[i+1][0]-this.controller.map.__getOffset(this.dot_div,true))+"px";
					dots[points_added].style.top = (points[i+1][1]-this.controller.map.__getOffset(this.dot_div,false))+"px";
					dots[points_added].style.display = "block";
				}
				else
				{
					var left_dist = ((Math.cos(angle)*pos*angle2)+points[i][0])-this.controller.map.__getOffset(this.dot_div,true);
					var top_dist = ((Math.sin(angle)*pos)+points[i][1])-this.controller.map.__getOffset(this.dot_div,false);
					/*if(is_ie)
					{
						left_dist-=5;
						top_dist-=5;
					}*/
					dots[points_added].style.left = (left_dist)+"px";
					dots[points_added].style.top = (top_dist)+"px";
					dots[points_added].style.display = "block";
					pos += 20;
				}
				points_added++;
			}
		}

		for(var i=points_added; i < dots.length; i++)
		{
			dots[i].style.display = "none";
		}
	},
	cleanDot : function ()
	{
		var dots = this.dot_div.getElementsByTagName("DIV");
		for(var i=0; i < dots.length; i++)
		{
			dots[i].style.display = "none";
		}
	}
}
var OverlayController = Class.create();
OverlayController.prototype = {
	initialized : false,

	map_point_set : null,
	map_point_set_count : 0,
	map_point_set_arr : null,
	map_point_set_timer : null,
	add_map_point_set_timer : null,
	map_point_message_panel : null,

	polyline_set : null,
	polyline_set_count : 0,
	polyline_set_arr : null,
	polyline_set_timer : null,

	polygon_set : null,
	polygon_set_count : 0,
	polygon_set_arr : null,
	polygon_set_timer : null,

	initialize : function (map)
	{
		if(map == null || this.initialized)
			return false;

		this.map = map;

		this.div = document.createElement("DIV");
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";
		this.div.style.zIndex = "56";
		this.map.tile_controller.div.appendChild(this.div);
		/*
		*	Function Mapping for Map controller.
		*/
		this.map.addMapPoint = this.addMapPoint.bind(this);
		this.map.removeMapPoint = this.removeMapPoint.bind(this);
		this.map.addMapPointSet = this.addMapPointSet.bind(this);
		this.map.removeAllMapPoint = this.removeAllMapPoint.bind(this);
		this.map.removeMapPointByGroupName = this.removeMapPointByGroupName.bind(this);

		this.map.addPolyline = this.addPolyline.bind(this);
		this.map.addPolylineSet = this.addPolylineSet.bind(this);

		this.map.addPolygon = this.addPolygon.bind(this);
		this.map.addPolygonSet = this.addPolygonSet.bind(this);

		this.map_point_unique_id = 0;
		this.map_point_set = [];
		this.polyline_unique_id = 0;
		this.polyline_set = [];
		this.polygon_unique_id = 0;
		this.polygon_set = [];

		this.map.addOnZoomListener(this.onZoomChangeListener.bind(this));

		this.map_point_message_panel = document.createElement("DIV");
		this.map_point_message_panel.style.display = "none";
		this.map_point_message_panel.className = "map_msg_panel";
		this.map.div.appendChild(this.map_point_message_panel);

		this.drawing = new MapDrawing(this);
		this.map_point_id = 0;
	},
	getMapPointByUniqueId : function (id)
	{
		var left = -1;
		var right = this.map_point_set.length;
		var mid;

		while(right - left > 1)
		{
			mid = (left + right) >>> 1;
			if(this.map_point_set[mid].unique_id < id)
				left = mid;
			else
				right = mid;
		}

		if(this.map_point_set[right].unique_id != id)
			return -(right + 1);

		return this.map_point_set[right];
	},
	addMapPoint : function(obj)
	{
		if(obj instanceof MapPoint)
		{
			if(typeof(obj.group) == "undefined" || obj.group == null)
				obj.group = "default";

			obj.map = this.map;
			obj.unique_id = this.map_point_unique_id;
			this.map_point_unique_id++;
			this.div.appendChild(obj.div);
			obj.setPosition();
			obj.show();
			obj.map_point_id = this.map_point_id;
			this.map_point_id++;
			this.map_point_set.push(obj);
		}
	},
	removeAllMapPoint : function ()
	{
		for( var i=0; i < this.map_point_set.length; i++)
		{
			this.div.removeChild(this.map_point_set[i].div);
		}
		this.map_point_set = [];
	},
	removeMapPointByGroupName : function (name)
	{
		var new_arr = [];
		for( var i=0; i < this.map_point_set.length; i++)
		{
			if(this.map_point_set[i].opt.group != null && this.map_point_set[i].opt.group == name)
			{
				this.div.removeChild(this.map_point_set[i].div);
			}
			else
			{
				new_arr.push(this.map_point_set[i]);
			}
		}

		this.map_point_set = [];
		for(var i=0; i < new_arr.length; i++)
		{
			this.map_point_set.push(new_arr[i]);
		}
	},
	removeMapPoint : function (obj)
	{
		var new_arr = [];
		for( var i=0; i < this.map_point_set.length; i++)
		{
			if(obj == this.map_point_set[i])
			{
				this.div.removeChild(obj.div);
			}
			else
			{
				new_arr.push(this.map_point_set[i]);
			}
		}

		this.map_point_set = [];
		for(var i=0; i < new_arr.length; i++)
		{
			this.map_point_set.push(new_arr[i]);
		}
	},
	addPolyline : function(obj)
	{

	},
	removePolyline : function (obj)
	{

	},
	addPolygon : function (obj)
	{

	},
	removePolygon : function (obj)
	{

	},
	addMapPointSetAction : function ()
	{

	},
	addMapPointSet : function(obj_arr)
	{
		if(this.map_point_set_arr == null)
		{
			this.map_point_set_arr = obj_arr;
			this.map_point_set_count = 0;
			this.map_point_message_panel.innerHTML = "Adding Map Point <span id='add_map_point_counter"+this.map.map_id+"'>000</span> / "+this.map_point_set_arr.length;;
			this.map_point_message_panel.style.display = "block";
			this.map_point_message_panel.style.zIndex = "1000";
			this.map_point_message_panel.style.position = "absolute";
			this.map_point_message_panel.style.left = "0px";
			this.map_point_message_panel.style.top = "0px";

			this.map_point_message_panel.style.left = ((this.map.div.offsetWidth/2)-(this.map_point_message_panel.offsetWidth/2))+"px";

			this.map_point_message_panel_counter = $('add_map_point_counter'+this.map.map_id);
			this.add_map_point_set_timer = new PeriodicalExecuter(this.addMapPointSetAction.bind(this), 0.001);
			return true;
		}
		else
		{
			return false;
		}
	},
	addMapPointSetAction : function ()
	{

		this.addMapPoint(this.map_point_set_arr[this.map_point_set_count]);
		this.map_point_set_count++;

		this.map_point_message_panel_counter.innerHTML = this.map_point_set_count;
		if(this.map_point_set_count > this.map_point_set_arr.length-1)
		{
			this.cancelMapPointSetAction()
		}
	},
	cancelMapPointSetAction : function ()
	{
		this.map_point_message_panel.style.display = "none";
		this.add_map_point_set_timer.stop();
		this.add_map_point_set_timer = null;
		this.map_point_set_arr = null;
	},
	addPolylineSet : function(obj_arr)
	{

	},
	addPolygonSet : function (obj_arr)
	{

	},
	onZoomChangeTimerAction : function ()
	{
		this.map_point_set[this.map_point_set_count].setPosition();
		this.map_point_set[this.map_point_set_count].show();
		this.map_point_set_count++;

		if(this.map_point_set_count > this.map_point_set.length-1)
		{
			this.map_point_set_timer.stop();
			this.map_point_set_timer = null;
		}
	},
	onZoomChangeListener : function ()
	{
		this.div.style.display = "none";
		for( var i=0; i < this.map_point_set.length; i++)
		{
			this.map_point_set[i].setPosition();
		}
		this.div.style.display = "";
	},
	toJSON : function ()
	{
		var obj = {};
		obj.points = [];
		for( var i=0; i < this.map_point_set.length; i++)
		{
			obj.points.push(this.map_point_set[i]);
		}

		return Object.toJSON(obj);
	},
	getSnap : function ()
	{
		return this.toJSON();
	},
	setSnap : function ()
	{

	}
}

var MapGridHandler = Class.create();
MapGridHandler.prototype = {
	response_function : null,
	initialized : false,
	initialized_layout : false,
	initialize : function (map)
	{
		if(typeof(map) == "undefined" || map == null)
			return false;

		this.map = map;
		this.div = document.createElement("DIV");
		this.div.style.width = this.map.div.offsetWidth+"px";
		this.div.style.height = this.map.div.offsetHeight+"px";
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";
		this.div.style.display = "none";
		this.div.style.zIndex = "1000";
		this.map.moving_panel.appendChild(this.div);

		this.initialized = true;
	},
	setResponseFunction : function(func)
	{
		if(typeof(func) != "function" || func == null || !this.initialized)
			return false;

		this.response_function = func;
		this.map.addOnDragEndListener(this.response_function);
	},
	setGridLayout : function (x, y)
	{
		if(x == null || isNaN(x) || y == null || isNaN(y) || !this.initialized)
			return false;

		while(this.div.childNodes.length > 0)
			this.div.removeChild(this.div.childNodes[0]);

		this.num_of_x = x;
		this.num_of_y = y;

		this.num_of_px_per_xtile = Math.ceil(this.map.div.offsetWidth/this.num_of_x);
		this.num_of_px_per_ytile = Math.ceil(this.map.div.offsetHeight/this.num_of_y);
		var tmp = null;
		for(var y=0; y < this.num_of_y; y++)
		{
			var y_px = y*this.num_of_px_per_ytile;
			for(var x=0; x < this.num_of_x; x++)
			{
				var x_px = x*this.num_of_px_per_xtile;
				tmp = document.createElement("DIV");
				tmp.id = "__map_grid_layer_"+x+"_"+y;
				tmp.style.position = "absolute";
				tmp.style.left = (x_px)+"px";
				tmp.style.top = (y_px)+"px";
				tmp.style.width = this.num_of_px_per_xtile+"px";
				tmp.style.height = this.num_of_px_per_ytile+"px";
				this.div.appendChild(tmp);
			}
		}
		this.initialized_layout = true;
	},
	show : function ()
	{
		this.div.style.display = "";
	},
	hide : function ()
	{
		this.div.style.display = "none";
	}
}

var TileLayer = Class.create();
TileLayer.prototype = {
	name : "",
	tiles : [],
	opt : null,
	tile_lib : CONST_MAP_TILE_LIB,
	controller : null,
	initialized : false,
	initialized_tile : false,
	opacity : 1,
	default_layer : null,
	initialize : function (controller)
	{
		if(controller == null)
			return false;

		this.controller = controller;
		this.opt = {};
		this.div = document.createElement("DIV");
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";

		this.controller.div.appendChild(this.div);

		this.initialized = true;
	},
	initializeTiles : function ()
	{
		if(!this.initialized)
		{
			return;
		}

		var clncla_arr = this.controller.map.__getTilePosByLnLa();

		var current_x = Math.floor(clncla_arr[0])-Math.floor(this.controller.map.num_of_tile_x/2);
		var current_y = Math.floor(clncla_arr[1])-Math.floor(this.controller.map.num_of_tile_y/2);

		var y_tile_pos = current_y;
		var x_tile_pos = current_x;

		var margin_x_px = (clncla_arr[0]-Math.floor(clncla_arr[0]))*this.controller.map.tile_width;
		var margin_y_px = (clncla_arr[1]-Math.floor(clncla_arr[1]))*this.controller.map.tile_height;

		var margin_left = this.controller.map.__getOffset(this.controller.map.container,true)-this.controller.map.__getOffset(this.div,true);
		var margin_top = this.controller.map.__getOffset(this.controller.map.container,false)-this.controller.map.__getOffset(this.div,false);

		var center_x_px = parseInt((this.controller.map.div.offsetWidth/2)-margin_x_px-this.controller.map.__getOffset(this.controller.div,true));
		var center_x_px = parseInt((this.controller.map.div.offsetWidth/2)-margin_x_px+margin_left);
		var center_y_px = parseInt((this.controller.map.div.offsetHeight/2)-margin_y_px-this.controller.map.__getOffset(this.controller.div,false));
		var center_y_px = parseInt((this.controller.map.div.offsetHeight/2)-margin_y_px+margin_top);

		var l = 0;
		var t = 0;

		var map_lib_pos = 0;

		this.tiles = [];

		while(this.div.childNodes.length > 0)
		{
			this.div.removeChild(this.div.childNodes[0]);
		}

		for(var x=0; x<this.controller.map.num_of_tile_x; x++)
		{
			this.tiles[x] = [];
			y_tile_pos = current_y;
			for(var y=0; y<this.controller.map.num_of_tile_y; y++)
			{
				map_lib_pos = Math.round((this.tile_lib.length-1)*Math.random());
				this.tiles[x][y] = new Tile(this.controller.map, this.tile_lib[map_lib_pos], x_tile_pos, y_tile_pos, this.controller.map.current_zoom_level, this.controller.map.tile_width, this.controller.map.tile_height, this.opt);
				this.div.appendChild(this.tiles[x][y].image);
				if(this.opacity != 1)
				{
					Element.setOpacity( $(this.tiles[x][y].image), this.opacity );
				}
				l = (this.controller.map.tile_width*(x_tile_pos-Math.floor(clncla_arr[0])))+center_x_px;
				t = (this.controller.map.tile_height*(y_tile_pos-Math.floor(clncla_arr[1])))+center_y_px;
				this.tiles[x][y].setLeftTop(l, t);
				y_tile_pos++;
			}
			x_tile_pos++;
		}
		this.tile_initialized = true;
	},
	updateTiles : function ()
	{
		var clncla_arr = this.controller.map.__getTilePosByLnLa();

		var current_x = Math.floor(clncla_arr[0])-Math.floor(this.controller.map.num_of_tile_x/2);
		var current_y = Math.floor(clncla_arr[1])-Math.floor(this.controller.map.num_of_tile_y/2);

		var y_tile_pos = current_y;
		var x_tile_pos = current_x;

		var margin_x_px = (clncla_arr[0]-Math.floor(clncla_arr[0]))*this.controller.map.tile_width;
		var margin_y_px = (clncla_arr[1]-Math.floor(clncla_arr[1]))*this.controller.map.tile_height;

		var margin_left = this.controller.map.__getOffset(this.controller.map.container,true)-this.controller.map.__getOffset(this.div,true);
		var margin_top = this.controller.map.__getOffset(this.controller.map.container,false)-this.controller.map.__getOffset(this.div,false);

		var center_x_px = parseInt((this.controller.map.div.offsetWidth/2)-margin_x_px-this.controller.map.__getOffset(this.controller.div,true));
		var center_x_px = parseInt((this.controller.map.div.offsetWidth/2)-margin_x_px+margin_left);
		var center_y_px = parseInt((this.controller.map.div.offsetHeight/2)-margin_y_px-this.controller.map.__getOffset(this.controller.div,false));
		var center_y_px = parseInt((this.controller.map.div.offsetHeight/2)-margin_y_px+margin_top);

		var l = 0;
		var t = 0;

		var map_lib_pos = 0;

		for(var x=0; x<this.controller.map.num_of_tile_x; x++)
		{
			y_tile_pos = current_y;
			for(var y=0; y<this.controller.map.num_of_tile_y; y++)
			{
				this.tiles[x][y].resetProperties(this.tiles[x][y].src, x_tile_pos, y_tile_pos, this.controller.map.current_zoom_level, this.controller.map.tile_width, this.controller.map.tile_height, this.opt);
				l = (this.controller.map.tile_width*(x_tile_pos-Math.floor(clncla_arr[0])))+center_x_px;
				t = (this.controller.map.tile_height*(y_tile_pos-Math.floor(clncla_arr[1])))+center_y_px;
				this.tiles[x][y].setLeftTop(l, t);
				if(this.opacity != 1 && Element.getOpacity($(this.tiles[x][y].image)) != this.opacity)
				{
					Element.setOpacity( $(this.tiles[x][y].image), this.opacity );
				}
				y_tile_pos++;
			}
			x_tile_pos++;
		}
	},
	setName : function (val)
	{
		this.name = val;
	},
	setZIndex : function (val)
	{
		this.div.style.zIndex = val;
		for(var x=0; x<this.controller.map.num_of_tile_x; x++)
		{
			for(var y=0; y<this.controller.map.num_of_tile_y; y++)
			{
				this.tiles[x][y].image.style.zIndex = val;
			}
		}
	},
	setOpacity : function (val)
	{
		this.opacity = val;
		for(var x=0; x<this.controller.map.num_of_tile_x; x++)
		{
			for(var y=0; y<this.controller.map.num_of_tile_y; y++)
			{
				Element.setOpacity( $(this.tiles[x][y].image), val );
			}
		}
	}
}
var TileLayerController = Class.create();
TileLayerController.prototype = {
	div : null,
	layers : null,
	zoom_layer : null,
	initialized : false,
	default_tile_layer_added : false,
	zoom_tile_layer_added : false,
	initialize : function (map)
	{
		if(map == null)
			return false;

		this.with_smooth_zoom = false;
		this.layers = [];
		this.draggable = true;
		this.map = map;
		this.div = document.createElement("DIV");
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";
		this.map.div.appendChild(this.div);

		this.map.drag.init(this.div, null);

		this.div.onDragStart = this.map.divOnDragStartListener.bind(this.map);
		this.div.onDrag = this.map.divOnDragListener.bind(this.map);
		this.div.onDragEnd = this.map.divOnDragEndListener.bind(this.map);

		this.map.enableDrag = this.enableDrag.bind(this);
		this.map.disableDrag = this.disableDrag.bind(this);
		//this.div.onselectstart = this.map.__void.bindAsEventListener(this);
		this.initialized = true;

		if(this.map.map_id == 1)
			this.style_sheet =	this.map.__addStyleClass(".zoom_tile2 {width:200px;height:200px;}");
		return true;
	},
	disableDrag : function ()
	{
		this.draggable = false;
		this.map.drag = null;
		this.div.onmousedown = null;
		this.div.onmouseup = null;
		this.div.onmousemove = null;
		this.div.onDragStart = null;
		this.div.onDrag = null;
		this.div.onDragEnd = null;
	},
	enableDrag : function ()
	{
		this.draggable = true;
		this.map.drag = Drag;
		this.map.drag.init(this.div, null);

		this.div.onDragStart = this.map.divOnDragStartListener.bind(this.map);
		this.div.onDrag = this.map.divOnDragListener.bind(this.map);
		this.div.onDragEnd = this.map.divOnDragEndListener.bind(this.map);
	},
	updateTileLayers2 : function ()
	{
		var clncla_arr = this.map.__getTilePosByLnLa();

		var current_x = Math.floor(clncla_arr[0])-Math.floor(this.map.num_of_tile_x/2);
		var current_y = Math.floor(clncla_arr[1])-Math.floor(this.map.num_of_tile_y/2);

		var y_tile_pos = current_y;
		var x_tile_pos = current_x;

		var margin_x_px = (clncla_arr[0]-Math.floor(clncla_arr[0]))*this.map.tile_width;
		var margin_y_px = (clncla_arr[1]-Math.floor(clncla_arr[1]))*this.map.tile_height;

		var margin_left = this.map.__getOffset(this.map.container,true)-this.map.__getOffset(this.div,true);
		var margin_top = this.map.__getOffset(this.map.container,false)-this.map.__getOffset(this.div,false);

		var center_x_px = parseInt((this.map.div.offsetWidth/2)-margin_x_px-this.map.__getOffset(this.div,true));
		var center_x_px = parseInt((this.map.div.offsetWidth/2)-margin_x_px+margin_left);
		var center_y_px = parseInt((this.map.div.offsetHeight/2)-margin_y_px-this.map.__getOffset(this.div,false));
		var center_y_px = parseInt((this.map.div.offsetHeight/2)-margin_y_px+margin_top);

		var left = 0;
		var top = 0;

		var map_lib_pos = 0;
		for(var x=0; x<this.map.num_of_tile_x; x++)
		{
			y_tile_pos = current_y;
			for(var y=0; y<this.map.num_of_tile_y; y++)
			{
				for(var l=0; l < this.layers.length; l++)
				{
					this.layers[l].tiles[x][y].resetProperties(this.layers[l].tiles[x][y].src, x_tile_pos, y_tile_pos, this.map.current_zoom_level, this.map.tile_width, this.map.tile_height, this.layers[l].opt);
					left = (this.map.tile_width*(x_tile_pos-Math.floor(clncla_arr[0])))+center_x_px;
					top = (this.map.tile_height*(y_tile_pos-Math.floor(clncla_arr[1])))+center_y_px;
					this.layers[l].tiles[x][y].setLeftTop(left, top);
					if(this.layers[l].opacity != 1 && Element.getOpacity($(this.layers[l].tiles[x][y].image)) != this.layers[l].opacity)
					{
						Element.setOpacity( $(this.layers[l].tiles[x][y].image), this.layers[l].opacity );
					}
				}
				y_tile_pos++;
			}
			x_tile_pos++;
		}
	},
	updateTileLayers : function ()
	{
		for(var l=0; l < this.layers.length; l++)
		{
			this.layers[l].updateTiles();
		}
	},
	addDefaultTileLayer : function ()
	{
		if(this.default_tile_layer_added)
			return false;
		var default_tile_layer = new TileLayer(this);
		default_tile_layer.setName("default");
		default_tile_layer.initializeTiles();
		default_tile_layer.setZIndex(50);
//		default_tile_layer.setOpacity(0.5);
		this.layers.push(default_tile_layer);
		this.default_layer = this.layers[0];
		this.default_tile_layer_added = true;
	},
	addZoomTileLayer : function ()
	{
		if(this.zoom_tile_layer_added || !this.default_tile_layer_added)
			return false;

		this.zoom_layer = document.createElement("DIV");
		this.zoom_layer.id = "zoom_layer";
		this.zoom_layer.style.position = "absolute";
		this.zoom_layer.style.display = "none";
		this.zoom_layer.style.overflow = "visible";
		this.zoom_layer.style.left = this.default_layer.tiles[0][0].image.offsetLeft+"px";
		this.zoom_layer.style.top = this.default_layer.tiles[0][0].image.offsetTop+"px";
		this.zoom_layer.style.width = ((this.map.num_of_tile_x*this.map.tile_width))+"px";
		this.zoom_layer.style.height = ((this.map.num_of_tile_y*this.map.tile_height))+"px";
		this.zoom_layer.style.zIndex = "40";

		this.div.appendChild(this.zoom_layer);

		this.setZoomTile();
	},
	setZoomTile : function ()
	{
		while(this.zoom_layer.childNodes.length > 0)
			this.zoom_layer.removeChild(this.zoom_layer.childNodes[0]);

		var tmp_img = null;
		for(var y=0; y<this.map.num_of_tile_y; y++)
		{
			for(var x=0; x<this.map.num_of_tile_x; x++)
			{
				tmp_img = document.createElement("IMG");
				tmp_img.className = "zoom_tile2";
				tmp_img.id = "zoom_"+x+"_"+y+"_"+this.map.map_id;
				tmp_img.src = this.default_layer.tiles[x][y].image.src;
				this.zoom_layer.appendChild(tmp_img);
			}
			tmp_img = document.createElement("BR");
			this.zoom_layer.appendChild(tmp_img);
		}
		tmp_img = null;

		this.zoom_tile_layer_added = true;
	},
	standardInitZoomLayer : function ()
	{
		if(this.visual_effect_obj != null)
			this.visual_effect_obj.cancel();
		this.setZoomLayerPosition();
		this.setZoomLayerImage();
		this.showZoomLayer();
	},
	setZoomLayerPosition : function ()
	{
		this.zoom_layer.style.left = this.default_layer.tiles[0][0].image.offsetLeft+"px";
		this.zoom_layer.style.top = this.default_layer.tiles[0][0].image.offsetTop+"px";
	},
	showZoomLayer : function ()
	{
		this.zoom_layer.style.zIndex = "60";
		this.zoom_layer.style.display = "";
	},
	hideZoomLayer : function ()
	{
		this.zoom_layer.style.zIndex = "40";
		this.zoom_layer.style.display = "none";
	},
	setZoomLayerImage : function ()
	{

		for(var y=0; y<this.map.num_of_tile_y; y++)
		{
			for(var x=0; x<this.map.num_of_tile_x; x++)
			{
				$("zoom_"+x+"_"+y+"_"+this.map.map_id).src = this.default_layer.tiles[x][y].image.src;
			}
		}
		var css_obj = this.map.__getStyleClass("zoom_tile2");
		css_obj.style.width = 200;
		css_obj.style.height = 200;
	},
	zoomLayerAction : function (ratio, x, y)
	{

		var width = this.map.num_of_tile_x*this.map.tile_width;
		var height = this.map.num_of_tile_y*this.map.tile_height;
		var zoom_layer_left = this.map.__getOffset(this.zoom_layer, true);
		var zoom_layer_top = this.map.__getOffset(this.zoom_layer, false);

		var css = this.map.__getStyleClass("zoom_tile2");

		if(x == null)
			x = (this.map.div.offsetWidth/2)+this.map.__getOffset(this.map.div, true);

		if(y == null)
			y = (this.map.div.offsetHeight/2)+this.map.__getOffset(this.map.div, false);

		if(ratio > 0)
		{
			var rate = Math.pow(2,ratio);
			var final_width = (width*rate);
			var final_height = (height*rate);
			this.zoom_layer.style.width = final_width+"px";
			this.zoom_layer.style.height = final_height+"px"
			var zoom_rate = 0;
			for(var r=0; r < ratio; r++)
			{
				zoom_rate = zoom_rate+Math.pow(2,r);
			}

			zoom_layer_left = zoom_layer_left-((x-zoom_layer_left)*(zoom_rate));
			zoom_layer_top = zoom_layer_top-((y-zoom_layer_top)*(zoom_rate));
			var final_left = zoom_layer_left-this.div.offsetLeft;
			var final_top = zoom_layer_top-this.div.offsetTop;

			this.visual_effect_obj = new Effect.Parallel(
			    [
			    new Effect.Morph(this.zoom_layer,{style: 'left:'+(final_left-this.map.__getOffset(this.map.div, true))+'px; top:'+(final_top-this.map.__getOffset(this.map.div, false))+'px'}),
			    new Effect.Morph2(css, {style: 'width:'+(final_width/this.map.num_of_tile_x)+'px;height:'+(final_height/this.map.num_of_tile_y)+'px'})
			    ],
			    { duration: 1,
			      afterFinish:this.zoomLayerActionFinish.bind(this) }
			);
		}
		else
		{
			var rate = 0;
			var amount = 1;
			for(var i=0; i<Math.abs(ratio); i++)
			{
				var tmp = amount/2;
				amount = tmp;
				rate += amount;
				zoom_layer_left = ((x-zoom_layer_left)/2)+zoom_layer_left;
				zoom_layer_top = ((y-zoom_layer_top)/2)+zoom_layer_top;
			}
			var final_left = zoom_layer_left-this.div.offsetLeft;
			var final_top = zoom_layer_top-this.div.offsetTop;
			var final_width = width-(width*rate);
			var final_height = height-(height*rate);

			this.visual_effect_obj = new Effect.Parallel(
			    [
			    new Effect.Morph(this.zoom_layer,{style: 'left:'+(final_left-this.map.__getOffset(this.map.div, true))+'px; top:'+(final_top-this.map.__getOffset(this.map.div, false))+'px'}),
			    new Effect.Morph2(css, {style: 'width:'+(final_width/this.map.num_of_tile_x)+'px;height:'+(final_height/this.map.num_of_tile_y)+'px'})
			    ],
			    { duration: 1,
			      afterFinish:this.zoomLayerActionFinish.bind(this) }
			);
		}

	},
	zoomLayerActionFinish : function ()
	{
		this.visual_effect_obj = null;
		this.hideZoomLayer();
		this.map.__afterChangeZoom();
	},
	checkEdge : function ()
	{
		var edge_margin = this.map.__getLeftTopEdgeMargin();
		//alert(edge_margin[0]+" "+edge_margin[1]+" "+edge_margin[2]+" "+edge_margin[3]);
		while(edge_margin[0] > 0)
		{
			this.moveLeft();
			edge_margin = this.map.__getLeftTopEdgeMargin();
		}
		while(edge_margin[1] < 0)
		{
			this.moveRight();
			edge_margin = this.map.__getLeftTopEdgeMargin();
		}
		while(edge_margin[2] > 0)
		{
			this.moveTop();
			edge_margin = this.map.__getLeftTopEdgeMargin();
		}
		while(edge_margin[3] < 0)
		{
			this.moveBottom();
			edge_margin = this.map.__getLeftTopEdgeMargin();
		}
	},
	moveLeft : function ()
	{
		var new_left = this.default_layer.tiles[0][0].image.offsetLeft-this.map.tile_width;
		var new_x = this.default_layer.tiles[0][0].x-1;
		/*
		* Add a for loop to support multi tile layer
		*/
		for(var l=0; l < this.layers.length; l++)
		{
			var o=this.layers[l].tiles.pop();
			this.layers[l].tiles.unshift(o);
			for(var i=0; i<o.length; i++)
			{
				o[i].updatePos(new_x, o[i].y, this.map.current_zoom_level, this.layers[l].opt);
				o[i].image.style.left = new_left+"px";
			}
		}
	},
	moveRight : function ()
	{
		var new_left = this.default_layer.tiles[this.default_layer.tiles.length-1][0].image.offsetLeft+this.map.tile_width;
		var new_x = this.default_layer.tiles[this.default_layer.tiles.length-1][0].x+1;
		for(var l=0; l < this.layers.length; l++)
		{
			var o=this.layers[l].tiles.shift();
			this.layers[l].tiles.push(o);
			for(var i=0; i<o.length; i++)
			{
				o[i].updatePos(new_x, o[i].y, this.map.current_zoom_level, this.layers[l].opt);
				o[i].image.style.left = new_left+"px";
			}
		}
	},
	moveTop : function ()
	{
		var new_top = this.default_layer.tiles[0][0].image.offsetTop-this.map.tile_height;
		var new_y = this.default_layer.tiles[0][0].y-1;
		for(var l=0; l < this.layers.length; l++)
		{
			for(var i=0; i<this.layers[l].tiles.length; i++)
			{
				var o=this.layers[l].tiles[i].pop();
				this.layers[l].tiles[i].unshift(o);
				o.updatePos(o.x, new_y, this.map.current_zoom_level, this.layers[l].opt);
				o.image.style.top = new_top+"px";
			}
		}
	},
	moveBottom : function ()
	{
		var new_top = this.default_layer.tiles[0][this.default_layer.tiles[0].length-1].image.offsetTop+this.map.tile_height;
		var new_y = this.default_layer.tiles[0][this.default_layer.tiles[0].length-1].y+1;
		for(var l=0; l < this.layers.length; l++)
		{
			for(var i=0; i<this.layers[l].tiles.length; i++)
			{
				var o=this.layers[l].tiles[i].shift();
				this.layers[l].tiles[i].push(o);
				o.updatePos(o.x, new_y, this.map.current_zoom_level, this.layers[l].opt);
				o.image.style.top = new_top+"px";
			}
		}
	},
	getLayerByName : function (name)
	{
		for(var l=0; l < this.layers.length; l++)
		{
			if(this.layers[l].name == name)
			{
				return this.layers[l];
			}
		}
		return null;
	}
}

var Map2 = Class.create();
Map2.prototype = {
	drag : Drag,
	hit_counter : 0,
	hit_counter_dop : 0,
	container : null,
	tile_mode : 0,
	zoom : 3,
	map_id : 1,
	copyright_text : "&copy;2008&nbsp;Survey&nbsp;and&nbsp;Mapping&nbsp;Office,&nbsp;Lands&nbsp;Department<br>Copyright&nbsp;reserved&nbsp;-&nbsp;reproduction&nbsp;by&nbsp;permission&nbsp;only.",
	thumbnail_zoom_level : 4,
	default_tile_width : 200,
	default_tile_height : 200,
	tile_width : 200,
	tile_height : 200,
	zooming_layer : null,
	zooming_effect : null,
	zooming_value : null,

	on_drag_external_listener : null,
	on_zoom_external_listener : null,
	on_drag_start_external_listener : null,
	on_drag_end_external_listener : null,

	scroll_wheel_zoom_enable : true,
	draggable : true,
	dblclick_zoom : true,
	dblclick_action : true,
	dblclick_enable : true,

	tile_controller : null,

	check_edge_timeout : null,

	mouse_wheel_checker : null,
	mouse_wheel_zoom_level : null,
	mouse_wheel_action_count : null,
	mouse_wheel_action_count_history : null,
	mouse_wheel_xy : null,

	client_x : null,
	client_y : null,

	map_moving : false,
	map_overview : null,
	map_control : null,

	initialize : function (container, opt)
	{
		if(typeof(CONST_ZOOM_P1) == "undefined" || typeof(CONST_ZOOM_P2) == "undefined")
			return false;

		if(container.tagName.toLowerCase() != "div")
			return false;

		this.container = container;
		//alert(this.__getOffset(this.container, true));
		var tmp_c_left = this.__getOffset(this.container, true);
		var tmp_c_top = this.__getOffset(this.container, false);
		this.container.style.overflow = "hidden";
		this.container.style.position = "absolute";
		this.container.style.left = tmp_c_left+"px";
		this.container.style.top = tmp_c_top+"px";
		this.map_id = 1;
		if(opt != null && opt.map_id != null && !isNaN(opt.map_id))
			this.map_id = opt.map_id;

		while(typeof($("__map_panel_"+this.map_id)) == "undefined")
		{
			this.map_id++;
		}
		this.on_drag_external_listener = [];
		this.on_zoom_external_listener = [];
		this.on_drag_start_external_listener = [];
		this.on_drag_end_external_listener = [];

		this.div = document.createElement("DIV");
		this.div.className = "map";
		this.div.id = "__map_panel_"+this.map_id;
		this.div.style.overflow = "hidden";
		this.div.style.position = "relative";
		this.div.style.left = "0px";
		this.div.style.top = "0px";

		var tmp_width = (this.container.offsetWidth-parseInt((this.container.style.borderLeftWidth!=null)?this.container.style.borderLeftWidth:0)-parseInt((this.container.style.borderRightWidth!=null)?this.container.style.borderRightWidth:0)+1);
		var tmp_height = (this.container.offsetHeight-parseInt((this.container.style.borderTopWidth!=null)?this.container.style.borderTopWidth:0)-parseInt((this.container.style.borderBottomWidth!=null)?this.container.style.borderBottomWidth:0)+1);
		if(tmp_width < 0)
			tmp_width = 1;
		if(tmp_height < 0)
			tmp_height = 1;
		this.div.style.width = tmp_width+"px";
		this.div.style.height = tmp_height+"px";

		this.container.appendChild(this.div);
		/*document.body.appendChild(this.div);
		this.div.style.left = this.__getOffset(this.container, true)+"px";
		alert(this.__getOffset(this.container, false));
		this.div.style.top = this.__getOffset(this.container, false)+"px";*/
		//this.div.onselectstart = this.__void.bindAsEventListener(this);
		//this.container.onselectstart = this.__void.bindAsEventListener(this);
		this.num_of_tile_x = Math.round(parseInt(this.container.offsetWidth)/this.tile_width)+2;
		this.num_of_tile_y = Math.round(parseInt(this.container.offsetHeight)/this.tile_height)+2;

		this.min_zoom = null;
		this.max_zoom = null;

		/*for(var i=0; i<CONST_ZOOM_P2.length; i++)
		{
			var zoom_level = parseInt(CONST_ZOOM_P2[i].level);
			if(this.min_zoom == null || zoom_level < this.min_zoom)
				this.min_zoom = zoom_level;
			if(this.max_val == null || zoom_level > this.max_zoom)
				this.max_zoom = zoom_level;
		}*/
		for(var i=0; i<CONST_ALL_ZOOM.length; i++)
		{
			var zoom_level = parseInt(CONST_ALL_ZOOM[i].level);
			if(this.min_zoom == null || zoom_level < this.min_zoom)
				this.min_zoom = zoom_level;
			if(this.max_val == null || zoom_level > this.max_zoom)
				this.max_zoom = zoom_level;
		}
		if(this.map_id == 1)
		{
			this.max_zoom-=2;
		}

		this.current_zoom_level = CONST_DEFAULT_ZOOM;
		this.current_zoom_obj = CONST_ZOOM_P1;

		this.current_center_ln = CONST_DEFAULT_LN;
		this.current_center_la = CONST_DEFAULT_LA;

		/*
		*	Controller Initialization
		*/
		this.tile_controller = new TileLayerController(this);

		this.tile_controller.addDefaultTileLayer();

		this.tile_controller.addZoomTileLayer();
		this.tile_controller.div.ondblclick = this.__mapDblClickEventListener.bindAsEventListener(this);
		this.moving_panel = this.tile_controller.div;
		this.overlay_controller = new OverlayController(this);

		/*this.grid_controller = new MapGridHandler(this);
		this.grid_controller.setGridLayout(10,10);
		this.grid_controller.show();*/
		/*
		*	End of Controller Initialization
		*/

		/*
		*	Scroll Wheel Listener Initialization
		*/
		/*if(ie && this.tile_controller.div.onmousewheel == null)
		{
			if(this.map_id == 1 || this.map_id == "1")
				this.div.onmousewheel = this.__mouseWheelCapture.bindAsEventListener(this);
		}
		else
		{
			if(this.map_id == 1 || this.map_id == "1")
				this.div.addEventListener('DOMMouseScroll', this.__mouseWheelCaptureNonIE.bindAsEventListener(this), false);
		}*/
		/*if(document.attachEvent){
			if(this.map_id == 1 || this.map_id == "1")
				this.div.attachEvent("onmousewheel",this.__mouseWheelCapture.bindAsEventListener(this));

		}else{
			if(this.map_id == 1 || this.map_id == "1")
			{
				this.div.addEventListener("DOMMouseScroll", this.__mouseWheelCaptureNonIE.bindAsEventListener(this), false);
				Event.observe(window, "mousemove", this.__mapMouseMoveEventListener.bindAsEventListener(this));
			}
		}*/

		if (window.addEventListener)
		{
        		this.div.addEventListener('DOMMouseScroll', this.__mouseWheelCaptureNonIE.bindAsEventListener(this), false);
        		Event.observe(window, "mousemove", this.__mapMouseMoveEventListener.bindAsEventListener(this));
        }

		this.div.onmousewheel = this.__mouseWheelCapture.bindAsEventListener(this);

		/*
		*	End of Scroll Wheel Listener Initialization
		*/
		this.map_point_id = 0;
	},
	divOnDragStartListener : function (evt)
	{
		this.dragging = true;
		if(this.check_edge_timeout != null)
			this.check_edge_timeout.stop();

		if(!this.tile_controller.draggable)
			this.drag.end();

		var e = this.__getEvt(evt);

		if($(e[1]).draggable != null && $(e[1]).draggable == false)
			this.drag.end();

		this.check_edge_timeout = new PeriodicalExecuter(this.__dragTrackingAction.bind(this), 0.2);

		for(var i=0; i < this.on_drag_start_external_listener.length; i++)
		{
			this.on_drag_start_external_listener[i]();
		}

	},
	divOnDragListener : function ()
	{

	},
	divOnDragEndListener : function ()
	{
		if(this.tile_mode == 0)
			this.hit_counter++;
		else
			this.hit_counter_dop++;

		this.dragging = false;
		if(this.check_edge_timeout != null)
			this.check_edge_timeout.stop();
		this.__dragTrackingAction();
		for(var i=0; i < this.on_drag_end_external_listener.length; i++)
		{
			this.on_drag_end_external_listener[i]();
		}

	},
	/*
	*	Action Listener
	*/
	__mapMouseMoveEventListener : function (evt)
	{
		var e = evt ? evt : window.event;
		this.client_x = e.clientX;
		this.client_y = e.clientY;
	},
	/*__mapDblClickEventListener2 : function (evt)
	{
		var e = this.__getEvt(evt);
		var map_center_left = (this.div.offsetWidth/2)+this.__getOffset(this.div, true);
		var map_center_top = (this.div.offsetHeight/2)+this.__getOffset(this.div, false);

		var margin_left = (e[0].clientX-map_center_left)/2;
		var margin_top = (e[0].clientY-map_center_top)/2;

		var final_left = Math.ceil(Math.abs(map_center_left+margin_left));
		var final_top = Math.ceil(Math.abs(map_center_top+margin_top));
		var center_coor = this.__getCoorByClientXY(final_left, final_top);
		if(center_coor != null && center_coor.length == 2)
		{
			this.current_center_ln = center_coor[0];
			this.current_center_la = center_coor[1];

			var tmp = this.__getZoomInConfig();
			if(tmp === false)
				return false;
			this.tile_controller.updateTileLayers();
		}

	},*/
	__mapDblClickEventListener : function (evt)
	{
		if(!this.dblclick_enable)
			return;

		if(this.map_moving)
			return;

		this.map_moving = false;

		var e = this.__getEvt(evt);

		if(e[1].className != "maptile")
			return;

		var center = this.__getCenterPosition();
		var map_center_left = center[0]+parseInt(this.container.style.borderLeftWidth);
		var map_center_top = center[1]+parseInt(this.container.style.borderTopWidth);
//		alert(document.body.scrollLeft+" "+document.body.scrollTop);
		new Effect.Move (this.tile_controller.div,{ x: parseInt(map_center_left-e[0].clientX-document.body.scrollLeft), y: parseInt(map_center_top-e[0].clientY-document.body.scrollTop), mode: 'relative', duration:0.2, transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this, true)});
	},
	__mouseWheelCaptureNonIE : function(evt)
	{
		try{
			var e = this.__getEvt(evt);
			/*alert(e[1].tagName+" "+e[1].id);
			if( e[1].id.indexOf("tile_") == -1 && this.grid_selector_layer != e[1] )
			{
				if(!(e[1].scrollable != null && e[1].scrollable))
				{
					return;
				}
			}*/
			if(this.scroll_wheel_zoom_enable)
			{
				if (evt.detail > 0)
				{
					this.__mouseWheeling(e,1);
				}
				else
				{
					this.__mouseWheeling(e,-1);
				}
			}
		}
		catch(e)
		{}
	},
	__mouseWheelCapture : function(evt)
	{
		try{
			var e = this.__getEvt(evt);

			if(this.scroll_wheel_zoom_enable)
			{
				if (e[0].wheelDelta < 0 )
				{
					if(is_ie || agt.indexOf("safari")!=-1)
						this.__mouseWheeling(e,1);
					else
					{
						this.__mouseWheeling(e,-1);
					}
				}
				else
				{
					if(is_ie || agt.indexOf("safari")!=-1)
						this.__mouseWheeling(e,-1);
					else
						this.__mouseWheeling(e,1);
				}
			}
		}catch(e){}
	},
	/*
	*	End of Action Listener
	*/
	/*
	* Internal Use Function
	*/
	__getCenterPosition : function ()
	{
		var center_left = (Math.ceil(this.div.offsetWidth/2)+this.__getOffset(this.div,true));
		var center_top = (Math.ceil(this.div.offsetHeight/2)+this.__getOffset(this.div,false));
		//+parseInt(this.container.style.borderLeftWidth)+parseInt(this.container.style.borderTopWidth)
		return [center_left, center_top];
	},
	__mouseWheelStart : function (e)
	{
		this.mouse_wheel_zoom_level = 0;
		if(e != null)
		{
			//		alert(document.body.scrollLeft+" "+document.body.scrollTop);
			if(this.client_x != null && this.client_y != null)
				this.mouse_wheel_xy = [this.client_x+document.body.scrollLeft,this.client_y+document.body.scrollTop];
			else
				this.mouse_wheel_xy = [e[0].clientX+document.body.scrollLeft,e[0].clientY+document.body.scrollTop];
		}
	},
	__mouseWheeling : function (e, direction)
	{
		if(this.mouse_wheel_action_count == null)
		{
			this.mouse_wheel_action_count = 0;
			this.__mouseWheelStart(e);
		}
		if(direction > 0)
		{
			this.mouse_wheel_zoom_level++;
		}
		else
		{
			this.mouse_wheel_zoom_level--;
		}
		this.mouse_wheel__obj = e[1];
		this.mouse_wheel_action_count++;
		if(this.mouse_wheel_checker != null)
			this.mouse_wheel_checker.stop();
		this.mouse_wheel_checker = new PeriodicalExecuter(this.__mouseWheelCheck.bind(this), 0.01);
	},
	__mouseWheelEnd : function ()
	{
		this.mouse_wheel_zoom_level = null;
		this.mouse_wheel_action_count = null;
	},
	__mouseWheelCheck : function ()
	{
		if(this.mouse_wheel_action_count_history == this.mouse_wheel_action_count)
		{
			if(this.mouse_wheel_checker != null)
				this.mouse_wheel_checker.stop();
			var zoom_amount = 0;
			if(this.mouse_wheel_zoom_level > 0)
			{
				zoom_amount = Math.ceil(this.mouse_wheel_zoom_level/7);
			}
			else
			{
				zoom_amount = (Math.ceil(Math.abs(this.mouse_wheel_zoom_level)/7))*-1;
			}

			var loop_times = Math.abs(zoom_amount);
			this.setZoomLevel(this.current_zoom_level+zoom_amount,this.mouse_wheel_xy[0], this.mouse_wheel_xy[1]);
			this.mouse_wheel_action_count = null;
			this.mouse_wheel_zoom_level = null;
			this.mouse_wheel_xy = null;

		}
		else
		{
			this.mouse_wheel_action_count_history = this.mouse_wheel_action_count;
		}
	},
	__dragTrackingAction : function()
	{
		this.tile_controller.checkEdge();
		this.__setCurrentCenterCoor();
	},
	__void : function ()
	{
		return false;
	},
	__addStyleClass : function (css)
	{
	    var head, style;
	    head = document.getElementsByTagName('head')[0];
		var style = document.createElement("style");
		style.setAttribute("type", "text/css");
		if(style.styleSheet)
		{// IE
			style.styleSheet.cssText = css;
		}
		else
		{// w3c
			var cssText = document.createTextNode(css);
			style.appendChild(cssText);
		}
		head.appendChild(style);
	    return style;
	},
	__getStyleClass : function (className) {
		for (var s = 0; s < document.styleSheets.length; s++)
		{
			try{
			if(document.styleSheets[s].rules)
			{
				for (var r = 0; r < document.styleSheets[s].rules.length; r++)
				{
					if (document.styleSheets[s].rules[r].selectorText == '.' + className)
					{
						return document.styleSheets[s].rules[r];
					}
				}
			}
			else if(document.styleSheets[s].cssRules)
			{
				for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
				{
					if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
						return document.styleSheets[s].cssRules[r];
				}
			}
			}catch(e){}
		}
		return null;
	},
	__getTilePosByLnLa : function (ln, la, zoom)
	{
		if(ln == null)
			var ln = this.current_center_ln;
		if(la == null)
			var la = this.current_center_la;
		var zoom_property = this.current_zoom_obj;
		if(zoom != null)
			zoom_property = zoom;

		var y2 = (parseInt(zoom_property["la"])-parseInt(la))/parseFloat(zoom_property["total_y_meter"]);
		var y3 = y2*parseFloat(zoom_property["total_y_px"]);
		var cla = y3/this.default_tile_height;
		var x2 = (parseInt(ln)-parseInt(zoom_property["ln"]))/parseFloat(zoom_property["total_x_meter"]);
		var x3 = x2*parseFloat(zoom_property["total_x_px"]);
		var cln = x3/this.default_tile_width;
		return [cln, cla];
	},
	__getEvt : function(evt)
	{
		var e = evt ? evt : window.event;
		var src = ((ie)?e.srcElement:e.target);
		return [e, src];
	},
	__getOffset : function(obj, bool)
	{
		var total=0;
		while(obj!=null)
		{
			total+=obj["offset"+(bool?"Left":"Top")];

			obj=obj.offsetParent;
		}
		return total;
	},
	__getMapDivLeftTop : function ()
	{
		var l = this.__getOffset(this.container,true);
		var t = this.__getOffset(this.container,false);
		return [l, t];
	},
	__getLeftTopEdgeMargin : function()
	{
		var map_div_pos = this.__getMapDivLeftTop();

		var v1 = (parseInt(this.__getOffset(this.tile_controller.default_layer.tiles[0][0].image, true))-map_div_pos[0]);
		var v2 = parseInt(this.__getOffset(this.tile_controller.default_layer.tiles[0][0].image, true))+(this.num_of_tile_x*this.tile_width)-(map_div_pos[0]+this.div.offsetWidth);
		var v3 = (parseInt(this.__getOffset(this.tile_controller.default_layer.tiles[0][0].image, false))-map_div_pos[1]);
		var v4 = parseInt(this.__getOffset(this.tile_controller.default_layer.tiles[0][0].image, false))+(this.num_of_tile_y*this.tile_height)-(map_div_pos[1]+this.div.offsetHeight);
		return [v1,v2,v3,v4];
	},
	__getCoorByClientXY2 : function (x, y)
	{
		//var center_left = (Math.ceil(this.div.offsetWidth/2)+this.__getOffset(this.div,true));
		//var center_top = (Math.ceil(this.div.offsetHeight/2)+this.__getOffset(this.div,false));
		var center = this.__getCenterPosition();
		var center_left = center[0];
		var center_top = center[1];
		var center_obj = this.__getCenterObjAndMargin();
		var diff_x = ((x-center_left)/this.tile_width);
		var diff_y = ((y-center_top)/this.tile_height);

		var pos_x = center_obj[0].x+(diff_x);
		var pos_y = center_obj[0].y+(diff_y);
		var coor = this.__getCoorByObjPosAndMargin( Math.floor(pos_x), Math.floor(pos_y), Math.floor(((pos_x-Math.floor(pos_x)))*200)+center_obj[1], Math.floor(((pos_y-Math.floor(pos_y)))*200)+center_obj[2] );
		if(coor == null || coor.length != 2)
			return false;
		else
			return [coor[0], coor[1]];
	},
	__getClientXYByCoor : function (ln, la)
	{
		var center = this.__getCenterPosition();

		var clncla = this.__getTilePosByLnLa(Math.floor(ln),Math.floor(la));
		var center_clncla = this.__getTilePosByLnLa();

		var final_left = Math.ceil(center[0])-Math.ceil((center_clncla[0]-clncla[0])*this.tile_width);
		var final_top = Math.ceil(center[1])-Math.ceil((center_clncla[1]-clncla[1])*this.tile_height);
		//alert(final_left+" "+final_top+" "+$("tile_"+Math.floor(clncla[0])+"_"+Math.floor(clncla[1])+"_"+this.current_zoom_level+"_"+this.map_id));
		final_left = final_left-this.__getOffset(this.div,true)-this.tile_controller.div.offsetLeft;
		final_top = final_top-this.__getOffset(this.div,false)-this.tile_controller.div.offsetTop

		return [final_left, final_top];
	},
	__getCoorByClientXY : function (x, y)
	{
		if(x == null || y == null)
			return false;
		var target_tile = null;

		var tl = x;
		var tt = y;

		for(var x=0; x<this.num_of_tile_x; x++)
		{
			for(var y=0; y<this.num_of_tile_y; y++)
			{
				var l1 = this.__getOffset(this.tile_controller.default_layer.tiles[x][y].image, true);
				var t1 = this.__getOffset(this.tile_controller.default_layer.tiles[x][y].image, false);
				var l2 = l1+this.tile_width;
				var t2 = t1+this.tile_height;
				if(l1 <= tl && t1 <= tt && l2 >= tl && t2 >= tt)
				{
					target_tile = this.tile_controller.default_layer.tiles[x][y];
					break;
				}
			}
			if(target_tile != null)
				break;
		}

		if(target_tile == null)
			return null;

		var obj_x = tl-parseInt(this.__getOffset(target_tile.image, true));
		var obj_y = tt-parseInt(this.__getOffset(target_tile.image, false));
		try{
			return this.__getCoorByObjAndMargin(target_tile, obj_x, obj_y);
		}catch(e)
		{
			return null;
		}
	},
	__getCenterObjAndMargin : function ()
	{

		var target_tile = null;
		//var tl = (Math.ceil(this.div.offsetWidth/2)+this.__getOffset(this.div,true));
		//var tt = (Math.ceil(this.div.offsetHeight/2)+this.__getOffset(this.div,false));
		var center = this.__getCenterPosition();
		var tl = center[0];
		var tt = center[1];
		for(var x=0; x<this.num_of_tile_x; x++)
		{
			for(var y=0; y<this.num_of_tile_y; y++)
			{
				var l1 = this.__getOffset(this.tile_controller.default_layer.tiles[x][y].image, true);

				var t1 = this.__getOffset(this.tile_controller.default_layer.tiles[x][y].image, false);

				var l2 = l1+this.tile_width;
				var t2 = t1+this.tile_height;
				if(l1 <= tl && t1 <= tt && l2 >= tl && t2 >= tt)
				{
					target_tile = this.tile_controller.default_layer.tiles[x][y];
					break;
				}
			}
			if(target_tile != null)
				break;
		}
		if(target_tile == null)
			return false;

		obj_x = tl-parseInt(this.__getOffset(target_tile.image, true));

		obj_y = tt-parseInt(this.__getOffset(target_tile.image, false));

		return [target_tile, obj_x, obj_y];
	},
	__getCoorByObjPosAndMargin : function (pos_x, pos_y, margin_x, margin_y)
	{
		var glat = (
					(
					 (
						 (
							parseInt(pos_y)
						 )*this.tile_height
					 )+margin_y
				    )/this.current_zoom_obj["total_y_px"])*this.current_zoom_obj["total_y_meter"];
		glat = Math.floor(this.current_zoom_obj["la"])-glat;
		var glng = (
					(
					 (
						 (
							parseInt(pos_x)
						 )*this.tile_width
					 )+margin_x
				    )/this.current_zoom_obj["total_x_px"])*this.current_zoom_obj["total_x_meter"];
		glng = glng+Math.floor(this.current_zoom_obj["ln"]);

		return [glng, glat];
	},
	__getCoorByObjAndMargin : function (obj, margin_x, margin_y)
	{
		var id_arr = obj.image.id.split("_");
		return this.__getCoorByObjPosAndMargin(id_arr[1], id_arr[2], margin_x, margin_y);
	},
	__setCurrentCenterCoor : function ()
	{
		var tmp = this.__getCenterObjAndMargin();
		var tmp2 = this.__getCoorByObjAndMargin(tmp[0], tmp[1], tmp[2]);

		this.current_center_ln = tmp2[0];
		this.current_center_la = tmp2[1];
	},
	__moveFinishedAction : function (with_zoom)
	{
		this.tile_controller.checkEdge();
		this.__setCurrentCenterCoor();
		if(typeof(with_zoom) != "undefined" && with_zoom ===  true)
			this.zoomIn();
// && !(with_map_overview_sync != null && with_map_overview_sync == false)
		if(this.map_overview != null)
		{
			this.map_overview.onDragEndListener();
		}
		this.map_moving = false;
	},
	__getZoomInConfig : function ()
	{
		var tmp_zoom_val = this.current_zoom_level;
		this.current_zoom_level--;
		if(this.current_zoom_level < this.min_zoom)
			this.current_zoom_level = this.min_zoom;
		var tmp_zoom_level = this.current_zoom_level;

		if(this.current_zoom_level == tmp_zoom_val)
			return false;
		var tmp_zoom_obj = null;

		for(var i=0; i < CONST_ALL_ZOOM.length; i++)
		{
			if(CONST_ALL_ZOOM[i].level == tmp_zoom_level)
			{
				tmp_zoom_obj = CONST_ALL_ZOOM[i];
			}
		}
		if(tmp_zoom_obj == null)
		{
			return false;
		}
		else
			this.current_zoom_obj = tmp_zoom_obj;
	},
	__getZoomOutConfig : function ()
	{
		var tmp_zoom_val = this.current_zoom_level;
		this.current_zoom_level++;
		if(this.current_zoom_level > this.max_zoom)
			this.current_zoom_level = this.max_zoom;
		if(this.current_zoom_level < this.min_zoom)
		{
			var margin = Math.abs(this.min_zoom-this.current_zoom_level);
			this.tile_width = this.default_tile_width+(margin*200);
			this.tile_height = this.default_tile_width+(margin*200);
		}
		if(this.current_zoom_level == tmp_zoom_val)
			return false;
		var tmp_zoom_obj = null;
		for(var i=0; i < CONST_ALL_ZOOM.length; i++)
		{
			if(CONST_ALL_ZOOM[i].level == this.current_zoom_level)
			{
				tmp_zoom_obj = CONST_ALL_ZOOM[i];
			}
		}
		if(tmp_zoom_obj == null)
			return false;
		else
			this.current_zoom_obj = tmp_zoom_obj;
	},
	__afterChangeZoom : function ()
	{
		for(var i=0; i < this.on_zoom_external_listener.length; i++)
		{
			this.on_zoom_external_listener[i]();
		}
	},
	/*
	* End of Internal Use Function Section
	*/
	/*
	* External Use Function
	*/
	setSmoothZoom : function (bool)
	{
		if(this.tile_controller != null && this.tile_controller instanceof TileLayerController)
		{
			this.tile_controller.with_smooth_zoom = bool;
		}
	},
	getOptimizeMapCenterAndZoomLevelByMaxMinCoor : function (min_ln, max_ln, min_la, max_la)
	{
	try{
		if(min_ln != null && max_ln != null && min_la != null && max_la != null)
		{
			var center_ln = Math.floor((max_ln-min_ln)/2);
			var center_la = Math.floor((max_la-min_la)/2);

			var ln_margin = (max_ln-min_ln);
			var la_margin = (max_la-min_la);
			var zoom_case = 0;

			var ln_ratio = ln_margin/this.container.offsetWidth;
			var la_ratio = la_margin/this.container.offsetHeight;

			if(ln_margin > la_margin)
				zoom_case = 1;
			else if(la_margin > ln_margin)
				zoom_case = 2;

			var possible_level = [];
			var possible_rate = [];
			var rate = 1;

			// Find out possible zoom level
			for(var i=0; i<CONST_ALL_ZOOM.length; i++)
			{
				switch(zoom_case)
				{
					case 1:
					case 0:
						if(parseFloat(CONST_ALL_ZOOM[i].glg1_per_px) > ln_ratio)
						{
							possible_level.push(parseInt(CONST_ALL_ZOOM[i].level));
							possible_rate.push(parseFloat(CONST_ALL_ZOOM[i].glg1_per_px));
							rate = ln_ratio;
						}
						break;
					case 2:
						if(parseFloat(CONST_ALL_ZOOM[i].gla1_per_px) > la_ratio)
						{
							possible_level.push(parseInt(CONST_ALL_ZOOM[i].level));
							possible_rate.push(parseFloat(CONST_ALL_ZOOM[i].gla1_per_px));
							rate = la_ratio;
						}
						break;
				}
			}

			var min_zoom = 0;
			var pos = -1;
			var plus = 0;
			if(possible_level.length > 0)
			{
				min_zoom = 100;
				for(var i=0; i<possible_level.length; i++)
				{
					if(	possible_level[i] < min_zoom )
					{
						min_zoom = possible_level[i];
						pos = i;
					}
				}
			}

			if((rate/possible_rate[pos]) > 0.6)
				plus = 1;

			return [(min_zoom+plus), (min_ln+center_ln), (max_la-center_la)];
		}
	}
	catch(e)
	{
		alert(e.message);
		return false;
	}
	},
	optimizeMapCenterAndZoomLevel : function (map_points)
	{
		var min_ln = null;
		var max_ln = null;

		var min_la = null;
		var min_la = null;

		var return_center_ln = null;
		var return_center_la = null;
		var return_zoom_level = null;

		for(var i=0; i < map_points.length; i++)
		{
			if(map_points[i].ln == null || map_points[i].la == null)
				continue;

			if(map_points[i].ln > max_ln)
				max_ln = map_points[i].ln;
			else if(map_points[i].ln < min_ln)
				min_ln = map_points[i].ln;

			if(map_points[i].la > max_la)
				max_la = map_points[i].la;
			else if(map_points[i].la < min_la)
				min_la = map_points[i].la;
		}

		return this.getOptimizeMapCenterAndZoomLevelByMaxMinCoor(min_ln,max_ln,min_la,max_la);
	},
	resize : function (width, height)
	{
/*
		if(width == null || height == null || this.map_moving)
			return false;

		this.container.style.width = width+"px";
		this.container.style.height = height+"px";

		this.div.style.width = (this.container.offsetWidth-parseInt((this.container.style.borderLeftWidth!=null)?this.container.style.borderLeftWidth:0)-parseInt((this.container.style.borderRightWidth!=null)?this.container.style.borderRightWidth:0)+1)+"px";
		this.div.style.height = (this.container.offsetHeight-parseInt((this.container.style.borderTopWidth!=null)?this.container.style.borderTopWidth:0)-parseInt((this.container.style.borderBottomWidth!=null)?this.container.style.borderBottomWidth:0)+1)+"px";

		var num_x = Math.round(parseInt(this.container.offsetWidth)/this.tile_width)+2;
		var num_y = Math.round(parseInt(this.container.offsetHeight)/this.tile_height)+2;

		if(num_x > this.num_of_tile_x || num_y > this.num_of_tile_y)
		{
			this.num_of_tile_x = num_x;
			this.num_of_tile_y = num_y;
			for(var i=0; i < this.tile_controller.layers.length; i++)
			{
				this.tile_controller.layers[i].initializeTiles();
			}
		}

		this.tile_controller.setZoomTile();
		this.tile_controller.checkEdge();
		this.setCenter();

		if(this.map_overview != null)
		{
			this.map_overview.onDragEndListener();
		}
*/
		if(width == null || height == null || this.map_moving)
			return false;

		this.container.style.width = width+"px";
		this.container.style.height = height+"px";

		this.div.style.width = (this.container.offsetWidth-parseInt((this.container.style.borderLeftWidth!=null)?this.container.style.borderLeftWidth:0)-parseInt((this.container.style.borderRightWidth!=null)?this.container.style.borderRightWidth:0)+1)+"px";
		this.div.style.height = (this.container.offsetHeight-parseInt((this.container.style.borderTopWidth!=null)?this.container.style.borderTopWidth:0)-parseInt((this.container.style.borderBottomWidth!=null)?this.container.style.borderBottomWidth:0)+1)+"px";

		var num_x = Math.round(parseInt(this.container.offsetWidth)/this.tile_width)+2;
		var num_y = Math.round(parseInt(this.container.offsetHeight)/this.tile_height)+2;

		if(num_x > this.num_of_tile_x || num_y > this.num_of_tile_y)
		{
			this.num_of_tile_x = num_x;
			this.num_of_tile_y = num_y;
			for(var i=0; i < this.tile_controller.layers.length; i++)
			{
				this.tile_controller.layers[i].initializeTiles();
			}
		}

		this.tile_controller.setZoomTile();
		this.tile_controller.checkEdge();
		this.setCenter();

		if(this.map_overview != null)
		{
			this.map_overview.onDragEndListener();
			if(typeof(this.map_overview.setPosition) == "function")
				this.map_overview.setPosition();
		}

		if(this.map_control != null && typeof(this.map_control.setPosition) == "function")
		{
			this.map_control.setPosition();
		}
	},
	addMapControl : function ()
	{
		if(this.map_control != null)
			this.div.removeChild(this.map_control.div);

		this.map_control = new MapControlStandard(this);
	},
	addMapControlMini : function ()
	{
		if(this.map_control != null)
			this.div.removeChild(this.map_control.div);

		this.map_control = new MapControlMini(this);
	},
	addMapOverview : function ()
	{
		this.map_overview = new MapOverview(this);
	},
	switchMapMode : function (mode)
	{
		if(isNaN(mode))
			return false;
		this.tile_mode = mode;
		if(this.tile_controller.layers.length > 0)
		{
			this.tile_controller.default_layer.opt = {"dop":mode};
			this.tile_controller.default_layer.updateTiles();
		}
		if(this.map_overview != null)
		{
			this.map_overview.overview_map.switchMapMode(mode);
		}
		return true;
	},
	moveToEast : function (pixal)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;
		if(pixal == null || isNaN(pixal))
			var pixal = 400;

		new Effect.Move (this.tile_controller.div,{ x: (Math.abs(pixal)*(-1)), y: 0, mode: 'relative', duration:0.5, transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this)});
	},
	moveToSouth : function (pixal)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(pixal == null || isNaN(pixal))
			var pixal = 400;

		new Effect.Move (this.tile_controller.div,{ x: 0, y: (Math.abs(pixal)*(-1)), mode: 'relative', duration:0.5, transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this)});
	},
	moveToWest : function (pixal)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(pixal == null || isNaN(pixal))
			var pixal = 400;

		new Effect.Move (this.tile_controller.div,{ x: Math.abs(pixal), y: 0, mode: 'relative', duration:0.5, transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this)});
	},
	moveToNorth : function (pixal)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(pixal == null || isNaN(pixal))
			var pixal = 400;

		new Effect.Move (this.tile_controller.div,{ x: 0, y: Math.abs(pixal), mode: 'relative', duration:0.5, transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this)});
	},
	moveToNorthEast : function (x, y)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(x == null || isNaN(x) || x > 400)
			var x = 400;

		if(y == null || isNaN(y) || y > 400)
			var y = 400;

		new Effect.Move (this.tile_controller.div,{ x: (Math.abs(x)*(-1)), y: Math.abs(y), mode: 'relative', transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this), duration:0.5});
	},
	moveToSouthEast : function (x, y)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(x == null || isNaN(x) || x > 400)
			var x = 400;

		if(y == null || isNaN(y) || y > 400)
			var y = 400;

		new Effect.Move (this.tile_controller.div,{ x: (Math.abs(x)*(-1)), y: (Math.abs(y)*(-1)), mode: 'relative', transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this), duration:0.5});
	},
	moveToSouthWest : function (x, y)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(x == null || isNaN(x) || x > 400)
			var x = 400;

		if(y == null || isNaN(y) || y > 400)
			var y = 400;

		new Effect.Move (this.tile_controller.div,{ x: Math.abs(x), y: (Math.abs(y)*(-1)), mode: 'relative', transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this), duration:0.5});
	},
	moveToNorthWest : function (x, y)
	{
		if(this.map_moving || this.dragging)
			return;

		this.map_moving = true;

		if(x == null || isNaN(x) || x > 400)
			var x = 400;

		if(y == null || isNaN(y) || y > 400)
			var y = 400;

		new Effect.Move (this.tile_controller.div,{ x: Math.abs(x), y: Math.abs(y), mode: 'relative', transition: Effect.Transitions.slowstop, afterFinish:this.__moveFinishedAction.bind(this), duration:0.5});
	},
	moveToByXY : function (x, y, func)
	{
		if(this.map_moving || this.dragging)
			return;

		if(x == null || isNaN(x))
			return false;
		if(y == null || isNaN(y))
			return false;

		this.map_moving = true;

		if(x > 0 && x > 400)
			x = 400;
		if(x < 0 && x < -400)
			x = -400;

		if(y > 0 && y > 400)
			y = 400;
		if(y < 0 && y < -400)
			y = -400;

		new Effect.Move (this.tile_controller.div,{ x: x, y: y, mode: 'relative', transition: Effect.Transitions.slowstop, afterFinish:((func != null && typeof(func)=="function")?func:this.__moveFinishedAction.bind(this)), duration:0.5});
	},
	moveToByXYs : function (x,y)
	{
		if(this.map_moving || this.dragging)
			return;

		if(x == null || isNaN(x))
			return false;
		if(y == null || isNaN(y))
			return false;

		//this.map_moving = true;

		this.tile_controller.div.style.left = (this.tile_controller.div.offsetLeft+x)+"px";
	},
	setZoomLevel : function (val, x, y, opt)
	{
		if(this.tile_controller.visual_effect_obj != null)
			return false;

		if(isNaN(val))
			return false;

		if(val < this.min_zoom)
		{
			val = this.min_zoom;
		}
		if(val > this.max_zoom)
		{
			val = this.max_zoom;
		}
		if(this.current_zoom_level == val)
			return false;
		var ratio = this.current_zoom_level-val;
		//alert("1"+ratio);
		if(x != null && y != null)
		{
			/*x = x-parseInt(this.container.style.borderLeftWidth);
			y = y-parseInt(this.container.style.borderTopWidth);*/
			var mxx = parseInt((this.container.style.borderLeftWidth!=null)?this.container.style.borderLeftWidth:0);
			//+parseInt((this.container.style.borderRightWidth!=null)?this.container.style.borderRightWidth:0);
			var myy = parseInt((this.container.style.borderTopWidth!=null)?this.container.style.borderTopWidth:0);
			//+parseInt((this.container.style.borderBottomWidth!=null)?this.container.style.borderBottomWidth:0);
			x = x-mxx;
			y = y-myy;
			//var map_center_left = (this.div.offsetWidth/2)+this.__getOffset(this.div, true);
			//var map_center_top = (this.div.offsetHeight/2)+this.__getOffset(this.div, false);
			var center = this.__getCenterPosition();
			var map_center_left = center[0];
			var map_center_top = center[1];
			var margin_times = Math.abs(this.current_zoom_level-val);

			var margin_left = null;
			var margin_top = null;
			var final_left = map_center_left;
			var final_top = map_center_top;
			for(var m=0; m < margin_times; m++)
			{
				if(val > this.current_zoom_level)
				{
					margin_left = (x-map_center_left);
					margin_top = (y-map_center_top);
					final_left = (final_left-margin_left);
					final_top = (final_top-margin_top);
				}
				else
				{
					margin_left = (x-map_center_left)/2;
					margin_top = (y-map_center_top)/2;
					final_left = Math.abs(final_left+margin_left);
					final_top = Math.abs(final_top+margin_top);
				}

				map_center_left = final_left;
				map_center_top = final_top;
			}
			var center_coor = this.__getCoorByClientXY2(final_left, final_top);
			if(center_coor === false)
				return false;
			if(center_coor != null && center_coor.length == 2)
			{
				this.current_center_ln = center_coor[0];
				this.current_center_la = center_coor[1];
			}
		}


		this.current_zoom_level = val;
		var tmp_zoom_obj = null;

		for(var i=0; i < CONST_ALL_ZOOM.length; i++)
		{
			if(CONST_ALL_ZOOM[i].level == this.current_zoom_level)
			{
				tmp_zoom_obj = CONST_ALL_ZOOM[i];
			}
		}
		if(tmp_zoom_obj == null)
			return false;
		else
			this.current_zoom_obj = tmp_zoom_obj;

		//alert(ratio);
		//alert(this.tile_controller.with_smooth_zoom);
		if((opt != null && opt.no_smooth_zoom != null && opt.no_smooth_zoom) || !this.tile_controller.with_smooth_zoom)
		{
			this.tile_controller.updateTileLayers2();
			this.__afterChangeZoom();
		}
		else
		{
			if(ratio < 0)
			{
				this.tile_controller.standardInitZoomLayer();
				this.tile_controller.updateTileLayers2();
				this.tile_controller.zoomLayerAction(ratio,x,y);
			}
			else
			{
				this.tile_controller.standardInitZoomLayer();
				this.tile_controller.updateTileLayers2();
				this.tile_controller.zoomLayerAction(ratio,x,y);
			}
		}

		return true;
	},

	zoomIn : function (x, y)
	{
		if(this.tile_controller.visual_effect_obj != null)
			return false;

		//this.tile_controller.zoomLayerAction(1);
		if(x != null && y != null)
		{
			//var map_center_left = (this.div.offsetWidth/2)+this.__getOffset(this.div, true);
			//var map_center_top = (this.div.offsetHeight/2)+this.__getOffset(this.div, false);
			var center = this.__getCenterPosition();
			var map_center_left = center[0];
			var map_center_top = center[1];

			var margin_left = (x-map_center_left)/2;
			var margin_top = (y-map_center_top)/2;

			var final_left = Math.ceil(Math.abs(map_center_left+margin_left));
			var final_top = Math.ceil(Math.abs(map_center_top+margin_top));
			var center_coor = this.__getCoorByClientXY(final_left, final_top);
			if(center_coor != null && center_coor.length == 2)
			{
				this.current_center_ln = center_coor[0];
				this.current_center_la = center_coor[1];
			}
		}
		var tmp = this.__getZoomInConfig();
		if(tmp === false)
			return false;
		this.tile_controller.standardInitZoomLayer();
		this.tile_controller.updateTileLayers2();
		this.tile_controller.zoomLayerAction(1);
		this.__afterChangeZoom();
		return true;
	},
	zoomOut : function (x,y)
	{
		//this.tile_controller.zoomLayerAction(-1);
		if(this.tile_controller.visual_effect_obj != null)
			return false;

		if(x != null && y != null)
		{
			//var map_center_left = (this.div.offsetWidth/2)+this.__getOffset(this.div, true);
			//var map_center_top = (this.div.offsetHeight/2)+this.__getOffset(this.div, false);
			var center = this.__getCenterPosition();
			var map_center_left = center[0];
			var map_center_top = center[1];

			var margin_left = (x-map_center_left);
			var margin_top = (y-map_center_top);

			var final_left = Math.ceil(Math.abs(map_center_left-margin_left));
			var final_top = Math.ceil(Math.abs(map_center_top-margin_top));
			var center_coor = this.__getCoorByClientXY(final_left, final_top);
			if(center_coor != null && center_coor.length == 2)
			{
				this.current_center_ln = center_coor[0];
				this.current_center_la = center_coor[1];
			}
		}
		var tmp = this.__getZoomOutConfig();
		if(tmp === false)
			return false;
		this.tile_controller.standardInitZoomLayer();
		this.tile_controller.updateTileLayers2();
		this.tile_controller.zoomLayerAction(-1);

		this.__afterChangeZoom();
		return true;
	},
	getCenterCoor : function ()
	{
		var center = this.__getCenterPosition();
		var map_center_left = center[0];
		var map_center_top = center[1];
		var center_coor = this.__getCoorByClientXY2(map_center_left, map_center_top);
		return center_coor;
	},
	getBoundaryCoor : function ()
	{
		var left = this.__getOffset(this.div,true);
		var top = this.__getOffset(this.div,false);
		var lt_coor = this.__getCoorByClientXY2(left,top);

		var left = (Math.ceil(this.div.offsetWidth)+this.__getOffset(this.div,true));
		var top = (Math.ceil(this.div.offsetHeight)+this.__getOffset(this.div,false));
		var rb_coor = this.__getCoorByClientXY2(left,top);

		return [lt_coor,rb_coor];
	},
	setCenter : function (ln, la, smooth)
	{
		if(ln == null || la == null)
		{
			var ln = this.current_center_ln;
			var la = this.current_center_la;
		}

		if(smooth == null || !smooth)
		{
			this.current_center_ln = ln;
			this.current_center_la = la;
			this.tile_controller.updateTileLayers2();
			this.overlay_controller.onZoomChangeListener();
		}
		else
		{
			var xy1 = this.__getClientXYByCoor(this.current_center_ln, this.current_center_la);
			var xy2 = this.__getClientXYByCoor(ln, la);
			this.current_center_ln = ln;
			this.current_center_la = la;
			var mx = xy1[0]-xy2[0];
			var my = xy1[1]-xy2[1];
			this.map_moving = true;
			new Effect.Move (this.tile_controller.div,{ x: mx, y: my, mode: 'relative', transition: Effect.Transitions.slowstop, afterFinish:this.afterSmoothSetCenter.bind(this), duration:0.5});
		}
	},
	afterSmoothSetCenter : function ()
	{
		this.tile_controller.checkEdge();
		this.__setCurrentCenterCoor();
		this.overlay_controller.onZoomChangeListener();
		this.map_moving = false;
	},
	addOnDragListener : function(f)
	{
		if(typeof(f) != "function")
			return false;
		this.on_drag_external_listener.push(f);
	},
	removeOnDragListener : function(f)
	{
		if(typeof(f) != "function")
			return false;
		var pos = -1;
		for(var i=0; i < this.on_drag_external_listener.length; i++)
		{
			if(f == this.on_drag_external_listener[i])
			{
				pos = i;
				break;
			}
		}
		if(pos != -1)
		{
			this.on_drag_external_listener.splice(pos , 1);
		}
	},
	addOnDragStartListener : function(f)
	{
		if(typeof(f) != "function")
			return false;
		this.on_drag_start_external_listener.push(f);
	},
	removeOnDragStartListener : function (f)
	{
		if(typeof(f) != "function")
			return false;
		var pos = -1;
		for(var i=0; i < this.on_drag_start_external_listener.length; i++)
		{
			if(f == this.on_drag_start_external_listener[i])
			{
				pos = i;
				break;
			}
		}
		if(pos != -1)
		{
			this.on_drag_start_external_listener.splice(pos , 1);
		}
	},
	addOnDragEndListener : function (f)
	{
		if(typeof(f) != "function")
			return false;
		this.on_drag_end_external_listener.push(f);
	},
	removeOnDragEndListener : function (f)
	{
		if(typeof(f) != "function")
			return false;
		var pos = -1;
		for(var i=0; i < this.on_drag_end_external_listener.length; i++)
		{
			if(f == this.on_drag_end_external_listener[i])
			{
				pos = i;
				break;
			}
		}
		if(pos != -1)
		{
			this.on_drag_end_external_listener.splice(pos , 1);
		}
	},
	addOnZoomListener : function(f)
	{
		if(typeof(f) != "function")
			return false;
		this.on_zoom_external_listener.push(f);
	},
	removeOnZoomListener : function(f)
	{
		if(typeof(f) != "function")
			return false;
		var pos = -1;
		for(var i=0; i < this.on_zoom_external_listener.length; i++)
		{
			if(f == this.on_zoom_external_listener[i])
			{
				pos = i;
				break;
			}
		}
		if(pos != -1)
		{
			this.on_zoom_external_listener.splice(pos , 1);
		}
	},
	enableScrollWheelZoom : function()
	{
		this.scroll_wheel_zoom_enable = true;
	},
	disableScrollWheelZoom : function()
	{
		this.scroll_wheel_zoom_enable = false;
	},
	enableDrag : function ()
	{
		this.draggable = true;
	},
	disableDrag : function ()
	{
		this.draggable = false;
	},
	enableDoubleClick : function ()
	{
		this.dblclick_enable = true;
	},
	disableDoubleClick : function ()
	{
		this.dblclick_enable = false;
	},
	setCopyrightText : function (val)
	{
		if(val == null)
			return false;
		this.copyright_text = val;
		this.attachCopyrightText();
	},
	resetCopyrightText : function()
	{
		if(this.copyright_text == null)
			return false;
		this.copyright_text_div.style.left = "3px";
		this.copyright_text_div.style.top = (parseInt(this.container.offsetHeight)-parseInt(this.copyright_text_div.offsetHeight)-3)+"px";
	},
	attachCopyrightText : function()
	{
		if(this.copyright_text == null)
			return false;

		if(this.copyright_text_div == null)
		{
			this.copyright_text_div = window.document.createElement("div");
			this.copyright_text_div.style.zIndex = "1500";
			this.copyright_text_div.style.position = "absolute";
			this.container.appendChild(this.copyright_text_div);
		}

		this.copyright_text_div.innerHTML = this.copyright_text;
		this.copyright_text_div.className = "copyrighttext";
		//this.copyright_text_div.style.left = (parseInt(this.container.offsetWidth)-parseInt(this.copyright_text_div.offsetWidth)-3)+"px";
		this.copyright_text_div.style.left = "3px";
		this.copyright_text_div.style.top = (parseInt(this.container.offsetHeight)-parseInt(this.copyright_text_div.offsetHeight)-3)+"px";

	},
	detachCopyrightText : function()
	{
		if(this.copyright_text_div != null)
		{
			try{
				this.container.removeChild(this.copyright_text_div);
			}
			catch(e){}
		}
	},
	toJSON : function ()
	{
		var obj = {};
		obj.center_ln = this.current_center_ln;
		obj.center_la = this.current_center_la;
		obj.zoom_level = this.current_zoom_level;
		obj.tile_mode = this.tile_mode;

		return Object.toJSON(obj);
	},
	getSnap : function ()
	{
		return this.toJSON();
	},
	parseSnap : function (str)
	{
		var obj = null;
		eval("obj = "+str);

		if(obj.center_ln != null && obj.center_la != null)
		{
			this.setCenter(obj.center_ln, obj.center_la);
			if(this.map_overview != null)
			{
				this.map_overview.onDragEndListener();
			}
		}

		if(obj.zoom_level != null)
			this.setZoomLevel(obj.zoom_level);

		if(obj.tile_mode != null)
			this.switchMapMode(obj.tile_mode);
	}
	/*
	* End of External Use Function Section
	*/
}

var MapZoom = Class.create();
MapZoom.prototype = {
	properties : null,
	initialize : function(p, root)
	{
		if(p != null)
		{
			this.parent = p;
		}
		if(root != null)
		{
			this.root = root;
		}
		else
		{
			this.root = "";
		}
	},
	setProperties : function(properties)
	{
		this.properties = ((properties == null)?null:properties);
	},
	getProperties : function()
	{
		if(typeof(this.parent) == "undefined")
			return false;
		url = this.root+"xml/zoom_properties.php?z="+this.parent.zoom;

		this.ajax_request = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: this.getPropertiesRespone.bind(this)
			});
	},
	getPropertiesRespone : function(req)
	{
		var xml = req.responseXML;

		var data = xml.getElementsByTagName("item");

		if(data.length > 0)
		{
			this.properties = null;
			eval(" this.properties = "+data[0].firstChild.nodeValue);
		}
	}
}

var MapLatLng = Class.create();
MapLatLng.prototype = {
	latlng : null,
	//MapLatLng {"lat" : 0, "lng" : 0, "gov_lat" : 0, "gov_lng" : 0},
	initialize : function(properties)
	{
		if(properties != null)
		{
			var r = this.setLatLng(properties);
		}
	},
	setLatLng : function(properties)
	{
		if(	properties["lat"] != null &&  properties["lng"] != null && properties["gov_lat"] != null && properties["gov_lng"] != null)
		{
			this.latlng = properties;
			return true;
		}
		else
		{
			return false;
		}
	},
	getLatLng : function()
	{
		return this.latlng;
	}
}

var MapLatLngBound = Class.create();
MapLatLngBound.prototype = {
	latlng_bound : null,
	initialize : function(ll1, ll2)
	{
		var r = this.setLatLngVound(ll1, ll2)
	},
	getLatLngBound : function()
	{
		return this.latlng_bound;
	},
	setLatLngBound : function(ll1, ll2)
	{
		latlng1 = new MapLatLng(ll1);
		latlng2 = new MapLatLng(ll2);
		if(latlng1.getLatLng() != null && latlng2.getLatLng() != null)
		{
			this.latlng_bound = new Array();
			this.latlng_bound.push(latlng1);
			this.latlng_bound.push(latlng2);
			return true;
		}
		else
		{
			return false;
		}
	}
}

var Tile = Class.create();
Tile.prototype = {
	image : null,
	coor : null,
	initialize : function(p, src, x, y, z, w, h, opt)
	{
		this.parent = p;
		this.x = x;
		this.y = y;
		this.z = z;
		this.image = document.createElement("IMG");
		this.image.id = "tile_"+x+"_"+y+"_"+z+"_"+this.parent.map_id;
		this.image.style.width = w+"px";
		this.image.style.height = h+"px";
		this.image.className = "maptile";
		this.image.style.position = "absolute";
		this.left = 0;
		this.top = 0;
		this.image.style.left = "0px";
		this.image.style.top = "0px";
		this.image.style.display = "";
		this.tmp_image = new Image(this.parent.tile_width, this.parent.tile_height);
		//if(is_ie || is_gecko)
		//	this.tmp_image.onload = this.tmpImageOnLoad.bindAsEventListener(this);
		this.src = src;

		/*switch(	this.parent.tile_mode )
		{
			case 2:
				this.image.src = this.src+"?x="+this.x+"&y="+this.y+"&z="+this.z+"&dop=1";
				break;
			default:
				this.image.src = this.src+"?x="+this.x+"&y="+this.y+"&z="+this.z;
				break;
		}*/
		var src = this.src+"?x="+this.x+"&y="+this.y+"&z="+this.z;
		if(opt != null && typeof(opt) == "object")
		{
			var h = $H(opt);
			src = src+"&"+h.toQueryString();
		}
		this.image.src = src;
	},
	tmpImageOnLoad : function ()
	{
		this.image.src = this.tmp_image.src;
	},
	getImage : function()
	{
		return this.image;
	},
	resetProperties : function(src, x, y, z, w, h, opt)
	{
		//this.image.src = CONST_IMG_PATH+"images/dummy_tile.gif";
		this.x = x;
		this.y = y;
		this.z = z;
		this.image.id = "tile_"+x+"_"+y+"_"+z+"_"+this.parent.map_id;
		this.image.style.width = w+"px";
		this.image.style.height = h+"px";
		this.src = src;

		this.updateSrc(opt);
	},
	setImage : function(image_object)
	{
		this.image = image_object;
	},
	setImageSrc : function(src)
	{
		if(this.image.tagName == "IMG")
		{
			this.image.src = src;
			return true;
		}
		return false;
	},
	setLeftTop : function(left, top)
	{
		this.left = left;
		this.top = top;
		this.image.style.left = left+"px";
		this.image.style.top = top+"px";
	},
	updateSrc : function(opt)
	{
		//if(is_ie || is_gecko)
		//	this.image.src = CONST_IMG_PATH+"images/dummy_tile.gif";
		this.image.id = "tile_"+this.x+"_"+this.y+"_"+this.z+"_"+this.parent.map_id;

		var src = this.src+"?x="+this.x+"&y="+this.y+"&z="+this.z;
		if(opt != null && typeof(opt) == "object")
		{
			var h = $H(opt);
			src = src+"&"+h.toQueryString();
		}
		//this.image.src = src;
		//if(is_ie || is_gecko)
		//	this.tmp_image.src = src;
		//else
			this.image.src = src;
	},
	updatePos : function(x, y, z, opt)
	{
		this.x = x;
		this.y = y;
		this.z = z;
		this.updateSrc(opt);
	}
}

var MapGrid = Class.create();
MapGrid.prototype = {
	grid_item_width : 100,
	grid_item_height : 50,
	initialize : function(p)
	{
		this.parent = p;
		this.num_x = Math.ceil(parseInt(this.parent.map_tile_container.div.offsetWidth)/this.grid_item_width);
		this.num_y = Math.ceil(parseInt(this.parent.map_tile_container.div.offsetHeight)/this.grid_item_height);
	},
	getGridObj : function()
	{
		this.div = window.document.createElement("DIV");
		w = this.num_x*this.grid_item_width+this.num_x;
		h = this.num_y*this.grid_item_height+this.num_y;
		this.div.style.width = w+"px";
		this.div.style.height = h+"px";
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";
		this.div.style.zIndex = "1000";
		this.div.id = "grid_master";
		this.html = "";
		l = 0;
		t = 0;
		for(var y=0; y < this.num_y; y++)
		{
			for(var x=0; x < this.num_x; x++)
			{
				l = x*this.grid_item_width;
				div_l = window.document.createElement("DIV");
				div_l.style.left = l+"px";
				div_l.style.top = t+"px";
				div_l.style.position = "absolute";
				div_l.style.width = this.grid_item_width+"px";
				div_l.style.height = this.grid_item_height+"px";
				div_l.style.border = "1px #DDDDDD solid";
				div_l.id = "grid_"+x+"_"+y;
				div_l.className = "test";
				div_l.style.display = "none";
				this.div.appendChild(div_l);
			}
			t = t+this.grid_item_height;
		}
		return this.div;
	}
}


var MapContextMenu = Class.create();
MapContextMenu.prototype = {
	items : null,
	initialize : function()
	{
		this.items = new Array();
		this.parent = null;
		this.initDiv();
	},
	initDiv : function()
	{
		this.div = window.document.createElement("div");
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "0px";
		this.div.style.width = "180px";
		this.div.style.height = "100px";
		this.div.style.zIndex = "2000";
		this.div.style.display = "none";
		this.div.id = "context_menu_div";
		htm = '<table width="180" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">';
		htm += '  <tr>';
		htm += '    <td bgcolor="#FFFFFF" id="context_menu_item_list">--</td>';
		htm += '  </tr>';
		htm += '</table>';
		this.div.innerHTML = htm;

		this.div_shad = window.document.createElement("div");
		this.div_shad.style.position = "absolute";
		this.div_shad.style.left = "8px";
		this.div_shad.style.top = "8px";
		this.div_shad.style.width = "180px";
		this.div_shad.style.height = "100px";
		this.div_shad.style.display = "none";
		this.div_shad.style.zIndex = "1900";
		this.div_shad.style.backgroundColor = "#999999";
		this.div_shad.id = "context_menu_shad";
		this.div_shad.className = "msgshad";

		htm = "&nbsp;";
		this.div_shad.innerHTML = htm;
	},
	searchGroup : function(g_name)
	{
		for(var i=0; i < this.items.length; i++)
		{
			if(this.items[i][0] != null && this.items[i][0] == gname)
				return this.items[i];
		}
		return null;
	},
	deleteItemByObject : function(obj)
	{
		for(var i=0; i < this.items.length; i++)
		{
			if(this.items[i][0] != null && this.items[i][0] == obj.group)
			{
				var pos = -1;
				for(var y=0; y < this.items[i].arr.length; y++)
				{
					if(this.items[i][1][y] == obj)
					{
						pos = y;
						break;
					}
				}
				if(pos != -1)
				{
					return this.items[i][1].splice(pos, 1);
				}
			}
		}
		return null;
	},
	sortItems : function(a, b)
	{
	   if(a.k > b.k)
	      return 1
	   if(a.k < b.k)
	      return -1
	   return 0
	},
	addItem : function(obj) //{"text" : , "action" : , "group" : }
	{
		if(obj.text != null && obj.action != null && obj.group != null)
		{
			obj.text.replace("<img", "<img width='20px' height='20px'");
			this.items.push({"k":obj.group, "o":obj});
			this.items.sort(this.sortItems);

		}
	},
	displayItems : function()
	{
		var obj = $("context_menu_item_list");
		obj.innerHTML = "";
		if(this.items.length == 0)
			obj.innerHTML = "&nbsp;";
		var last_k = "";
		for(var i=0; i < this.items.length; i++)
		{
			var tmp_o = document.createElement("div");
			tmp_o.className = "context_header_text";
			if(this.items[i].k != last_k)
			{
				if(i != 0)
				{
					xx = document.createElement("hr");
					obj.appendChild(xx);
				}
				tmp_o.innerHTML = this.items[i].k;
			}
			obj.appendChild(tmp_o);

			this.items[i].o.layer = document.createElement("a");
			this.items[i].o.layer.className = "context_item_text";
			this.items[i].o.layer.innerHTML = this.items[i].o.text;
			this.items[i].o.layer.href = "javascript:a()";
			this.items[i].o.layer.onclick = this.items[i].o.action;
			obj.appendChild(this.items[i].o.layer);
			last_k = this.items[i].k;
		}
	},
	showMenu : function(obj, x, y)
	{
		this.parent.context_menu_x = x;
		this.parent.context_menu_x = y;
		var tmp = this.parent.calCoorByObj(obj, x, y);
		this.parent.context_menu_ln = tmp[0];
		this.parent.context_menu_la = tmp[1];
		this.displayItems();
		this.div.style.display = "";
		this.div.style.left = (x-this.parent.getOffset(this.parent.container, true))+"px";
		this.div.style.top = (y-this.parent.getOffset(this.parent.container, false))+"px";
		this.div.style.height = this.div.childNodes[0].offsetHeight+"px";
		this.div_shad.style.display = "";
		this.div_shad.style.left = (x-this.parent.getOffset(this.parent.container, true)+5)+"px";
		this.div_shad.style.top = (y-this.parent.getOffset(this.parent.container, false)+5)+"px";
		this.div_shad.style.height = this.div.childNodes[0].offsetHeight+"px";
	},
	hideMenu : function()
	{
		this.div.style.display = "none";
		this.div_shad.style.display = "none";
	}
}

var MapOverview = Class.create();
MapOverview.prototype = {
	initialize : function (map)
	{
		if(map == null || !(map instanceof Map2))
			return false;

		this.map = map;
		this.frame_div = document.createElement("DIV");
		this.frame_div = document.createElement("DIV");
		this.frame_div.style.position = "absolute";
		this.frame_div.style.backgroundColor = "#FFFFFF";
		this.frame_div.style.width = "152px";
		this.frame_div.style.height = "152px";
		this.frame_div.style.border = "1px #333333 solid";
		this.frame_div.style.left = (this.map.div.offsetWidth-152)+"px";
		this.frame_div.style.top = (this.map.div.offsetHeight-152)+"px";
		this.frame_div.style.zIndex = "102";
		this.map.div.appendChild(this.frame_div);

		this.div = document.createElement("DIV");
		this.div.style.position = "absolute";
		this.div.style.backgroundColor = "#FFFFFF";
		this.div.style.width = "150px";
		this.div.style.height = "150px";
		this.div.style.border = "0px #333333 solid";
		this.div.style.left = (this.map.div.offsetWidth-150)+"px";
		this.div.style.top = (this.map.div.offsetHeight-150)+"px";
		this.div.style.zIndex = "102";
		this.map.div.appendChild(this.div);

		this.switch_div = document.createElement("DIV");
		this.switch_div.style.position = "absolute";
		this.switch_div.style.backgroundColor = "#FFFFFF";
		this.switch_div.style.width = "21px";
		this.switch_div.style.height = "21px";
		this.switch_div.style.cursor = "pointer";
		this.switch_div.style.border = "0px #333333 solid";
		this.switch_div.style.left = (this.map.div.offsetWidth-21)+"px";
		this.switch_div.style.top = (this.map.div.offsetHeight-21)+"px";
		this.switch_div.innerHTML = "<img src='"+CONST_IMG_PATH+"images/close_map_overview.gif'>";
		this.switch_div.onclick = this.switchMapClick.bindAsEventListener(this);
		this.switch_div.style.zIndex = "103";
		this.map.div.appendChild(this.switch_div);

		this.boundary_div = document.createElement("DIV");
		this.boundary_div.style.position = "absolute";
		this.boundary_div.style.backgroundImage = "url("+CONST_IMG_PATH+"images/nbsp.gif)";
		this.boundary_div.style.zIndex = "5005";
		this.boundary_div.style.display = "none";
		this.boundary_div.style.border = "2px #333333 solid";
		this.boundary_div.style.backgroundColor = "#A6DBFF";
		this.boundary_div.style.cursor = "pointer";
		this.div.appendChild(this.boundary_div);
		Element.setOpacity($(this.boundary_div), 0.3);

		this.shield = document.createElement("DIV");
		this.shield.style.position = "absolute";
		this.shield.style.backgroundImage = "url("+CONST_IMG_PATH+"images/nbsp.gif)";
		this.shield.style.width = "150px";
		this.shield.style.height = "150px";
		this.shield.style.left = (0)+"px";
		this.shield.style.top = (0)+"px";
		this.shield.style.zIndex = "5004";
		this.div.appendChild(this.shield);

		Drag.init(this.boundary_div, null);
		this.boundary_div.onDragEnd = this.onBoundaryDragEndListener.bind(this);

		this.overview_map = new Map2(this.div, {map_id : 2});
		this.div.style.left = (this.map.div.offsetWidth-150)+"px";
		this.div.style.top = (this.map.div.offsetHeight-150)+"px";
		this.overview_map.dblclick_enable = false;
		this.overview_map.setZoomLevel(this.map.current_zoom_level+4, null, null, {no_smooth_zoom:true});
		this.overview_map.disableDrag();
		this.map.addOnZoomListener(this.onZoomListener.bind(this));
		this.map.addOnDragEndListener(this.onDragEndListener.bind(this));

		this.setBoundaryLayer();

		this.map.setMapOverviewPosition = this.setPosition.bind(this);

		this.moving = 0;
	},
	setPosition : function ()
	{
		if(this.switch_div.childNodes[0].src.indexOf("open_") != -1)
		{
			this.div.style.left = (this.map.div.offsetWidth)+"px";
			this.div.style.top = (this.map.div.offsetHeight)+"px";

			this.frame_div.style.left = (this.map.div.offsetWidth)+"px";
			this.frame_div.style.top = (this.map.div.offsetHeight)+"px";
		}
		else
		{
			this.div.style.left = (this.map.div.offsetWidth-150)+"px";
			this.div.style.top = (this.map.div.offsetHeight-150)+"px";

			this.frame_div.style.left = (this.map.div.offsetWidth-152)+"px";
			this.frame_div.style.top = (this.map.div.offsetHeight-152)+"px";
		}
		this.switch_div.style.left = (this.map.div.offsetWidth-21)+"px";
		this.switch_div.style.top = (this.map.div.offsetHeight-21)+"px";

		this.setBoundaryLayer();
	},
	show : function ()
	{
		this.moving = 1;
		new Effect.Parallel (
		[
			new Effect.Move (this.div,{ x: (this.map.div.offsetWidth-150), y: (this.map.div.offsetHeight-150), mode: 'absolute', transition: Effect.Transitions.slowstop}),
			new Effect.Move (this.frame_div,{ x: (this.map.div.offsetWidth-152), y: (this.map.div.offsetHeight-152), mode: 'absolute', transition: Effect.Transitions.slowstop})
		],
		{
			duration : 0.5
		}
		);
	},
	hide : function ()
	{
		this.moving = 2;
		new Effect.Parallel (
		[
			new Effect.Move (this.div,{ x: (this.map.div.offsetWidth), y: (this.map.div.offsetHeight) , mode: 'absolute', transition: Effect.Transitions.slowstop}),
			new Effect.Move (this.frame_div,{ x: (this.map.div.offsetWidth), y: (this.map.div.offsetHeight), mode: 'absolute', transition: Effect.Transitions.slowstop})
		],
		{
			duration : 0.5
		}
		);
	},
	toggle : function ()
	{
		if(this.moving != 0)
			return;
		switch(this.moving)
		{
			case 1:
				this.hide();
				break;
			case 2:
				this.show();
				break;
		}
	},
	afterMoving : function ()
	{
		this.moving = false;
	},
	switchMapClick : function ()
	{
		if(this.switch_div.childNodes[0].src.indexOf("close_") != -1)
		{
			this.hide();
			this.switch_div.childNodes[0].src = CONST_IMG_PATH+"images/open_map_overview.gif";
		}
		else
		{
			this.show();
			this.switch_div.childNodes[0].src = CONST_IMG_PATH+"images/close_map_overview.gif";
		}
	},
	onZoomListener : function ()
	{
		Element.setOpacity($(this.overview_map.div), 0);
		if(this.veffects != null)
			this.veffects.cancel();
		this.veffects = new Effect.Opacity($(this.overview_map.div), {duration:1.5, from:0.0, to:1.0});
		//var xy = this.overview_map.__getClientXYByCoor(this.map.current_center_ln, this.map.current_center_la);
		this.overview_map.setCenter(this.map.current_center_ln, this.map.current_center_la);
		this.overview_map.setZoomLevel(this.map.current_zoom_level+4, null, null, {no_smooth_zoom:true});

		this.setBoundaryLayer();
	},
	onDragEndListener : function ()
	{
		this.overview_map.setCenter(this.map.current_center_ln, this.map.current_center_la);
	},
	setBoundaryLayer : function ()
	{
		var x1 = this.map.__getOffset(this.map.div, true);
		var y1 = this.map.__getOffset(this.map.div, false);
		var x2 = x1+this.map.div.offsetWidth;
		var y2 = y1+this.map.div.offsetHeight;

		var left_top = this.map.__getCoorByClientXY2(x1, y1);
		var right_bottom = this.map.__getCoorByClientXY2(x2, y2);

		var xy1 = this.overview_map.__getClientXYByCoor(left_top[0], left_top[1]);
		var xy2 = this.overview_map.__getClientXYByCoor(right_bottom[0], right_bottom[1]);

		var width = xy2[0]-xy1[0];
		var height = xy2[1]-xy1[1];
		//this.boundary_left = xy1[0];
		this.boundary_left = (this.div.offsetWidth/2)-(width/2);
		//this.boundary_top = xy1[1];
		this.boundary_top = (this.div.offsetHeight/2)-(height/2);

		this.boundary_div.style.left = (this.boundary_left-1)+"px";
		this.boundary_div.style.top = (this.boundary_top-1)+"px";
		this.boundary_div.style.width = (width+2)+"px";
		this.boundary_div.style.height = (height+2)+"px";

		this.boundary_div.style.display = "block";
	},
	onBoundaryDragEndListener : function ()
	{
		var x1 = this.map.__getOffset(this.boundary_div, true)+(this.boundary_div.offsetWidth/2);
		var y1 = this.map.__getOffset(this.boundary_div, false)+(this.boundary_div.offsetHeight/2);
		var coor = this.overview_map.__getCoorByClientXY2(x1, y1);
		var margin_x = this.boundary_left-this.boundary_div.offsetLeft;
		var margin_y = this.boundary_top-this.boundary_div.offsetTop;
		this.map.setCenter(coor[0], coor[1], true);

/*		var c2 = this.map.__getClientXYByCoor(coor[0], coor[1]);
		var c1 = this.map.__getClientXYByCoor(this.map.current_center_ln, this.map.current_center_la);

		var mx = c1[0]-c2[0];
		var my = c1[1]-c2[1];

		this.map.moveToByXY(mx,my, this.map.__moveFinishedAction.bind(this.map, false, false));*/
		this.overview_map.moveToByXY(margin_x,margin_y);
		new Effect.Move (this.boundary_div,{ x: this.boundary_left, y: this.boundary_top, mode: 'absolute', transition: Effect.Transitions.slowstop, duration:0.2});
	},
	afterBoundaryMove : function ()
	{

	}
}

var MapControlStandard = Class.create();
MapControlStandard.prototype = {
	initialize : function (map)
	{
		if(map == null)
			return false;

		this.map = map;

		this.div = document.createElement("DIV");
		this.div.style.position = "absolute";
		this.div.style.width = "64px";
		this.div.style.height = "300px";
		this.map.div.appendChild(this.div);
		this.div.style.top = "10px";
		this.div.style.left = (this.map.div.offsetWidth-74)+"px";
		this.div.style.zIndex = "101";

		this.move_top = document.createElement("DIV");
		this.move_top.style.position = "absolute";
		this.move_top.style.width = "21px";
		this.move_top.style.height = "21px";
		this.move_top.style.top = "0px";
		this.move_top.style.left = "21px";
		this.move_top.style.cursor = "pointer";
		this.move_top.onclick = this.map.moveToNorth.bind(this.map);
		this.move_top.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_n.gif' width='21' height='21' >";
		this.div.appendChild(this.move_top);

		this.move_right = document.createElement("DIV");
		this.move_right.style.position = "absolute";
		this.move_right.style.width = "21px";
		this.move_right.style.height = "21px";
		this.move_right.style.top = "21px";
		this.move_right.style.left = "42px";
		this.move_right.style.cursor = "pointer";
		this.move_right.onclick = this.map.moveToEast.bind(this.map);
		this.move_right.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_e.gif' width='21' height='21' >";
		this.div.appendChild(this.move_right);

		this.move_bottom = document.createElement("DIV");
		this.move_bottom.style.position = "absolute";
		this.move_bottom.style.width = "21px";
		this.move_bottom.style.height = "21px";
		this.move_bottom.style.top = "42px";
		this.move_bottom.style.left = "21px";
		this.move_bottom.style.cursor = "pointer";
		this.move_bottom.onclick = this.map.moveToSouth.bind(this.map);
		this.move_bottom.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_s.gif' width='21' height='21' >";
		this.div.appendChild(this.move_bottom);

		this.move_left = document.createElement("DIV");
		this.move_left.style.position = "absolute";
		this.move_left.style.width = "21px";
		this.move_left.style.height = "21px";
		this.move_left.style.top = "21px";
		this.move_left.style.left = "0px";
		this.move_left.style.cursor = "pointer";
		this.move_left.onclick = this.map.moveToWest.bind(this.map);
		this.move_left.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_w.gif' width='21' height='21' >";
		this.div.appendChild(this.move_left);

		this.slider_top = document.createElement("DIV");
		this.slider_top.style.position = "absolute";
		this.slider_top.style.width = "21px";
		this.slider_top.style.height = "20px";
		this.slider_top.style.left = "21px";
		this.slider_top.style.top = "70px";
		this.slider_top.innerHTML = "<img src='"+CONST_IMG_PATH+"images/z_t.gif' width='21' height='20'>";
		this.div.appendChild(this.slider_top);

		this.slider_middle = document.createElement("DIV");
		this.slider_middle.style.position = "absolute";
		this.slider_middle.style.width = "19px";
		if(is_ie)
			this.slider_middle.style.width = "21px";
		this.slider_middle.style.height = "130px";
		this.slider_middle.style.left = "21px";
		this.slider_middle.style.top = "90px";
		this.slider_middle.style.border = "1px #888888 solid";
		this.slider_middle.style.backgroundColor = "#EEEEEE";
		this.slider_middle.style.fontSize = "2px";
		this.div.appendChild(this.slider_middle);

		this.slider_bottom = document.createElement("DIV");
		this.slider_bottom.style.position = "absolute";
		this.slider_bottom.style.width = "21px";
		this.slider_bottom.style.height = "20px";
		this.slider_bottom.style.left = "21px";
		this.slider_bottom.style.top = "222px";
		if(is_ie)
			this.slider_bottom.style.top = "220px";
		this.slider_bottom.innerHTML = "<img src='"+CONST_IMG_PATH+"images/z_b.gif' width='21' height='20'>";
		this.div.appendChild(this.slider_bottom);

		this.zooms = [];
		//alert(this.map.max_zoom+" "+this.map.min_zoom);
		var num_zoom = (this.map.max_zoom-this.map.min_zoom)+1;
		//alert(num_zoom);
		var start_top = this.slider_middle.offsetTop+5;
		var end_top = (this.slider_middle.offsetTop+this.slider_middle.offsetHeight)-10;

		var height_margin = (end_top-start_top)/num_zoom;
		var pos_cnt = 0;
		for(var i=this.map.min_zoom; i<=this.map.max_zoom; i++)
		{
			var tmp = document.createElement("DIV");
			tmp.style.position = "absolute";
			tmp.style.fontSize = "1px";
			tmp.style.width = "15px";
			tmp.style.height = "1px";
			this.zooms[i] = Math.ceil(start_top+(pos_cnt*height_margin)+(height_margin/2));
			tmp.style.left = (this.slider_middle.offsetLeft+3)+"px";
			tmp.style.top = this.zooms[i]+"px";
			//alert(i+" : "+this.zooms[i]);
			if(is_ie)
				tmp.style.borderTop = "1px #CCCCCC solid";
			else
				tmp.style.backgroundColor = "#CCCCCC";
			this.div.appendChild(tmp);
			pos_cnt++;
		}

		tmp = document.createElement("DIV");
		tmp.style.position = "absolute";
		tmp.style.fontSize = "1px";
		tmp.style.width = "1px";
		tmp.style.height = (end_top-start_top)+"px";
		tmp.style.top = (start_top+2)+"px";
		tmp.style.left = (this.slider_middle.offsetLeft+(this.slider_middle.offsetWidth/2)-((is_ie)?0:1))+"px";
		tmp.style.backgroundColor = "#CCCCCC";
		this.div.appendChild(tmp);

		this.dragger = document.createElement("DIV");
		this.dragger.style.position = "absolute";
		this.dragger.style.width = "15px";
		this.dragger.style.height = "12px";
		this.dragger.style.left = "26px";

		this.dragger.style.top = (this.zooms[this.map.current_zoom_level]-4)+"px";
		this.dragger.style.cursor = "pointer";
		this.dragger.innerHTML = "<img src='"+CONST_IMG_PATH+"images/pointer.gif' width='15' height='12'>";
		this.div.appendChild(this.dragger);
		Drag2.init(this.dragger, null, 26, 26, (start_top+4), Math.ceil(start_top+((num_zoom-1)*height_margin)+(height_margin/2)-6));
		this.dragger.onDragEnd = this.onDragEndListener.bindAsEventListener(this);
		this.map.addOnZoomListener(this.setZoomLevel.bind(this));

		this.switch_div = document.createElement("DIV");
		this.switch_div.style.position = "absolute";
		this.switch_div.style.width = "21px";
		this.switch_div.style.height = "21px";
		this.switch_div.innerHTML = "<img src='"+CONST_IMG_PATH+"images/close_map_control.gif' width='21' height='21'>";
		this.map.div.appendChild(this.switch_div);
		this.switch_div.style.left = (this.map.div.offsetWidth-21)+"px";
		this.switch_div.style.backgroundColor = "#FFFFFF";
		this.switch_div.style.top = "0px";
		this.switch_div.style.zIndex = "1002";
		this.switch_div.style.cursor = "pointer";
		this.switch_div.onclick = this.toggle.bind(this);

		this.map.setMapControlPosition = this.setPosition.bind(this);
	},
	setPosition : function ()
	{
		if(this.switch_div.childNodes[0].src.indexOf("open_") != -1)
		{
			this.div.style.top = (this.div.offsetHeight*-1)+"px";
			this.div.style.left = (this.map.div.offsetWidth)+"px";
		}
		else
		{
			this.div.style.top = "10px";
			this.div.style.left = (this.map.div.offsetWidth-74)+"px";
		}
		this.switch_div.style.left = (this.map.div.offsetWidth-21)+"px";
		this.switch_div.style.top = "0px";
	},
	show : function ()
	{
		this.switch_div.childNodes[0].src = CONST_IMG_PATH+"images/close_map_control.gif";
		new Effect.Move (this.div,{x: (this.map.div.offsetWidth-74), y: (10), mode: 'absolute', duration:0.5});
	},
	hide : function ()
	{
		this.switch_div.childNodes[0].src = CONST_IMG_PATH+"images/open_map_control.gif";
		new Effect.Move (this.div,{x: (this.map.div.offsetWidth), y: (this.div.offsetHeight*-1), mode: 'absolute', duration:0.5});
	},
	toggle : function ()
	{
		if(this.switch_div.childNodes[0].src.indexOf("close_") != -1)
		{
			this.hide();
		}
		else
		{
			this.show();
		}
	},
	onDragEndListener : function ()
	{
		var margin = [];
		var min = 10000;
		var min_val = null;
		for(var i=0; i < this.zooms.length; i++)
		{
			var tmp = Math.abs(this.zooms[i]-this.dragger.offsetTop);
			if(tmp < min)
			{
				min = tmp;
				min_val = i;
			}
		}
		this.dragger.style.top = (this.zooms[min_val]-5)+"px";
		this.map.setZoomLevel(min_val+1);
	},
	setZoomLevel : function ()
	{
		//alert(this.map.current_zoom_level+" : "+(this.zooms[(this.map.current_zoom_level)]-5));
		this.dragger.style.top = (this.zooms[(this.map.current_zoom_level)]-5)+"px";
	}
}
/*
var MapControlMini = Class.create();
MapControlMini.prototype = {
	initialize : function ()
	{

	}
}*/
var MapControlMini = Class.create();
MapControlMini.prototype = {
	initialize : function (map)
	{
		if(map == null)
			return false;

		this.map = map;

		this.div = document.createElement("DIV");
		this.div.style.position = "absolute";
		this.div.style.width = "64px";
		this.div.style.height = "100px";
		this.map.div.appendChild(this.div);
		this.div.style.top = "10px";
		this.div.style.left = (this.map.div.offsetWidth-74)+"px";
		this.div.style.zIndex = "101";

		this.move_top = document.createElement("DIV");
		this.move_top.style.position = "absolute";
		this.move_top.style.width = "21px";
		this.move_top.style.height = "21px";
		this.move_top.style.top = "0px";
		this.move_top.style.left = "21px";
		this.move_top.style.cursor = "pointer";
		this.move_top.onclick = this.map.moveToNorth.bind(this.map);
		this.move_top.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_n.gif' width='21' height='21' >";
		this.div.appendChild(this.move_top);

		this.move_right = document.createElement("DIV");
		this.move_right.style.position = "absolute";
		this.move_right.style.width = "21px";
		this.move_right.style.height = "21px";
		this.move_right.style.top = "21px";
		this.move_right.style.left = "42px";
		this.move_right.style.cursor = "pointer";
		this.move_right.onclick = this.map.moveToEast.bind(this.map);
		this.move_right.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_e.gif' width='21' height='21' >";
		this.div.appendChild(this.move_right);

		this.move_bottom = document.createElement("DIV");
		this.move_bottom.style.position = "absolute";
		this.move_bottom.style.width = "21px";
		this.move_bottom.style.height = "21px";
		this.move_bottom.style.top = "42px";
		this.move_bottom.style.left = "21px";
		this.move_bottom.style.cursor = "pointer";
		this.move_bottom.onclick = this.map.moveToSouth.bind(this.map);
		this.move_bottom.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_s.gif' width='21' height='21' >";
		this.div.appendChild(this.move_bottom);

		this.move_left = document.createElement("DIV");
		this.move_left.style.position = "absolute";
		this.move_left.style.width = "21px";
		this.move_left.style.height = "21px";
		this.move_left.style.top = "21px";
		this.move_left.style.left = "0px";
		this.move_left.style.cursor = "pointer";
		this.move_left.onclick = this.map.moveToWest.bind(this.map);
		this.move_left.innerHTML = "<img src='"+CONST_IMG_PATH+"images/dir_w.gif' width='21' height='21' >";
		this.div.appendChild(this.move_left);

		this.slider_top = document.createElement("DIV");
		this.slider_top.style.position = "absolute";
		this.slider_top.style.width = "21px";
		this.slider_top.style.height = "20px";
		this.slider_top.style.left = "21px";
		this.slider_top.style.top = "70px";
		this.slider_top.innerHTML = "<img src='"+CONST_IMG_PATH+"images/z_t.gif' width='21' height='20'>";
		this.slider_top.onclick = this.zoomIn.bind(this);
		this.slider_top.style.cursor = "pointer";
		this.div.appendChild(this.slider_top);
		this.slider_bottom = document.createElement("DIV");
		this.slider_bottom.style.position = "absolute";
		this.slider_bottom.style.width = "21px";
		this.slider_bottom.style.height = "20px";
		this.slider_bottom.style.left = "21px";
		this.slider_bottom.style.top = "90px";
		this.slider_bottom.onclick = this.zoomOut.bind(this);
		this.slider_bottom.style.cursor = "pointer";
		//if(is_ie)
		//	this.slider_bottom.style.top = "220px";
		this.slider_bottom.innerHTML = "<img src='"+CONST_IMG_PATH+"images/z_b.gif' width='21' height='20'>";
		this.div.appendChild(this.slider_bottom);

		this.zooms = [];

		var num_zoom = (this.map.max_zoom-this.map.min_zoom);
		/*var start_top = this.slider_middle.offsetTop+5;
		var end_top = (this.slider_middle.offsetTop+this.slider_middle.offsetHeight)-10;

		var height_margin = (end_top-start_top)/num_zoom;*/

/*		for(var i=0; i<num_zoom; i++)
		{
			var tmp = document.createElement("DIV");
			tmp.style.position = "absolute";
			tmp.style.fontSize = "1px";
			tmp.style.width = "15px";
			tmp.style.height = "1px";
			this.zooms[i] = Math.ceil(start_top+(i*height_margin)+(height_margin/2));
			tmp.style.left = (this.slider_middle.offsetLeft+3)+"px";
			tmp.style.top = this.zooms[i]+"px";
			if(is_ie)
				tmp.style.borderTop = "1px #CCCCCC solid";
			else
				tmp.style.backgroundColor = "#CCCCCC";
			this.div.appendChild(tmp);
		}

		tmp = document.createElement("DIV");
		tmp.style.position = "absolute";
		tmp.style.fontSize = "1px";
		tmp.style.width = "1px";
		tmp.style.height = (end_top-start_top)+"px";
		tmp.style.top = (start_top+2)+"px";
		tmp.style.left = (this.slider_middle.offsetLeft+(this.slider_middle.offsetWidth/2)-((is_ie)?0:1))+"px";
		tmp.style.backgroundColor = "#CCCCCC";
		this.div.appendChild(tmp);

		this.dragger = document.createElement("DIV");
		this.dragger.style.position = "absolute";
		this.dragger.style.width = "15px";
		this.dragger.style.height = "12px";
		this.dragger.style.left = "26px";

		this.dragger.style.top = (this.zooms[this.map.current_zoom_level-1]-4)+"px";
		this.dragger.style.cursor = "pointer";
		this.dragger.innerHTML = "<img src='"+CONST_IMG_PATH+"images/pointer.gif' width='15' height='12'>";
		this.div.appendChild(this.dragger);
		Drag2.init(this.dragger, null, 26, 26, (start_top+4), Math.ceil(start_top+((num_zoom-1)*height_margin)+(height_margin/2)-6));
		this.dragger.onDragEnd = this.onDragEndListener.bindAsEventListener(this);
		this.map.addOnZoomListener(this.setZoomLevel.bind(this));
*/
		this.switch_div = document.createElement("DIV");
		this.switch_div.style.position = "absolute";
		this.switch_div.style.width = "21px";
		this.switch_div.style.height = "21px";
		this.switch_div.innerHTML = "<img src='"+CONST_IMG_PATH+"images/close_map_control.gif' width='21' height='21'>";
		this.map.div.appendChild(this.switch_div);
		this.switch_div.style.left = (this.map.div.offsetWidth-21)+"px";
		this.switch_div.style.backgroundColor = "#FFFFFF";
		this.switch_div.style.top = "0px";
		this.switch_div.style.zIndex = "1002";
		this.switch_div.style.cursor = "pointer";
		this.switch_div.onclick = this.toggle.bind(this);

		this.map.setMapControlPosition = this.setPosition.bind(this);
	},
	setPosition : function ()
	{
		if(this.switch_div.childNodes[0].src.indexOf("open_") != -1)
		{
			this.div.style.top = (this.div.offsetHeight*-1)+"px";
			this.div.style.left = (this.map.div.offsetWidth)+"px";
		}
		else
		{
			this.div.style.top = "10px";
			this.div.style.left = (this.map.div.offsetWidth-74)+"px";
		}
		this.switch_div.style.left = (this.map.div.offsetWidth-21)+"px";
		this.switch_div.style.top = "0px";
	},
	show : function ()
	{
		this.switch_div.childNodes[0].src = CONST_IMG_PATH+"images/close_map_control.gif";
		new Effect.Move (this.div,{x: (this.map.div.offsetWidth-74), y: (10), mode: 'absolute', duration:0.5});
	},
	hide : function ()
	{
		this.switch_div.childNodes[0].src = CONST_IMG_PATH+"images/open_map_control.gif";
		new Effect.Move (this.div,{x: (this.map.div.offsetWidth), y: (this.div.offsetHeight*-1), mode: 'absolute', duration:0.5});
	},
	toggle : function ()
	{
		if(this.switch_div.childNodes[0].src.indexOf("close_") != -1)
		{
			this.hide();
		}
		else
		{
			this.show();
		}
	},
	onDragEndListener : function ()
	{
		var margin = [];
		var min = 10000;
		var min_val = null;
		for(var i=0; i < this.zooms.length; i++)
		{
			var tmp = Math.abs(this.zooms[i]-this.dragger.offsetTop);
			if(tmp < min)
			{
				min = tmp;
				min_val = i;
			}
		}
		this.dragger.style.top = (this.zooms[min_val]-5)+"px";
		this.map.setZoomLevel(min_val+1);
	},
	setZoomLevel : function ()
	{
		this.dragger.style.top = (this.zooms[(this.map.current_zoom_level-1)]-5)+"px";
	},
	zoomIn : function ()
	{
		this.map.setZoomLevel(this.map.current_zoom_level-1);
	},
	zoomOut : function ()
	{
		this.map.setZoomLevel(this.map.current_zoom_level+1);
	}
}

var MapSnap = Class.create();
MapSnap.prototype = {
	initialized : false,
	initialize : function (map, opt)
	{
		if(map != null && !(map instanceof Map2))
			return;

		this.map = map;
		this.opt = {};
		if(opt != null && typeof(opt) == "object")
			this.opt = opt;

		this.initialized = true;
	},
	getSnap : function ()
	{
		if(!this.initialized)
			return false;

		var obj = {};

		obj.map = this.map.getSnap();
		obj.overlay = this.map.overlay_controller.getSnap();
		return Object.toJSON(obj);
	},
	restoreSnap : function (str)
	{
		if(!this.initialized)
			return false;

		/*
			Get Restore Obj
		*/
		var obj = null;
		eval("obj = "+str);

		/*
			Restore Map Procedure
		*/
		this.map.parseSnap(obj.map);

		/*
			Get Overlays Object
		*/
		var overlay = null;
		eval("overlay = "+obj.overlay);

		/*
			Restore Map Point Procedure
		*/
		if(overlay.points != null && overlay.points.length > 0)
		{
			var points = [];
			if(this.map.overlay_controller.add_map_point_set_timer != null)
			{
				this.map.overlay_controller.cancelMapPointSetAction();
			}

			this.map.removeAllMapPoint();

			for(var i=0; i < overlay.points.length; i++)
			{
				var tmp_icon = null;

				if(overlay.points[i].icon != null)
				{
					tmp_icon = new MapPointIcon(overlay.points[i].icon, overlay.points[i].icon_width, overlay.points[i].icon_height)
				}
				var tmp = new MapPoint(overlay.points[i].ln,overlay.points[i].la, {icon:tmp_icon});
				if(overlay.points[i].tabs != null && overlay.points[i].tabs.tab_list != null)
				{
					tmp.setInfoBubble(new OverlayInfoWindow(overlay.points[i].tabs.width, overlay.points[i].tabs.height));
					for(var j=0; j < overlay.points[i].tabs.tab_list.length; j++)
						tmp.opt.info_bubble.addTab(overlay.points[i].tabs.tab_list[j].header, overlay.points[i].tabs.tab_list[j].content);
				}
				if(overlay.points[i].draggable != null && overlay.points[i].draggable == 1)
				{
					tmp.enableDrag();
				}
				if(overlay.points[i].bounce != null)
				{
					tmp.bounce = overlay.points[i].bounce;
				}
				points.push(tmp);
			}
			this.map.addMapPointSet(points);
		}

		/*
			Restore Map SVG Procedure
		*/
		if(overlay.svg != null && overlay.svg.length > 0)
		{

		}
	}
}


var MapControlStandard = Class.create();
MapControlStandard.prototype = {
	initialize : function()
	{
		this.parent = null;
		this.zoom_level = new Array();
		this.slider = null;
	},
	initDiv : function()
	{
		this.div_shad = window.document.createElement("div");
		this.div_shad.style.position = "absolute";
		this.div_shad.style.position = "absolute";
		this.div_shad.style.left = "0px";
		this.div_shad.style.top = "20px";
		this.div_shad.style.zIndex = "2000";
		this.div_shad.style.border = "1px #999999 solid";
		this.div_shad.style.backgroundColor = "#FFFFFF";
		this.div_shad.className = "opac5";

		this.div = window.document.createElement("div");
		this.div.style.position = "absolute";
		this.div.style.left = "0px";
		this.div.style.top = "20px";
		this.div.style.zIndex = "2000";
		var htm = '<table width="63px" height="63px" border=0 cellpadding=0 cellspacing=0>';
		htm += '	<tr>';
		htm += '		<td id="map_control_nozoom_left_top">&nbsp;</td>';
		htm += '		<td id="map_control_nozoom_top" background="'+CONST_IMG_PATH+'images/natvigator3/dir_n.gif">&nbsp;</td>';
		htm += '		<td id="map_control_nozoom_right_top">&nbsp;</td>';
		htm += '	</tr>';
		htm += '	<tr>';
		htm += '		<td id="map_control_nozoom_left" background="'+CONST_IMG_PATH+'images/natvigator3/dir_w.gif">&nbsp;</td>';
		htm += '		<td >&nbsp;</td>';
		htm += '		<td id="map_control_nozoom_right" background="'+CONST_IMG_PATH+'images/natvigator3/dir_e.gif">&nbsp;</td>';
		htm += '	</tr>';
		htm += '	<tr>';
		htm += '		<td id="map_control_nozoom_left_bottom">&nbsp;</td>';
		htm += '		<td id="map_control_nozoom_bottom" background="'+CONST_IMG_PATH+'images/natvigator3/dir_s.gif">&nbsp;</td>';
		htm += '		<td id="map_control_nozoom_right_bottom">&nbsp;</td>';
		htm += '	</tr>';
		htm += '</table>';
		htm += '<table width=64 border=0 cellpadding=0 cellspacing=1>';
		htm += '<tr><td align="center" height="5px"></td></tr>';
		htm += '<tr><td align="center"><div id="zoom_control_zoom_level"></div>';

		htm += '</td></tr>';
		htm += '<tr><td align="center" height="5px"></td></tr>';
		htm += '</table>';
		this.div.innerHTML = htm;
	},
	resetOnResize : function()
	{
		this.div.style.left = (this.parent.container.offsetWidth-this.div.offsetWidth-10)+"px";
		this.div.style.top = "10px";
		this.div_shad.style.left = (this.parent.container.offsetWidth-this.div.offsetWidth-15)+"px";
		this.div_shad.style.top = "5px";
		this.div_shad.style.width = (this.div.offsetWidth+10)+"px";
		this.div_shad.style.height = (this.div.offsetHeight+10)+"px";
		this.slider.reset_drager();
	},
	initAction : function()
	{
		if($("map_control_nozoom_top") != null)
		{
			$("map_control_nozoom_top").onclick = this.mapMoveTop.bindAsEventListener(this);
			$("map_control_nozoom_top").style.cursor = "pointer";
		}
		if($("map_control_nozoom_bottom") != null)
		{
			$("map_control_nozoom_bottom").onclick = this.mapMoveBottom.bindAsEventListener(this);
			$("map_control_nozoom_bottom").style.cursor = "pointer";
		}
		if($("map_control_nozoom_right") != null)
		{
			$("map_control_nozoom_right").onclick = this.mapMoveRight.bindAsEventListener(this);
			$("map_control_nozoom_right").style.cursor = "pointer";
		}
		if($("map_control_nozoom_left") != null)
		{
			$("map_control_nozoom_left").onclick = this.mapMoveLeft.bindAsEventListener(this);
			$("map_control_nozoom_left").style.cursor = "pointer";
		}
		this.c_item = {"text" : "<img src='"+CONST_IMG_PATH+"images/natvigator2/move.gif' align='absmiddle'>&nbsp;Drag Mode", "action" : this.mapContextReturn1.bind(this), "obj":this, "group" : "Zoom Option"};
		this.c_item = {"text" : "<img src='"+CONST_IMG_PATH+"images/natvigator2/grid.gif' align='absmiddle'>&nbsp;Zoom Range Mode", "action" : this.mapContextReturn2.bind(this), "obj":this, "group" : "Zoom Option"};
		this.slider = new SliderX($("zoom_control_zoom_level"), this, 80, this.parent.max_zoom, this.parent.min_zoom, 1, this.parent.zoom);

		this.div_shad.style.width = (this.div.offsetWidth+10)+"px";
		this.div_shad.style.height = (this.div.offsetHeight+10)+"px";
	},
	hideZoomLevel : function()
	{
		this.div.childNodes[2].style.display = "none";
	},
	showZoomLevel : function()
	{
		this.div.childNodes[2].style.display = "";
	},
	zoomLevelMouseOver : function(evt)
	{
		return;
		var e = this.parent.getEvt(evt);
		var level = e[1].getAttribute("level");
		if(level == null)
			return;
		var obj = null;
		var clevel = level;
		for(var i=0; i<this.parent.zooms.length; i++)
		{
			if($("map_control_zoom_"+this.parent.zooms[i].level) != null)
			{
				obj = $("map_control_zoom_"+this.parent.zooms[i].level);
				clevel = obj.getAttribute("level");
				if(clevel == null)
					continue;
				switch((level-clevel))
				{
					case 0:
						obj.style.width = "26px";
						obj.style.height = "26px";
						break;
					case 1:
						obj.style.width = "24px";
						obj.style.height = "24px";
						break;
					case 2:
						obj.style.width = "22px";
						obj.style.height = "22px";
						break;
					case -1:
						obj.style.width = "24px";
						obj.style.height = "24px";
						break;
					case -2:
						obj.style.width = "22px";
						obj.style.height = "22px";
						break;
					default:
						obj.style.width = "20px";
						obj.style.height = "20px";
						break;
				}
			}
		}
	},
	mapContextReturn1 : function()
	{
		$("map_control_grid_button").src = CONST_IMG_PATH+"images/grid_off.gif";
		$("map_control_move_button").src = CONST_IMG_PATH+"images/drag_on.gif";
		this.parent.switchSelectMode(1);
	},
	mapContextReturn2 : function()
	{
		$("map_control_grid_button").src = CONST_IMG_PATH+"images/grid_on.gif";
		$("map_control_move_button").src = CONST_IMG_PATH+"images/drag_off.gif";
		this.parent.switchSelectMode(2);
	},
	mapSelectModeChange : function(evt)
	{
		var e = this.parent.getEvt(evt);
		if(e[1].id == null || e[1].id == "" || e[1].id.indexOf("map_control_") == -1)
			return;
		switch(e[1].id)
		{
			case "map_control_move_button":
				this.mapContextReturn1();
				break;
			case "map_control_grid_button":
				this.mapContextReturn2();
				break;
		}
	},
	mapMoveTop : function()
	{
		this.parent.transformByLTMargin(0, 400);
	},
	mapMoveBottom : function()
	{
		this.parent.transformByLTMargin(0, -400);
	},
	mapMoveRight : function()
	{
		this.parent.transformByLTMargin(-400, 0);
	},
	mapMoveLeft : function()
	{
		this.parent.transformByLTMargin(400, 0);
	},
	mapMoveLeftBottom : function()
	{
		this.parent.transformByLTMargin(400, -400);
	},
	mapMoveLeftTop : function()
	{
		this.parent.transformByLTMargin(400, 400);
	},
	mapMoveRightBottom : function()
	{
		this.parent.transformByLTMargin(-400, -400);
	},
	mapMoveRightTop : function()
	{
		this.parent.transformByLTMargin(-400, 400);
	},
	mapMove : function(direction)
	{
		if(typeof(this.parent.transformByLTMargin).toLowerCase() == "function")
		{
			switch(direction)
			{
				case 1:
					this.parent.transformByLTMargin(400, 0);
					break
				case 2:
					this.parent.transformByLTMargin(-400, 0);
					break
				case 3:
					this.parent.transformByLTMargin(0, 400);
					break;
				case 4:
					this.parent.transformByLTMargin(0, -400);
					break;
			}
		}
	},
	mapChangeZoomLevel : function(level)
	{
		if(this.parent.zoom != level)
			this.parent.changeZoomLevel(level, true);
	},
	setZoomLevel : function(level)
	{
		this.slider.set_val(level);
	}
}
