var id = 0;
var scaleText = [ "全　国", "広　域", "1/90万", "1/30万", "1/15万", "1/75000", "1/21000", "1/8000", "1/3000", "1/1500" ];

function MLargeMapControl( mm, obj ){

this.id="lmctr" + id++;

this.mmap = mm;
this.map=obj;

// スタート中心緯度経度
this.sen = this.mmap.getCenterLatLon();
// スタート中心pixel座標
this.sxy = this.mmap.latLon2Log(this.sen);
this.sx = parseInt(this.sxy.x);
this.sy = parseInt(this.sxy.y);

//alert("スタートnlel = " + this.sen + ", スタート中心pixel座標 : x : y = " + this.sxy + ":" + this.sx + ":" + this.sy);

};
MLargeMapControl.ID=0;
MLargeMapControl.prototype.show=function(){
	this.div=document.createElement("DIV");
	this.div.parentObj=this;
	this.div.style.position="absolute";
	this.div.style.left="10px";
	this.div.style.top="10px";
	this.div.id=this.id+"div";
	this.div.style.zIndex=500;
	this.map.appendChild(this.div);
	this.smoothZoom=false;

var s = "";
s += "<table border=0 cellpadding=0 cellspacing=2 id=cntarea"+this.id+">";
s += "<tr>";
s += "<td>";
s += "<div id=moveleftup"+this.id+">";
s += "<img src='/light/images/mcontrol/mvlu.png'>";
s += "</div>";
s += "</td>";
s += "<td>";
s += "<div id=moveup"+this.id+">";
s += "<img src='/light/images/mcontrol/mvu.png'>";
s += "</div>";
s += "</td>";
s += "<td>";
s += "<div id=moverightup"+this.id+">";
s += "<img src='/light/images/mcontrol/mvru.png'>";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "<tr>";
s += "<td>";
s += "<div id=moveleft"+this.id+">";
s += "<img src='/light/images/mcontrol/mvl.png'>";
s += "</div>";
s += "</td>";
s += "<td>";
s += "<div id=movecenter"+this.id+">";
s += "<img src='/light/images/mcontrol/mvc.png'>";
s += "</div>";
s += "</td>";
s += "<td>";
s += "<div id=moveright"+this.id+">";
s += "<img src='/light/images/mcontrol/mvr.png'>";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "<tr>";
s += "<td>";
s += "<div id=moveleftdown"+this.id+">";
s += "<img src='/light/images/mcontrol/mvld.png'>";
s += "</div>";
s += "</td>";
s += "<td>";
s += "<div id=movedown"+this.id+">";
s += "<img src='/light/images/mcontrol/mvd.png'>";
s += "</div>";
s += "</td>";
s += "<td>";
s += "<div id=moverightdown"+this.id+">";
s += "<img src='/light/images/mcontrol/mvrd.png'>";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "</table>";

this.div.innerHTML=s;


//var _mmap=this.map;
//this.div.onmouseup=function(){ _mmap.focuselem.focus(); }
//this.zoomdiv=document.getElementById("zoomarea"+this.id);
//this.zoomcur=document.createElement("IMG");
//this.zoomcur.src="/light/images/mcontrol/scroll_btn.png";
//this.zoomdiv.appendChild(this.zoomcur);
//this.zoomdiv.style.position="relative";
//this.zoomcur.id="zoomcur"+this.id;
//this.zoomcur.style.position="absolute";
//this.zoomcur.style.left=0;
//this.zoomcur.style.top=0;
//this.zbar=document.getElementById("zbar"+this.id);
// スケール
//this.setMaxZoomLevel(this.mmap.getLayerScaleList().length);

// 左上ボタン
this.zlu=document.getElementById("moveleftup"+this.id);
this.zlu.parentObj=this;
this.zlu.onmousedown=this.moveLeftUp;

// 上ボタン
this.zu=document.getElementById("moveup"+this.id);
this.zu.parentObj=this;
this.zu.onmousedown=this.moveUp;

// 右上ボタン
this.zru=document.getElementById("moverightup"+this.id);
this.zru.parentObj=this;
this.zru.onmousedown=this.moveRightUp;

// 左ボタン
this.zl=document.getElementById("moveleft"+this.id);
this.zl.parentObj=this;
this.zl.onmousedown=this.moveLeft;

// ★ボタン
this.zc=document.getElementById("movecenter"+this.id);
this.zc.parentObj=this;
this.zc.onmousedown=this.moveCenter;

// 右ボタン
this.zr=document.getElementById("moveright"+this.id);
this.zr.parentObj=this;
this.zr.onmousedown=this.moveRight;

// 左下ボタン
this.zld=document.getElementById("moveleftdown"+this.id);
this.zld.parentObj=this;
this.zld.onmousedown=this.moveLeftDown;

// 下ボタン
this.zd=document.getElementById("movedown"+this.id);
this.zd.parentObj=this;
this.zd.onmousedown=this.moveDown;

// 右下ボタン
this.zrd=document.getElementById("moverightdown"+this.id);
this.zrd.parentObj=this;
this.zrd.onmousedown=this.moveRightDown;

/*
this.zb=document.getElementById("zoomarea"+this.id);
this.zb.parentObj=this;
this.zb.flag=0;
this.zb.onmousedown=this.zoomMove;
//this.setZoomLevel(this.div.parentObj.map.zid);
*/
};

