/*   street.js  */

var moji_y=35.691226;

var moji_x=139.755684;

/*
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 myPano;



var marker;




var currentPitch=4;
var currentYaw=108;
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();



					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();
   }
   
