window.onresize = resizeWindow;
var myPano;   
var panoClient;

var GmapHscall = 1.0;

/*====================================
* ウィンドウサイズ変更イベントハンドラ
*
*=====================================*/
function resizeWindow(){
	//alert("ウィンドウが変更されました");
	newSize();
}

/*====================================
* 初期処理
*
*=====================================*/
function init(){
	initGMap();
	newSize();
}

/*====================================
* ウィンドウサイズ取得
*
*=====================================*/
function getWindowSize(){
	var t_width;
	var t_height;
	if(document.all){
		//t_width = document.body.clientWidth;
		//t_height = document.body.clientHeight;

		t_width = document.documentElement.clientWidth;
		t_height = document.documentElement.clientHeight;
	}else if(document.getElementById){
		t_width = window.innerWidth;
		t_height = window.innerHeight;
	}
	var obj = new Object();
	obj.w = t_width;
	obj.h = t_height;
	
	return obj;
}

/*====================================
* 全体のサイズ変更
*
*=====================================*/
function newSize() {
	var obj = getWindowSize();


	/*if(document.all && !document.getElementById) {
		document.all['flashArea'].style.pixelWidth = datoX;
		document.all['flashArea'].style.pixelHeight = datoY;
	}else{
		document.getElementById("flashArea").style.width = datoX + 'px';
		document.getElementById("flashArea").style.height = datoY + 'px';
	}
	*/
	//alert(datoX);
	
	var blockWidth = obj.w + 'px';
	var flashHeight = obj.h * GmapHscall;
	var stHeight = obj.h - flashHeight -2;
	if (stHeight < 0){
		stHeight = 0;
	}
	
	document.getElementById("chizuyado_div").style.width = blockWidth;
	document.getElementById("chizuyado_div").style.height = flashHeight + 'px';

	document.getElementById("pano").style.width = blockWidth;
	document.getElementById("pano").style.height = stHeight + 'px';
	
	myPano.checkResize();
}

/*====================================
* 以下、GoogleMapコントロール
*
*=====================================*/

//ビュー初期化
function initGMap() {


	//var myLatLng = new GLatLng(35.658918,139.745857);
	//var myPOV = {yaw:180,pitch:0};

	myPano = new GStreetviewPanorama(document.getElementById("pano"));
	//myPano.setLocationAndPOV(myLatLng, myPOV);
	
	panoClient = new GStreetviewClient();
	//panoClient.getNearestPanorama(myLatLng, showPanoData);
	
	//新しい場所に移動した場合
	GEvent.addListener(myPano, "initialized", changePanorama);
	//ヨー角度変更イベント
	GEvent.addListener(myPano, "yawchanged", changeYaw);
	
}
//swfに送信（位置変更時の緯度経度）
function changePanorama(location) {
	//alert("changePanorama");
	//var pov = myPano.getPov();
	if(navigator.appName.indexOf("Microsoft") != -1){
		//window.ChizuYado.setMarker(location.lat,location.lng, pov.yaw);
		window.ChizuYado.setMarker(location.lat,location.lng);
	}else{
		//document.ChizuYado.setMarker(location.lat,location.lng, pov.yaw);
		document.ChizuYado.setMarker(location.lat,location.lng);
	}
	
}
//swfに送信（ヨー角度変更時のヨー角度）
function changeYaw(yaw) {
	//alert("changeYaw");
	
	if(navigator.appName.indexOf("Microsoft") != -1){
		window.ChizuYado.setMarkerYaw(yaw);
	}else{
		document.ChizuYado.setMarkerYaw(yaw);
	}
	
}
//swfに送信（エラーメッセージ）
function errorMsg(msg) {
	if(navigator.appName.indexOf("Microsoft") != -1){
		window.ChizuYado.sViewErrorMsg(msg);
	}else{
		document.ChizuYado.sViewErrorMsg(msg);
	}
}
//移動
function showPanoData(panoData) {
	if (panoData.code != 200) {
		//GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
		//alert("指定された地点のストリートビューは存在しません。");
		//document.getElementById("msgBox").innerHTML = '<div id="msg">地図上で指定された地点のストリートビューは存在しません。</div>';
		errorMsg("この地点のストリートビューはありません");
		return;
	}
	myPano.setLocationAndPOV(panoData.location.latlng);
	
}
//swfから受信（GPS設定）
function setPanorama( lat, lng ) {
	
	panoClient.getNearestPanorama(new GLatLng(lat, lng), showPanoData);
}

//swfから受信（）
function setSViewVisible(flg) {
	if(flg == true){
		GmapHscall = 0.6;
	}else{
		GmapHscall = 1.0;
	}
	newSize();
	
	if(flg == true){
		if(navigator.appName.indexOf("Microsoft") != -1){
			window.ChizuYado.completeSViewVisible();
		}else{
			document.ChizuYado.completeSViewVisible();
		}
	}
}