/** @private 左上ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveLeftUp=function() {
  this.parentObj.movePro(-200, -200);
}

/** @private 上ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveUp=function() {
  this.parentObj.movePro(0, -200);
}

/** @private 右上ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveRightUp=function() {
  this.parentObj.movePro(200, -200);
}

/** @private 左ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveLeft=function() {
  this.parentObj.movePro(-200, 0);
}

/** @private ★ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveCenter=function() {
  var m = this.parentObj.mmap;
  m.smoothMoveTo(this.parentObj.sen);
}

/** @private 右ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveRight=function() {
  this.parentObj.movePro(200, 0);
}

/** @private 左下ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveLeftDown=function() {
  this.parentObj.movePro(-200, 200);
}

/** @private 下ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveDown=function() {
  this.parentObj.movePro(0, 200);
}

/** @private 右下ボタンをクリックしたときの処理 */
MLargeMapControl.prototype.moveRightDown=function() {
  this.parentObj.movePro(200, 200);
}

/** @private 移動処理 */
MLargeMapControl.prototype.movePro=function(mx , my) {
  var m = this.mmap;
  latlon = m.getCenterLatLon();
  xy = m.latLon2Log(latlon);
  x = parseInt(xy.x) + mx;
  y = parseInt(xy.y) + my;
  var curpp = m.log2LatLon(new Point(x, y));
  m.smoothMoveTo(curpp);
};

function LayerMapControl( mm, obj ) {
this.id="lmctr" + id++;
this.mmap = mm;
this.map=obj;
};

LayerMapControl.ID=0;
LayerMapControl.prototype.show=function(){

this.div=document.createElement("DIV");
this.div.parentObj=this;
this.div.style.position="absolute";
this.div.style.left="10px";
this.div.style.top="10px";
this.div.id=this.id+"div";
this.div.style.zIndex=500;
this.map.appendChild(this.div);
this.smoothZoom=false;

var s = "";
s += "<table border=0 cellpadding=0 cellspacing=2 id=cntarea"+this.id+">";
s += "<tr>";
s += "<td colspan='3' align='center'>";
s += "<table border=0 cellpadding=0 cellspacing=0>";
s += "<tr>";
s += "<td align='center'>";
s += "<div>";
s += "<img src='/light/images/mcontrol/scroll_bar_up.png' id=zoomin"+this.id+">";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "<tr>";
s += "<td align='center'>";
s += "<div id=zoomarea"+this.id+">";
s += "<table border=0 cellpadding=0 cellspacing=0>";
s += "<tr>";
s += "<td align='center'>";
s += "<img src='/light/images/mcontrol/scroll_bar_bar1.png' id=zoombar"+this.id+">";
s += "<div id=zbar"+this.id+">";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "</table>";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "<tr>";
s += "<td align='center'>";
s += "<div>";
s += "<img src='/light/images/mcontrol/scroll_bar_down.png' id=zoomout"+this.id+">";
s += "</div>";
s += "</td>";
s += "</tr>";
s += "</table>";
s += "</td>";
s += "</tr>";
s += "</table>";

this.div.innerHTML=s;

this.zoomdiv=document.getElementById("zoomarea"+this.id);
this.zoomcur=document.createElement("IMG");
this.zoomcur.src="/light/images/mcontrol/scroll_btn.png";
this.zoomdiv.appendChild(this.zoomcur);
this.zoomdiv.style.position="relative";
this.zoomcur.id="zoomcur"+this.id;
this.zoomcur.style.position="absolute";
this.zoomcur.style.left=0;
this.zoomcur.style.top=0;
this.zbar=document.getElementById("zbar"+this.id);
// スケール
this.setMaxZoomLevel(this.mmap.getLayerScaleList().length);

/** スケールテキスト表示　*/
this.z_=document.createElement("DIV");
this.z_.id="zoomlevel"+this.id;
this.z_.style.position="absolute";
this.z_.style.left="24px";
this.z_img=document.createElement("IMG");
this.z_txt=document.createElement("DIV");
this.z_.appendChild(this.z_img);
this.z_.appendChild(this.z_txt);
this.zoomdiv.appendChild(this.z_);
this.z_img.src="/light/images/scale.png";
this.z_img.style.position="absolute";
this.z_img.style.left="0px";
this.z_img.style.top="0px";
this.z_txt.style.position="absolute";
this.z_txt.style.left="7px";
this.z_txt.style.top="1px";
this.z_txt.style.fontSize="10pt";
this.z_txt.id="zoomleveltext"+this.id;
this.z_txt.style.width="40px";
this.z_.style.display="none";
this.zoomcur.parentObj=this;
this.zoomcur.onmouseover=this.visibleZoomLevel;
this.zoomcur.onmouseout=this.hiddenZoomLevel;
this.zoombar=document.getElementById("zoombar"+this.id);
//this.zoombar.parentObj=false;
this.zoombar.parentObj=true;

// ズームバー
this.zb =  document.getElementById("zoomarea"+this.id);
this.zb.parentObj = this;
this.zb.flag = 0;
this.zb.onmousedown = this.zoomMove;

};

