var p0=Array(),p1=Array(),q=Array(),course=Array(),mrk=Array(),wcourse=Array() ;var map,cyclist,ctime=-10,stp=1,cpos=0,blewup=-2,intv=1,zml=13,mpt=G_NORMAL_MAP,fr1,to1,showed=0,showedi=Array(),maxov,once=0,qi=-1 ;var icon_bike = new GIcon();icon_bike.image = "../images/bike0.png";icon_bike.iconSize = new GSize(21,17);icon_bike.iconAnchor = new GPoint(11,9);icon_bike.infoWindowAnchor = new GPoint(11,9);var icon_marker = new GIcon();icon_marker.image = "../images/marker.png";icon_marker.iconSize = new GSize(10,10);icon_marker.iconAnchor = new GPoint(5,5);icon_marker.infoWindowAnchor = new GPoint(0,9);function initCPJ(){
//	alert("initCPJ") ;
GEvent.addListener(map,'click',function(marker,point){if (marker){}else{nearest(point) ;}}) ;GEvent.addListener(map,'move',function(){var z = 17 - map.getZoom() ;var x = (map.getCenterLatLng()).x ;var y = (map.getCenterLatLng()).y ;var rectObj = map.getBounds() ;var bfr = rectObj.getSouthWest()+','+rectObj.getNorthEast() ;});}function pushTrack(fr,to,color,lat,lng,title,link){if ( fr == 0) {var ln = 5 ;fr1 = fr*10 ; to1 = to*10 ;}else{var ln = 4 ;}q.push(Array(fr,to,color,lat,lng,title,link,ln)) ;}function makeTrack(i){var fr=q[i][0]; var to=q[i][1];var color=q[i][2];var lat=q[i][3];var lng=q[i][4];var title=q[i][5];var link=q[i][6];var ln=q[i][7];course[i]  = new GPolyline(p0.slice(fr,to),color,ln,0.70) ;wcourse[i] = new GPolyline(p0.slice(fr,to),'#FFFFFF',ln,0.70) ;var wpt = new GPoint(lng,lat) ;if(i==0){mrk[i]    = new GMarker(wpt, {'icon':icon_bike, 'title':title}) ;cyclist   = mrk[i] ;}else{mrk[i]    = new GMarker(wpt, {'icon':icon_marker, 'title':title}) ;}map.addOverlay(mrk[i]) ;showedi[i] = 1 ;GEvent.addListener(mrk[i],'mouseover',function(){map.addOverlay(wcourse[i]);}) ;GEvent.addListener(mrk[i],'mouseout',function(){map.removeOverlay(wcourse[i]) ;map.addOverlay(course[i]);}) ;GEvent.addListener(mrk[i],'click',function(){if (i != 0 ){var w = window.open(link, '_self');}else{if ( blewup == ctime ){blowdown() ;}else{blowup() ;}}}) ;if(i==0){map.addOverlay(course[i]);makeNeighbours() ;}}function makeNeighbours(){if ( showed == 0) {window.setTimeout('showNeighbours(1)', 50);} else {for( i=1; i<q.length ; i++){map.removeOverlay(course[i]) ;map.removeOverlay(mrk[i]) ;showedi[i] = 0 ;}if(document.getElementById('disp')) document.getElementById('disp').innerHTML = "周辺コース表示" ;showed = 0 ;}}function showNeighbours(j){if(j<q.length){makeTrack(j) ;if(j<=maxov) map.addOverlay(course[j]);}else if((showedi[0]==1)&&(j == q.length)){map.removeOverlay(course[0]) ;map.addOverlay(wcourse[0]);}else if(j == (q.length+1)){map.removeOverlay(wcourse[0]);map.addOverlay(course[0]);}if(j<q.length){j++ ;str = 'showNeighbours('+j+')' ;window.setTimeout(str, 10) ;}else if(showed == 0){if((showedi[0]==1)&&(j<=(q.length+1))){j++ ;str = 'showNeighbours('+j+')' ;window.setTimeout(str, 1000) ;}else{showed = 1 ;if(document.getElementById('disp')) document.getElementById('disp').innerHTML = "周辺コース非表示" ;}}}function nearest(point){mindis = dist2(p0[0],point) ;ipos = 0 ;qi   = -1 ;for(i=0; i<q.length ; i++){if(showedi[i]!=1) continue ;for(j=q[i][0] ; j<q[i][1] ; j++){dis = dist2(p0[j],point) ;if ( dis < mindis ) {mindis = dis ;ipos   = j ;qi     = i ;}}}dist = Math.sqrt(mindis) ;if (dist < 10000) {if (ctime != ipos) {showCyclist(ipos*10) ;}}return qi ;}function dist2(point1,point2){x = (point1.y - point2.y) * (110570+(1700-570)*point1.y/90) ;y = (point1.x - point2.x) * 111320 * Math.cos(3.1416*point1.y/180) ;return (x*x+y*y) ;}function startCyclist(val){if(val){val = 4 ;}else{val = 1 ;}if(intv!=val){if(stp==0){intv = val ;return(true) ;}intv = val ;}if (stp == 0){if (cpos != 0){stopCyclist() ;}else{zoomup() ;continueCyclist() ;}}else{stp = 0 ;zoomup() ;blowdown() ;continueCyclist() ;}}function continueCyclist(){qi = 0 ;if(stp==0){if((ctime<fr1)||(to1 < ctime)){ipos = fr1-10 ;}else{ipos = ctime ;}if(ipos+10 >= to1){window.setTimeout('resetCyclist()', 1000);}else{if((ctime>=0)&&(ctime+10 < to1)){var zm = map.getZoom() ;var speed = 0.125 / intv ;for(j=17 ; j>zm ; j-- ){speed = speed * 2 ;}itime = ctime - ctime%10 ;pt1 = P0(itime+10);pt0 = P0(itime) ;d = Math.floor(Math.sqrt(dist2(pt1,pt0))) ;var wtime = d / speed ;}else{wtime = 300 ;}if((ipos<-1)||(wtime<400)){showCyclist(ipos+10) ;}else{showCyclist(ipos+1) ;wtime = wtime / 10 ;if(wtime > 400) wtime = 400 ;}window.setTimeout('continueCyclist()', wtime);}}}function showCyclist(ipos){var istat = 0, new_cyclist = 0 ;if (blewup>=0){blowdown() ;istat = 1 ;}if (ctime != ipos){cpos = new GLatLng(p0y(ipos),p0x(ipos)) ;mrk[qi].setPoint(cpos) ;cyclist = mrk[qi] ;if(showed[qi]==0){map.addOverlay(cyclist);showed[qi] = 1 ;}if(qi == 0) ctime = ipos ;var rect = map.getBounds() ;var sw   = rect.getSouthWest() ;var ne   = rect.getNorthEast() ;if(rect.contains(cpos)){}else{map.setCenter(cpos) ;}if(document.getElementById('altitude')){var zm = map.getZoom() ;var h  = (ipos - ipos%10)/10 ;document.getElementById('altitude').innerHTML = " 現在の標高: "+p1[h]+" m";}if(istat == 1) blowup() ;}}function resetCyclist(){if(cpos != 0){cpos = 0 ;ctime=-1;stp  = 1;document.getElementById('zoom').innerHTML = "" ;if(document.getElementById('altitude')) document.getElementById('altitude').innerHTML = "" ;}}function stopCyclist(){stp = 1 ;}function p0x(ipos){var s = ipos % 10 ; var t  = (ipos - s)/10 ;return (p0[t].x*(10-s) + p0[t+1].x*s)/10 ;}function p0y(ipos){var s = ipos % 10 ; var t  = (ipos - s)/10 ;return (p0[t].y*(10-s) + p0[t+1].y*s)/10 ;}function P0(ipos){return (new GPoint(p0x(ipos),p0y(ipos))) ;}function startPoint(){qi = 0 ;showCyclist(fr1) ;window.setTimeout('zoomup()', 50);if(stp==1) blowup() ;}function endPoint(){showCyclist(to1-10) ;zoomup() ;blowup() ;}function zoomup(){if(once == 1) return ;once = 1 ;var zm = map.getZoom() ;if(zm < 13){map.setZoom(14) ;}}function blowup(){cyclist.showMapBlowup({zoomLevel:zml,mapType:mpt,noCloseOnClick:true}) ;blewup = ctime ;}function blowdown(){blewup >= 0 ;map.closeInfoWindow() ;if(document.getElementById('zoom')) document.getElementById('zoom').innerHTML = "" ;blewup = -2 ;}function zmup(){if ( zml < 17 ){zml ++ ;}blowup() ;}function zmdown(){if ( zml > 1 ){zml -- ;}blowup() ;}function changeMap(parm){mpt = parm ;blowup() ;}function GetSize(){var ua = navigator.userAgent;var nWidth, nHeight;var nHit = ua.indexOf("MSIE");var bIE = (nHit >=  0);var bVer6 = (bIE && ((ua.substr(nHit+5, 1) == "6")||(ua.substr(nHit+5, 1) == "7")));var bStd = (document.compatMode && document.compatMode=="CSS1Compat");if (bIE) {if (bVer6 && bStd) {nWidth = document.documentElement.clientWidth;nHeight = document.documentElement.clientHeight;} else {nWidth = document.body.clientWidth;nHeight = document.body.clientHeight;}} else {nWidth = window.innerWidth;nHeight = window.innerHeight;}return(Array(nWidth,nHeight)) ;}function ChangeSize(){
//	  alert("ChangeSize") ;
var size = GetSize() ;var nWidth  = size[0] ;var nHeight = size[1] ;if(nWidth < 827+195){var width = 800 ;}else{var width = nWidth - 27 -195 ;}if(nHeight < 704){var height = 600 ;}else{var height = nHeight - 104 ;}document.getElementById("map").style.width  = width ;document.getElementById("map").style.height = height ;}