/*   street.js  */

var moji_y=35.318975;

var moji_x=139.550924;

/*
var moji_y=35.691060;

var moji_x=139.755148;
*/

var currentLatLng = new GLatLng(moji_y,moji_x);
var syurui=1;
var bai=17;
var flg_sv=0;



var fovMarker; 

var fovIcon = new GIcon(G_DEFAULT_ICON);

var iconSize = 80;

var map;
var coosu=0;


var myPano;



var marker;


var htm="";

var htm_0="";

var htm_1="";



var htm_2="";

var flg=0;

var currentPitch=-4;
var currentYaw=264;
var myPOV = {yaw:currentYaw+0.64659986187695,pitch: currentPitch};






function initialize1() {



	if (GBrowserIsCompatible()) {



    map = new GMap2(document.getElementById("map_canvas"));



		  map.setCenter(new GLatLng(moji_y,moji_x), bai);



		if(syurui==1) 

			map.setMapType(G_NORMAL_MAP);

		if(syurui==2)

			map.setMapType(G_SATELLITE_MAP);

    //   map.addMapType(G_NORMAL_MAP);

  //   map.setMapType(G_HYBRID_MAP);

     map.addControl(new GLargeMapControl());





		  map.addControl(new GMapTypeControl());







		  map.addControl(new GScaleControl());



		  



				if(flg_sv==0) {

				

				

				



		  	svOverlay = new GStreetviewOverlay();



					map.addOverlay(svOverlay);

				

		  }



		  



		  var point = new GLatLng(moji_y,moji_x);



		  marker = new GMarker(point);



		  map.addOverlay(marker);



		



		  geocoder = new GClientGeocoder();



	

		 
		      initialize3();







		



		GEvent.addListener(map, "click", function(overlay,point) {



			if (point) {



			 map.clearOverlays();
			 
			 switch(Number(coosu)) {
                 case 0:break;
                 case 1:ka1(1);
                        break;
		 case 2:ka1(2);
                        break;
			     default:break;
			 
			 
			 }
			 



					moji_y= new Object;moji_y=String(point.y);

 				moji_x= new Object;moji_x=String(point.x);



					currentLatLng = new GLatLng(moji_y,moji_x);

					document.getElementById("ido").value = moji_y.substr(0,9) + "," + moji_x.substr(0,10);



				 if(flg_sv==0) {



				 	svOverlay = new GStreetviewOverlay();



				 	map.addOverlay(svOverlay);

				

				 }



				 



				 marker = new GMarker(point);



				 map.addOverlay(marker);


					myPOV = {yaw:currentYaw+0.64659986187695,pitch: currentPitch};

                                
				  initialize3();





			}







		});



		



		







          map.addControl(new google.maps.LocalSearch("pub-0178478916959940"), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,28)));








		}







}







GSearch.setOnLoadCallback(initialize1);



 



 



/*   ストリートビュー表示 */	



function initialize3() {



	  myPano = new GStreetviewPanorama(document.getElementById("pano"));



//	  myPano.setLocationAndPOV(marker.getLatLng(), null);



	  fenwayPark = new GLatLng(moji_y,moji_x);



//      myPOV = {yaw:370.64659986187695,pitch:-5};



			myPano.setLocationAndPOV(fenwayPark, myPOV);

			

//		fovIcon.image = "http://www.vegashotelhunt.com/Vegas-Vision/demoicon.php?yaw=180";
		fovIcon.image = "img/icn0.png";
		fovIcon.iconSize = new GSize(iconSize, iconSize);

		fovIcon.iconAnchor = new GPoint(iconSize/2, iconSize); //anchor in the middle

		fovIcon.shadow = null;

		fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false});

		

			GEvent.addListener(myPano, "initialized", handleInitialized);

            GEvent.addListener(myPano, "yawchanged", handleYawChange);
            GEvent.addListener(myPano, "pitchchanged", handlePitchChange);

   GEvent.addListener(myPano, "error", handleNoFlash);



}



function handleInitialized(location) {

		currentLatLng = location.latlng;	

         placeFovMarker();			 

		return;	

    }
    
    
    function handlePitchChange(ptc) {

        currentPitch = Math.round(ptc);	
        document.getElementById("pch").value = currentPitch;

         placeFovMarker();			 

		return;	

	}

	

	function handleYawChange(yaw){

        currentYaw = Math.round(yaw);
        document.getElementById("ya").value = currentYaw;
  
		placeFovMarker();

		return;

	}

	

	

	function placeFovMarker(){

	

	 moji_y= new Object;moji_y=String(currentLatLng.y);

 	moji_x= new Object;moji_x=String(currentLatLng.x);

		document.getElementById("ido").value = moji_y.substr(0,9) + "," + moji_x.substr(0,10);

		

		map.removeOverlay(fovMarker);

//		fovIcon.image = "http://www.vegashotelhunt.com/Vegas-Vision/demoicon.php?yaw="+currentYaw+"&rand="+Math.random();	

		icn_dsp();
		fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false});

		map.addOverlay(fovMarker);

	

		map.removeOverlay(marker);

		marker = new GMarker(currentLatLng);

		map.addOverlay(marker);

		

		

		return;

	}