/** @private 現在のズームレベルを取得 */
LayerMapControl.prototype.getZoomLevel=function() {
  zbb = document.getElementById("zoombar"+this.id)
  zbc = this.zoomcur;
  zbbheight = zbb.height * (this.maxzoomlevel + 1);
  heightv = zbbheight;
  topv = Number(zbc.style.top.substring(0, zbc.style.top.length - 2) );
  selectv = this.maxzoomlevel - Math.round(topv / (heightv / (this.maxzoomlevel + 1)));
  return selectv;
}

/** @private ズームレベルを表示 */
LayerMapControl.prototype.visibleZoomLevel=function() {
//alert(this.zoomcur);
  zl = this.parentObj.zoomlv;
  zl.style.display = "block";
}
/** @private ズームレベルを非表示 */
LayerMapControl.prototype.hiddenZoomLevel=function() {
  zl = this.parentObj.zoomlv;
  zl.style.display = "none";
}

/** @private ズームバーを移動したときの処理 */
LayerMapControl.prototype.zoomMove=function(e) {
  pobj = this.parentObj;
  zbu = pobj.zb;
  zba = pobj.div;
  zbb = document.getElementById("zoombar"+pobj.id);
  zbc = pobj.zoomcur;
  zbl = pobj.zoomlv;
  zbt = pobj.zoomlvtxt;
  zbbheight = zbb.height * (pobj.maxzoomlevel + 1);
  mapheight = Number(pobj.map);
//  alert("mapheight = " + mapheight);
  cmove=function (e) {
    if(window.opera)
      posy = e.clientY;
    else if(document.all)
      posy = document.body.scrollTop+event.clientY;
    else if(document.layers||document.getElementById)
      posy = e.pageY;
    if (zba.style.top) {
      barpos = posy - 128 - zbu.height -
               Number(zba.style.top.substring(0, zba.style.top.length - 2))
               + zbc.height * 1.5 - 4;
    } else if (zba.style.bottom) {
      barpos = posy -  (mapheight -
                Number(zba.style.bottom.substring(0, zba.style.bottom.length - 2))) -
               zbu.height + zbc.height / 2 + zbbheight - 1;
    } else {
      barpos = posy - zbu.height - zbbheight - zbc.height;
    }
    if (barpos < 0) {
      barpos = 0;
    }
    if (barpos > zbbheight - zbc.height) {
      barpos = zbbheight - zbc.height;
    }
    zlv = pobj.getZoomLevel();
//    alert("zlv = " + zlv);
    //zbt.innerHTML = scaleText[zlv];
    //zbc.style.top = barpos;
    //zbl.style.top = barpos - 3;
    try{
      e.preventDefault();
    } catch(err) {
      event.returnValue = false;
    }
   }

   var zbaobj = zba;
   zba.onmousemove = function(e) {
     cmove(e);
   }

   zba.onmouseup = function(e) {
     zbaobj.onmousemove = null;
     zbaobj.onmouseup = null;
     value = pobj.getZoomLevel();
     pobj.setZoomLevel(value);
     if (this.parentObj.smoothZoom) {
       pobj.map.changeZoom( value );
     }
  }
  cmove(e);
}

/** @private 最大ズームレベルを設定 */
LayerMapControl.prototype.setMaxZoomLevel=function(value) {
  //if (this.getZoomLevel() > value) {
   // this.setZoomLevel(value)
  //}
  this.maxzoomlevel = value;
  this.zbar = document.getElementById("zbar"+this.id);
  zbs = "";
  //alert(this.maxzoomlevel);
  for (i = 0; i < this.maxzoomlevel; i++){
    var scale= this.mmap.getLayerScale(i);
    if(!_layers['s'+scale])continue;
    zbs += "<table border=0 cellpadding=0 cellspacing=0>";
    zbs += "<tr>";
    zbs += "<td align='center'>";
    zbs += "<img src='/light/images/mcontrol/scroll_bar_bar1.png'>";
    zbs += "</td>";
    zbs += "</tr>";
    zbs += "</table>";
  }
  this.zbar.innerHTML=zbs;
}


