var unit_no;
if ( unit_no == null ) {
	unit_no = 0;
}

var loop_flg;
var myPano = Array();
var myPOV = Array();
var panoList = new Object();
var iframePano;

var _ggmap_apikey = "";

if ( unit_no == 0 ) {
	try {
		_ggmap_apikey = ggmap_apikey;
	} catch(e){  }
}

var myView_target;
var src_user;

if ( _ggmap_apikey != "" ) {
	src_user = "http://maps.google.com/maps?file=api&v=2&sensor=false&key="+_ggmap_apikey;
	document.write(
		'<' +
		'script charset="utf-8" src="' + 
		src_user + 
		'"' + 
		' type="text/javascript"><' + 
		'/script>'
	);
	_ggmap_apikey = "";
}

function changePano(obj,no) {
	var wPov = myPano[no].getPOV();
	wPov.zoom = 0;
	if (window.navigator.userAgent.toLowerCase().indexOf("opera") > -1) {
		myPano[no].panTo(wPov);
	}
	else {
		myPano[no].setPOV(wPov);
	}

	var newPlace =
		new GLatLng(
			panoList[obj.value][0],
			panoList[obj.value][1]
		);
	myPOV[no].yaw	= panoList[obj.value][2];
	myPOV[no].pitch	= panoList[obj.value][3];
	myPOV[no].zoom	= 0;
	myPano[no].setLocationAndPOV(newPlace, myPOV[no]);
}

function handleNoFlash(errorCode) {
	if (errorCode == 603) {
//		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
	}
}

function handleUnload_createPano() {

	GUnload();
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		try {
			CollectGarbage();
		}
		catch(e) {
		}
	}
}

if (window.attachEvent){
	window.attachEvent('onunload', handleUnload_createPano);
}
else {
	window.addEventListener('unload', handleUnload_createPano, false);
}

function createPano(w,h,s) {

	var key;
	var save="";
	unit_no++;

str="";
str+="<div name=\"pano"+unit_no+"\" id=\"pano"+unit_no+"\"";
str+=" style=\"width: "+w+"px; height: "+h+"px\"></div> \n";
str+="<select id=\"combo"+unit_no+"\" onChange='changePano(this,"+(unit_no-1)+")'> \n";

	loop_flg = false;
	for (key in panoList)   {
		if ( s == key ) {
			loop_flg = true;
		}
		if ( loop_flg ) { 
			if ( save == '' ) {
				save = key;
			}
			str+="<option value=\""+key+"\">"+panoList[key][4]+"</option> \n";
		}
	}

str+="</select> \n";
str+=" ";

	document.write(str);

	myPano[(unit_no-1)] = new GStreetviewPanorama(document.getElementById("pano"+unit_no));
	var fenwayPark = new GLatLng(panoList[save][0],panoList[save][1]);
	myPOV[(unit_no-1)] = {yaw:panoList[save][2],pitch:panoList[save][3],zoom:0};
	myPano[(unit_no-1)].setLocationAndPOV(fenwayPark, myPOV[(unit_no-1)]);

	GEvent.addListener(myPano[(unit_no-1)], "error", handleNoFlash);

	document.getElementById("combo"+unit_no).selectedIndex = 0;
}

function createPanoArea(w,h,a,b,c,d) {

	unit_no++;

	var appVersion = window.navigator.appVersion.toLowerCase();

	if (appVersion.indexOf("msie 5.0") > -1) {

str="";
str+="<iframe \n";
str+="	id=\"pano"+unit_no+"\" \n";
str+="	frameborder=\"no\" \n";
str+="	scrolling=\"no\" \n";
str+="	width=\""+ (w+50) +"\" \n";
str+="	height=\""+ (h+50) +"\" \n";
str+="	src=\"http://winofsql.jp/ggv_pano_basic.php?w="+w+"&h="+h+"&a="+a+"&b="+b+"&c="+c+"&d="+d+"\" \n";
str+="></iframe> \n";
		document.write(str);

		document.write(
			'<' +
			'script ' + 
			' type="text/javascript">' + 
			'try {document.getElementById("'+'pano'+unit_no+'").contentWindow.location.reload();}catch(e){}' + 
			'<' + 
			'/script>'
		);

	}
	else {


str="";
str+="<div name=\"pano"+unit_no+"\" id=\"pano"+unit_no+"\"";
str+=" style=\"width: "+w+"px; height: "+h+"px\"></div> \n";

		document.write(str);

		myView_target = new GStreetviewPanorama(document.getElementById("pano"+unit_no));
		var fenwayPark = new GLatLng(a,b);
		var myPanoView = {yaw:c,pitch:d,zoom:0};
		myView_target.setLocationAndPOV(fenwayPark, myPanoView);

		GEvent.addListener(myView_target, "error", handleNoFlash);

	}

	if ( arguments.length == 7 ) {

		if ( arguments[6] == 1 ) {

str="";
			if (appVersion.indexOf("msie 5.0") > -1) {
				str+="<br>";
			}
str+="<a style='font-size:12px;text-decoration:none;color:navy;' href=\"http://maps.google.co.jp/maps?q="+a+",+"+b+"&iwloc=A&hl=ja\" target=\"_blank\">&#71;&#111;&#111;&#103;&#108;&#101;&#32;&#77;&#97;&#112;&#32;&#12391;&#34920;&#31034;&#12377;&#12427;</a> ";
			document.write(str);
		}
	}
}

function createPanoSet(w,h,url) {

	var opt;

	if ( arguments.length == 4 ) {
		opt = "&" + arguments[3];
	}
	else {
		opt = ""
	}

	url = encodeURIComponent(url);

str="";
str+="<iframe \n";
str+="	frameborder=\"no\" \n";
str+="	scrolling=\"no\" \n";
str+="	width=\""+(w+50)+"\" \n";
str+="	height=\""+(h+50)+"\" \n";
str+="	src=\"http://winofsql.jp/ggv_pano_view.php?w="+w+"&h="+h+"&id="+url+opt+"\" \n";
str+="></iframe> ";

	document.write(str);

}