function icn_dsp() {
 
 // 左上が原点
  if( currentYaw >=0 && currentYaw < 18 ) {
     fovIcon.image = "img/icn0.png";
//     fovIcon.iconSize = new GSize(80,80);
     fovIcon.iconAnchor = new GPoint(40,80);
  }
  if( currentYaw >= 18 && currentYaw < 54 ) {
     fovIcon.image = "img/icn36.png";
//     fovIcon.iconSize = new GSize(80,80);
     fovIcon.iconAnchor = new GPoint(30,80);
  }
  if( currentYaw >= 54 && currentYaw < 81 ) {
     fovIcon.image = "img/icn72.png";
//     fovIcon.iconSize = new GSize(80,80);
     fovIcon.iconAnchor = new GPoint(0,40);
  }
  if( currentYaw >= 81 && currentYaw < 99 ) {
     fovIcon.image = "img/icn90.png";
//     fovIcon.iconSize = new GSize(80,80);
     fovIcon.iconAnchor = new GPoint(0,40);
  }
 if( currentYaw >= 99 && currentYaw < 126 ) {
     fovIcon.image = "img/icn108.png";
//     fovIcon.iconSize = new GSize(80,80);
     fovIcon.iconAnchor = new GPoint(0,40);
  }
   if( currentYaw >= 126 && currentYaw < 162 ) {
     fovIcon.image = "img/icn144.png";
 //    fovIcon.iconSize = new GSize(80,80);
     fovIcon.iconAnchor = new GPoint(30,0);  
    } 
   if( currentYaw >= 162 && currentYaw < 198 ) {
      fovIcon.image = "img/icn180.png"; 
//      fovIcon.iconSize = new GSize(80,80);
      fovIcon.iconAnchor = new GPoint(40,0);
    }
    if( currentYaw >= 198 && currentYaw < 234 ) {
       fovIcon.image = "img/icn216.png";
 //      fovIcon.iconSize = new GSize(80,80);
       fovIcon.iconAnchor = new GPoint(40,0); 
     }
    if( currentYaw >= 234 && currentYaw < 259 ) {
       fovIcon.image = "img/icn252.png";
  //     fovIcon.iconSize = new GSize(80,80);
       fovIcon.iconAnchor = new GPoint(80,40);
    }
    
    if( currentYaw >= 259 && currentYaw < 279 ) {
       fovIcon.image = "img/icn270.png";
  //     fovIcon.iconSize = new GSize(80,80);
       fovIcon.iconAnchor = new GPoint(80,40);
    }
    
    if( currentYaw >= 279 && currentYaw < 306 ) {
       fovIcon.image = "img/icn288.png";
  //     fovIcon.iconSize = new GSize(80,80);
       fovIcon.iconAnchor = new GPoint(80,40);
    }
    
    
    if( currentYaw >= 306 && currentYaw < 342 ) {
       fovIcon.image = "img/icn324.png";
 //      fovIcon.iconSize = new GSize(80,80);
       fovIcon.iconAnchor = new GPoint(40,80);
    }
    
    if( currentYaw >= 342 && currentYaw < 361 ) {
       fovIcon.image = "img/icn0.png";
//       fovIcon.iconSize = new GSize(80,80);
       fovIcon.iconAnchor = new GPoint(40,80);
    }
    
 }

	



/* エラー処理 */	



function handleNoFlash(errorCode) {



      if (errorCode == 603) {



        alert("Error: フラッシュプレーヤーがOFFの様です。");



        return;



      }



}



	



	

/* 青枠　表示／非表示  */



function sen_kesu() {



	if(flg_sv==0) {



		flg_sv=1;

		

		

	map.clearOverlays();



						

		map.removeOverlay(fovMarker);

		icn_dsp();
		fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false});

		

		map.addOverlay(fovMarker);

		map.addOverlay(marker);

	



		document.myfm.b1.value="青枠を表示　";



	}



	else {



		flg_sv=0;



		map.removeOverlay(fovMarker);


		icn_dsp();
		fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false});

		map.addOverlay(fovMarker);

		

		map.addOverlay(svOverlay);

         map.addOverlay(marker);

		svOverlay = new GStreetviewOverlay();

	



		document.myfm.b1.value="青枠を非表示";



	}





}