var top_arr = [ 20, 36, 52, 68, 84, 100, 116, 132, 148, 163, 179 ];
/** 縮尺画像設定 */
var tmp={  '25000':'/scale_main8000.gif',
           '70000':'/scale_main21000.gif',
           '250000':'/scale_main75000.gif',
           '500000':'/scale_main150000.gif',
           '1000000':'/scale_main300000.gif',
           '3000000':'/scale_main900000.gif',
           '5000000':'/scale_main5000000.gif',
           '26000000':'/scale_main26000000.gif',
           '83479934':'/spacer.gif'};

function MapionMapControl( _m, top, left ) {
this.m = null;
this.path = "/sh/images/mcontrol";
this.sco = 0;
this.ps = new Array(4, 20, 36, 52, 68, 84, 100, 116, 132, 148, 179);
this.pr = new Array(0 + 20, 16 + 20, 32 + 20, 48 + 20, 64 + 20, 80 + 20, 96 + 20, 112 + 20, 128 + 20, 144 + 20, 160 + 20);
this.e = null;
this.es;
this.ers;
this.ers2;
this.ers3;
this.ers4;
this.ee;
this.ee2;
this.er;
this.er2;
this.esh;
this.erf;
this.ep;
this.so;
this.sc;
this.f_closed = false;
this.lid;
this.f_switch = null;
this.s_offsetY;
this.y;
this.cursor;
this.minScale;
this.maxScale;
this.sno1 = null;
this.sno2 = null;
this.sno1flg = true;
this.sno2flg = true;
this.nowid = null;
this.snum = 0;
if (!_m)return null;
this.m = _m;
if (_bi.type == 1 && _bi.version == 5)this.cursor = "hand";
else this.cursor = "pointer";
this.e = document.createElement("div");
if (!this.e)return null;
this.e.id = "crtl";
this.e.style.position = "absolute";
this.e.style.top = top + "px";
this.e.style.left = left + "px";
this.e.style.zIndex = 50;
this.es = this.createDiv(this.path + "/spacer.gif", 2, 17, 0, 10, 168, false);
//this.ers = this.createDiv(this.path + "/scale_main01.gif", 2, 20, 11, 43, 161, false);
//this.ers2 = this.createDiv(this.path + "/scale_main02.gif", 2, 20, 11, 43, 161, false);
//this.ers3 = this.createDiv(this.path + "/scale_main03.gif", 2, 20, 11, 43, 161, false);

this.ccc = document.createElement("div");
this.ccc.style.postion = "absolute";
this.ccc.style.top = "10px";
this.ccc.style.left = "10px";
this.ccc.style.zIndex = 2;
// 中心点の表示縮尺をリストにする
this.setScalelist();
if(this.sno1) this.ccc.appendChild(this.sno1);
if(this.sno2) this.ccc.appendChild(this.sno2);
this.ers4 = this.createDiv(this.path + "/spacer.gif", 4, 20, 11, 43, 17*parseInt(this.ccc.childNodes.length-this.snum)-parseInt(this.ccc.childNodes.length-this.snum), true);
//this.es = this.createDiv(this.path + "/scale_bar2.gif", 2, 17, 0, 10, 17*parseInt(this.ccc.childNodes.length-this.snum)-parseInt(this.ccc.childNodes.length-this.snum)+3, false);
this.ee = this.createDiv(this.path + "/scale_pl01.gif", 2, 0, 11, 43, 20, true);
this.ee2 = this.createDiv(this.path + "/scale_pl02.gif", 2, 0, 11, 43, 20, false);
this.er = this.createDiv(this.path + "/scale_mn01.gif", 2, top_arr[this.ccc.childNodes.length-this.snum] + 1, 11, 43, 20, true);
this.er2 = this.createDiv(this.path + "/scale_mn02.gif", 2, top_arr[this.ccc.childNodes.length-this.snum] + 1, 11, 43, 20, false);
this.esh = this.createImg(this.path + "/scale_btn2.gif", 2, this.getSwitchPos(),  - 4, true);
this.erf = this.createImg(this.path + "/scale_waku.gif", 3, this.getRedFramePos(), 2 + 11, false);
//this.ep = this.createDiv(path + "/scale_pop.gif", 2, 20 + 16 + 1, 11 + 43, 43, 143, false);
this.sc = this.createDiv(this.path + "/scale_close.gif", 2, 0,  - 4, 15, 15, true);
this.so = this.createDiv(this.path + "/scale_open.gif", 3, 0,  - 4, 15, 15, true);
this.ee2.style.display = "none";
this.er2.style.display = "none";
//this.ers2.style.display = "none";
//this.ers3.style.display = "none";
//this.ep.style.display = "none";
this.so.style.display = "none";
this.e.appendChild(this.es);
//this.e.appendChild(this.ers);
this.e.appendChild(this.ccc);

//this.e.appendChild(this.ers2);
//this.e.appendChild(this.ers3);
this.e.appendChild(this.ers4);
this.e.appendChild(this.ee);
this.e.appendChild(this.ee2);
this.e.appendChild(this.er);
this.e.appendChild(this.er2);
this.es.appendChild(this.esh);
this.e.appendChild(this.erf);
//this.e.appendChild(this.ep);
this.e.appendChild(this.so);
this.e.appendChild(this.sc);
this.e.onmouseover = this.eover();
this.e.onmouseout = this.eout();
this.ee.onclick = this.exclick();
this.er.onclick = this.reclick();
//this.ers4.onmouseover = this.rover();
this.ers4.onmousemove = this.rmove();
this.ers4.onmouseout = this.rout();
this.ers4.onclick = this.rclick();
this.esh.onmousedown = this.sdown();
document.onmousemove = this.smove();
document.onmouseup = this.sup();
this.so.onclick = this.soclick();
this.sc.onclick = this.scclick();
};

/** 中心点の表示できる縮尺をセットする */
MapionMapControl.prototype.setScalelist = function() {
	var s = this;
	var c = 0;
	var num = 0;
	var lid = s.m.getLayerScaleList();
	var lid=s.m.mapView.packageCollect.map.layerCollect
	for( var i=0; i<lid.length; i++ ) {
		var scale=lid[i].scale
		if( i==0 ) s.minScale = s.m.getLayerId(scale);
		if( i==lid.length-1 ) s.maxScale = s.m.getLayerId(scale);
		var obj = s.createDiv(s.path + tmp[scale], 2, top_arr[i], 11, 43, 17, false);

		if( scale == 5000 ) {
			s.sno1 = s.createDiv(s.path + "/scale_main1500_a.gif", 2, top_arr[i], 11, 43, 17, false);
			num++;
		}
/*
		else if( scale == 10000 ) {
			s.sno2 = s.createDiv(s.path + "/scale_main3000_a.gif", 2, top_arr[i], 11, 43, 17, false);
			num++;
		}
*/
		obj.id = scale;
		s.ccc.appendChild(obj);
		s.snum = num;
		c = i;
	}
};

MapionMapControl.prototype.createImg = function (path, zindex, top, left, cursor) {
var img = document.createElement("img");
img.src = path;
img.style.position = "absolute";
img.style.top = top + "px";
img.style.left = left + "px";
img.style.zIndex = zindex;
if (cursor)img.style.cursor = this.cursor;
return img;
};

MapionMapControl.prototype.createDiv = function (path, zindex, top, left, width, height, cursor) {
var div = document.createElement("div");
div.style.position = "absolute";
div.style.top = top + "px";
div.style.left = left + "px";
div.style.backgroundImage = "url(" + path + ")";
div.style.backgroundRepeat = "no-repeat";
div.style.width = width + "px";
div.style.height = height + "px";
div.style.zIndex = zindex;
if (cursor)div.style.cursor = this.cursor;
return div;
};

MapionMapControl.prototype.getSwitchPos = function () {
var lid = this.m.getCurrentLayerId();
return this.ps[lid];
};

MapionMapControl.prototype.getRedFramePos = function () {
var lid = this.m.getCurrentLayerId();
return this.pr[lid] + 2;
};

// スケールバーにマウスオーバーでzIndexをあげる
MapionMapControl.prototype.eover = function () {
return function (e) {
//alert('HERE');
	document.getElementById('crtl').style.zIndex=12000;
	};
};
MapionMapControl.prototype.eout = function () {
return function (e) {
	document.getElementById('crtl').style.zIndex=50;
	};
};

// スケールバーのプラス(+)ボタンをクリック
MapionMapControl.prototype.exclick = function () {
var s = this;
return function (e) {
	var lid = s.m.getCurrentLayerId();
	s.nowid = s.m.getLayerScale(lid);
	if (s.minScale <= lid - 1) {
		s.m.layerTo(lid - 1);
		s.erf.style.top = s.getRedFramePos() + "px";
		s.esh.style.top = s.ps[lid-1] + "px";
		if( lid - 2 < s.minScale )s.changePB(0);
		s.changeMB(1);
		//if (s.f_closed)s.closeMove(lid - 1);
		if (s.f_closed)s.closebar(1);
	}
	};
};