function city(ido,keido,kakudo,takasa,gazou,kakudai) {

		moji_y=ido;

		moji_x=keido;

		syurui=gazou;
		bai=kakudai;
		currentYaw=kakudo;
		
		currentLatLng = new GLatLng(moji_y,moji_x);
		myPOV = {yaw:currentYaw+0.64659986187695,pitch:takasa};
        currentPitch=takasa;

	 initialize1();

}












function zm(zom) {

 //  map.setCenter(new GLatLng(moji_y,moji_x),15);
   bai=zom; 
   initialize1();
   }



 function draw(lat1, lng1, lat2, lng2){
 
       
 
          var points = [];
            points[0] = new GLatLng(lat1, lng1);
               points[1] = new GLatLng(lat2, lng2);
   /*               points[2] = new GLatLng(36.031, 139.00);*/

                    var polyline = new GPolyline(points, "#FF0000", 2, 1);

                      map.addOverlay(polyline);
                      
                      


}




 function erase(){
           map.clearOverlays();
            
         
        }


function addAddressToMap_1(response) {



//	map.clearOverlays();

// 2008.5.5削除



		if(syurui==1) 



			map.setMapType(G_NORMAL_MAP);



		if(syurui==2)



			map.setMapType(G_SATELLITE_MAP);







      if (!response || response.Status.code != 200) {



        alert("Sorry, we were unable to geocode that address");



      } else {



        place = response.Placemark[0];



        point = new GLatLng(place.Point.coordinates[1],



							place.Point.coordinates[0]);



		



	map.setCenter(point,bai);

 /*

      marker = new GMarker(point);



       map.addOverlay(marker);

 */

        map.openInfoWindowHtml(map.getCenter(),htm_0+  '<br />' + htm_1 + '<br />' + htm_2);

                htm_0="";

		htm_1="";



		htm_2="";

		





      }
      




}


function findLocation_1(hm0,address,hm1,hm2,kakudai,gazou) {

          htm_0=hm0;

	  htm_1=hm1;



	  htm_2=hm2;



	  bai=kakudai;



	  syurui=gazou;


	  geocoder.getLocations(address, addAddressToMap_1);



}


function map_sel(which) {
	
	switch(Number(which)) {
	  		case 1:
				location.href="#map_canvas";
				break;
		
			default:
				break;
	}


}


/*   鎌倉　コース１　*/
function ka1(cose_no) {


         coosu=cose_no;
         
   
                 switch(cose_no) {
		 	case 1:
     draw(35.336956,139.544992,35.334470,139.547771);
     draw(35.334470,139.547771,35.333814,139.549208);
     draw(35.333814,139.549208,35.332194,139.550410);
     draw(35.332194,139.550410,35.331687,139.550989);
     draw(35.331687,139.550989,35.329455,139.550238);
     draw(35.329455,139.550238,35.328536,139.550389);
     draw(35.328536,139.550389,35.327135,139.549198);
     draw(35.327135,139.549198,35.327652,139.547288);
     draw(35.327652,139.547288,35.328509,139.545764);
     draw(35.327652,139.547288,35.327179,139.546945);
     draw(35.327179,139.546945,35.326382,139.545121);
     draw(35.326382,139.545121,35.325883,139.544509);
     draw(35.325883,139.544509,35.326522,139.543232);
     draw(35.326522,139.543232,35.325735,139.542632);
     draw(35.325735,139.542632,35.324859,139.543404);
     draw(35.324859,139.543404,35.323546,139.542911);
     draw(35.323546,139.542911,35.320517,139.542632);
     draw(35.320517,139.542632,35.319099,139.549884);
     
     
     break;
     			default:
				break;
			case 2:
				 draw(35.336903,139.545823,35.335415,139.547331);
                                 draw(35.335415,139.547331,35.334671,139.548173);
                                 draw(35.334671,139.548173,35.335533,139.549782);
				 draw(35.335533,139.549782,35.335551,139.550576);
				 draw(35.335551,139.550576,35.335048,139.551354);
				 draw(35.334671,139.548173,35.333779,139.549219);
				 draw(35.333779,139.549219,35.331704,139.551000);
				 draw(35.331704,139.551000,35.331013,139.552459);
				 draw(35.331013,139.552459,35.329043,139.554187);
				 draw(35.329043,139.554187,35.327730,139.556128);
				 draw(35.327730,139.556128,35.324369,139.553854);
				 draw(35.324369,139.553854,35.323669,139.554927);
				 draw(35.323669,139.554927,35.318889,139.551901);
				 draw(35.318889,139.551901,35.319012,139.550904);
				
				
				 break;
     		 }
		 
     map_sel(1);

}