// スケールバーのマイナス(-)ボタンをクリック
MapionMapControl.prototype.reclick = function () {
var s = this;
return function (e) {
	var lid = s.m.getCurrentLayerId();
	s.nowid = s.m.getLayerScale(lid);
	if (s.maxScale >= lid + 1) {
		s.m.layerTo(lid + 1);
		s.erf.style.top = s.getRedFramePos() + "px";
		s.esh.style.top = s.ps[lid+1] + "px";
		if( s.maxScale < lid + 2)s.changeMB(0);
		s.changePB(1);
		//if (s.f_closed)s.closeMove(lid + 1);
		if (s.f_closed)s.closebar(-1);
	}
	};
};

// スケールバーにマウスオーバーでpop画像を表示
MapionMapControl.prototype.rover = function () {
var s = this;
return function (e) {
	//s.ep.style.display = "block";
};
};

// スケールバーの横のボタンを移動で縮尺切り替え
MapionMapControl.prototype.rmove = function () {
var s = this;
return function (e) {
	if (!s.f_switch) {
		var y;
		if (_bi.type == 2)y = e.layerY + parseInt(this.style.top);
		else y = event.offsetY + this.style.posTop;
			for (var i = 0; i < s.pr.length; i++) {
				if (y > s.pr[i] && y <= s.pr[i] + 16) {
					var t = i;
					if (i <= s.minScale)t = s.minScale;
					s.erf.style.top = s.pr[t] + 2 + "px";
					s.lid = i;
					break;
				}
			}
	}
	return false;
};
};

MapionMapControl.prototype.rout = function () {
var s = this;
return function (e) {
	s.erf.style.top = s.getRedFramePos() + "px";
};
};

MapionMapControl.prototype.rclick = function () {
var s = this;
return function (e) {
	if (s.lid >= s.minScale) {
		s.m.layerTo(s.lid);
		s.esh.style.top = s.ps[s.lid] + "px";
		s.ee2.style.display = "none";
	}
	if(s.lid <= s.maxScale) {
		s.er2.style.display = "none";
	}
	if( s.lid == s.minScale ) s.ee2.style.display = "block";
	if( s.lid == s.maxScale ) s.er2.style.display = "block";
};
};

MapionMapControl.prototype.sdown = function () {
var s = this;
return function (e) {
	s.f_switch = this;
	if (_bi.type == 2)s.s_offsetY = e.pageY - parseInt(this.style.top);
	else s.s_offsetY = event.clientY + document.body.scrollTop - this.style.posTop;
	//s.ep.style.display = "block";
	s.erf.style.top = s.getRedFramePos() + "px";
	return false;
};
};

MapionMapControl.prototype.smove = function () {
var s = this;
return function (e) {
	if (s.f_switch) {
	if (_bi.type == 2)s.y = e.pageY - s.s_offsetY;
	else s.y = event.clientY + document.body.scrollTop - s.s_offsetY;
		var t = 0;
		if (s.minScale > 0)t = 16 * s.minScale + 4 + 1;
		if (s.y < t - (16 / 2))s.y = t - (16 / 2);
		if (s.y > 17*parseInt(s.ccc.childNodes.length-s.snum)-parseInt(s.ccc.childNodes.length-s.snum) - (16 / 2))s.y = 17*parseInt(s.ccc.childNodes.length-s.snum)-parseInt(s.ccc.childNodes.length-s.snum) - (16 / 2);
		s.esh.style.top = s.y + "px";
		s.erf.style.top = s.getRedFramePos() + "px";
		return false;
	}
};
};

MapionMapControl.prototype.sup = function () {
var s = this;
return function (e) {
	if (s.f_switch) {
		s.f_switch = null;
		var lid;
		if (s.y < s.ps[0] + 8) {
			s.esh.style.top = s.ps[0] + "px";
			lid = 0;
		}
		else if (s.y >= s.ps[s.ps.length - 1] - 8) {
			s.esh.style.top = s.ps[s.ps.length - 1] + "px";
			lid = s.ps.length - 1;
		}
		else {
			for (var i = 1; i < s.ps.length - 1; i++) {
				if (s.y >= s.ps[i] - 8 && s.y < s.ps[i] + 8) {
					s.esh.style.top = s.ps[i] + "px";
					lid = i;
					break;
				}
			}
		}
		s.m.layerTo(lid);
		s.erf.style.top = s.getRedFramePos() + "px";
		return false;
	}
};
};

MapionMapControl.prototype.soclick = function () {
var s = this;
return function (e) {
	s.f_closed = false;
	s.so.style.display = "none";
	s.esh.style.display = "block";
	s.es.style.display = "block";
	s.erf.style.display = "block";
	s.ers4.style.display = "block";
	s.er.style.top = 17*parseInt(s.ccc.childNodes.length-s.snum)+20-parseInt(s.ccc.childNodes.length-s.snum) + "px";
	s.er2.style.top = 17*parseInt(s.ccc.childNodes.length-s.snum)+20-parseInt(s.ccc.childNodes.length-s.snum) + "px";
	for( var i=0; i<s.ccc.childNodes.length-s.snum; i++ ) {
			s.ccc.childNodes[i].style.display = "block";
			s.ccc.childNodes[i].style.top = top_arr[i] + "px";
			s.ccc.childNodes[i].style.left = "11px";
	}
	s.getHantei(s.m.getLayerScaleList());
	if( s.sno1 && s.sno1flg ) s.sno1.style.display = "block";
	if( s.sno2 && s.sno2flg ) s.sno2.style.display = "block";
};
};

MapionMapControl.prototype.scclick = function () {
var s = this;
return function (e) {
	s.f_closed = true;
	s.so.style.display = "block";
	s.esh.style.display = "none";
	s.es.style.display = "none";
	s.erf.style.display = "none";
	s.ers4.style.display = "none";
	s.er.style.top = 36 + 1 + "px";
	s.er2.style.top = 36 + 1 + "px";
	if(s.sno1) s.sno1.style.display = "none";
	if(s.sno2) s.sno2.style.display = "none";
	var nows = null;
	for( var j=0; j<s.ccc.childNodes.length-s.snum; j++ ) {
		if( s.ccc.childNodes[j].id == s.m.getCurrentScale() ) {
			nows = s.ccc.childNodes[j];
			continue;
		}
		s.ccc.childNodes[j].style.display = "none";
	};
	var lid = s.m.getCurrentLayerId();
	if( lid <= s.minScale ) {
		s.ee2.style.display = "block";
	} else {
		s.ee2.style.display = "none";
	}
	s.nowid = nows.id;
	s.closeMove(nows);
};
};

MapionMapControl.prototype.closeMove = function (lid) {
lid.style.display = "block";
lid.style.top = "20px";
lid.style.left = "11px";
};

MapionMapControl.prototype.CancelBubble = function () {
return function (e) {
	CancelBubble(e);
};
};

// 縮尺変更で赤枠、ボタン位置変更
MapionMapControl.prototype.resetCnt = function() {
var s = this;
s.erf.style.top = s.getRedFramePos() + "px";
s.esh.style.top = s.getSwitchPos() + "px";
};


// プラス(+)ボタン画像を変更する
MapionMapControl.prototype.changePB = function( type ) {
var s = this;
if( type == 0 ) {
	s.ee2.style.display = "block";
} else {
	s.ee2.style.display = "none";
}
};
// マイナス(-)ボタン画像を変更する
MapionMapControl.prototype.changeMB = function( type ) {
var s = this;
if( type == 0 ) {
	s.er2.style.display = "block";
} else {
	s.er2.style.display = "none";
}
};


// 中心点の非表示縮尺の画像を変更
MapionMapControl.prototype.setnoneScale = function() {
var s = this;
var min = 15;
if( s.f_closed ) {
	var _list = s.m.getLayerScaleList();
	for( var key in _list ) {
		if( isNaN( parseInt(_list[key]) ) ) continue;
		if( _list[key] == 5000 ) {
			s.sno1flg = false;
		}
		if( _list[key] == 10000 ) {
			s.sno2flg = false;
		}
		if( min > s.m.getLayerId(_list[key]) ) min = s.m.getLayerId(_list[key]);
	}
	var nowscl = s.m.getCurrentScale();
	for( var j=0; j<s.ccc.childNodes.length-s.snum; j++ ) {
		s.ccc.childNodes[j].style.display = "none";
		if( s.ccc.childNodes[j].id == nowscl ) {
			s.closeMove( s.ccc.childNodes[j] );
			continue;
		}
	}
	// プラス(+)、マイナス(-)ボタンの表示変更
	if( s.m.getLayerId(s.m.getCurrentScale()) <= min ) {
		s.ee2.style.display = "block";
	} else {
		s.ee2.style.display = "none";
	}
	if( s.m.getLayerId(s.m.getCurrentScale()) >= s.maxScale ) {
		s.er2.style.display = "block";
	} else {
		s.er2.style.display = "none";
	}
} else {

if( s.sno1 ) s.sno1.style.display = "block"; s.sno1flg = true;
if( s.sno2 ) s.sno2.style.display = "block"; s.sno2flg = true;

var _list = s.m.getLayerScaleList();
for( var key in _list ) {
	if( isNaN( parseInt(_list[key]) ) ) continue;
	if( _list[key] == 5000 ) {
		if(s.sno1) s.sno1.style.display = "none";
		s.sno1flg = false;
	}
	if( _list[key] == 10000 ) {
		if(s.sno2) s.sno2.style.display = "none";
		s.sno2flg = false;
	}
	if( min > s.m.getLayerId(_list[key]) ) min = s.m.getLayerId(_list[key]);
}
// プラス(+)、マイナス(-)ボタンの表示変更
if( s.m.getLayerId(s.m.getCurrentScale()) <= min ) {
	s.ee2.style.display = "block";
} else {
	s.ee2.style.display = "none";
}
if( s.m.getLayerId(s.m.getCurrentScale()) >= s.maxScale ) {
	s.er2.style.display = "block";
} else {
	s.er2.style.display = "none";
}
}
s.minScale = min;

return ;
};

// ズームバーを閉じている時の処理
	MapionMapControl.prototype.closebar = function(num) {
	var s = this;
var obj = null;
var scl = s.m.getCurrentScale();
if(s.sno1) s.sno1.style.display = "none";
if(s.sno2) s.sno2.style.display = "none";
for( var i=0; i<s.ccc.childNodes.length; i++ ) {
	if( s.ccc.childNodes[i].id == scl ) {
		s.ccc.childNodes[i+num].style.display = "none";
		obj = s.ccc.childNodes[i];
	}
}
s.closeMove( obj );
};

// 中心点の1500分の1、3000分の1の表示・非表示を判定
MapionMapControl.prototype.getHantei = function( _list ) {
//alert(_list);
var s = this;
if( s.sno1==null && s.sno2==null) return;
var min = 15;
if( s.sno1 ) s.sno1.style.display = "block"; s.sno1flg = true;
if( s.sno2 ) s.sno2.style.display = "block"; s.sno2flg = true;

for( var key in _list ) {
	if( isNaN( parseInt(_list[key]) ) ) continue;
	if( _list[key] == 5000 ) {
		// 2008.09.17
		//s.sno1.style.display = "none";
		if(s.sno1) s.sno1.style.display = "none";
		s.sno1flg = false;
	}
	if( _list[key] == 10000 ) {
		// 2008.09.17
		//s.sno2.style.display = "none";
		if(s.sno2) s.sno2.style.display = "none";
		s.sno2flg = false;
	}
	if( min > s.m.getLayerId(_list[key]) ) min = s.m.getLayerId(_list[key]);
}
s.minScale = min;
//alert("ok");
};


/** 距離画像設定 */
var tmp_m = {'5000':'/m_1500.gif',
			 '10000':'/m_3000.gif',
			 '25000':'/m_8000.gif',
			 '70000':'/m_21000.gif',
			 '250000':'/m_75000.gif',
			 '500000':'/m_150000.gif',
			 '1000000':'/m_300000.gif',
			 '3000000':'/m_900000.gif',
			 '5000000':'/m_5000000.gif',
			 '26000000':'/m_26000000.gif'
};


function MapionMapMeter( _m, top, left ) {
	// 地図を入れる
	this.m = null;
	this.m = _m;
	// 画像のパス
	this.path = "/sh/images/mcontrol";
	// 距離画像を入れるdiv
	this.e = null;
	this.e = document.createElement("DIV");
	this.e.style.position = "absolute";
    this.e.style.backgroundImage = "url('/sh/images/mcontrol/meter_bg.gif')";
    this.e.style.backgroundRepeat = "no-repeat";
	this.e.style.filter		= "alpha(opacity=80);";
	this.e.style.MozOpacity	= 0.8;
	this.e.style.Opacity	= 0.8;
	this.e.style.width	= "170px";
	this.e.style.height	= "38px";
	this.e.style.right	= "10px";
	this.e.style.bottom	= "32px";
	this.e.style.zIndex	= 15;
	// 距離画像
	this.i = null;
};


// 縮尺に合わせて距離画像を表示
MapionMapMeter.prototype.dispMeter = function() {
	var s = this;
	s.i = document.createElement("IMG");
	s.i.style.position = "absolute";
	s.i.style.right		= "1px";
	s.i.style.bottom	= "5px";
	s.i.style.zIndex	= 20;
	s.i.src = s.path + tmp_m[s.m.getCurrentScale()];
	s.e.appendChild(s.i);
};

// 縮尺変更時に距離画像を再表示
MapionMapMeter.prototype.changeMeter = function() {
	var s = this;
	s.i = null;
	s.e.innerHTML ='';
	s.i = document.createElement("IMG");
	s.i.style.position = "absolute";
	s.i.style.right		= "1px";
	s.i.style.bottom	= "5px";
	s.i.style.zIndex	= 20;
	s.i.src = s.path + tmp_m[s.m.getCurrentScale()];
	s.e.appendChild(s.i);
};


