$( function() {

	$( "#selDistirctSiGun" ).change( function() {
		var areaKey = window.document.getElementById( "selDistirctSiGun" ).value;
		var params = "method=getTravelList&prmAreaKey="+ encodeURIComponent( areaKey );
		new ajax.xhr.Request( "explore0101.do", params, setSelectBox, "GET", "selTravelList" );
		
	});
	
	$( "#selDistirctSido" ).change( function() {
		var distirctSido = window.document.getElementById( "selDistirctSido" ).value;
		var params = "method=getSggList&prmSido="+ encodeURIComponent( distirctSido );
		new ajax.xhr.Request( "explore0101.do", params, setSelectBox, "GET", "selDistirctSiGun" );
	});
	
	$( "#imgSubmit" ).click( function() {
		var tourCode = window.document.getElementById( "selTravelList" ).value;
		if( tourCode != undefined && tourCode != "" ) {
			window.document.forms[ "frmTravelInfo" ].method.value = "getVrInfo";
			window.document.forms[ "frmTravelInfo" ].prmTourCode.value = window.document.getElementById( "selTravelList" ).value;
			window.document.forms[ "frmTravelInfo" ].submit();
			
			var selText = window.document.getElementById( "selTravelList" ).options[window.document.getElementById( "selTravelList" ).selectedIndex].text;
			window.document.getElementById( "subTitle" ).style.display = "block";
			window.document.getElementById( "subTitle" ).innerHTML = selText;
			
			window.document.getElementById( "vrInfo" ).style.display = "block";
			window.document.getElementById( "imgNoSearch" ).style.display = "none";
		} else {
			alert( "답사지를 선택하세요." );
		}
	}).css( "cursor", "pointer" );
	
	$( "#goRight" ).click( function() {
		moveList2('next', 'relative_pic', 5, 5);
	}).css( "cursor", "pointer" );
	
	$( "#goLeft" ).click( function() {
		moveList2('prev', 'relative_pic', 5, 5);
	}).css( "cursor", "pointer" );
	
});

function setSelectBox( req ) {
	
	if ( req.readyState == 4 ) {
		if ( req.status == 200 ) {   
			xmlDoc = req.responseXML;			
			var select = xmlDoc.getElementsByTagName( "select" );			
			document.getElementById( this ).length = 0;
			if ( select.length > 0 ) {
				for( var i=0; i<select.length; i++ ) {
					var node = document.createElement( "option" );
					var text = document.createTextNode( select[i].getElementsByTagName( "text" )[0].childNodes[0].nodeValue );
					node.setAttribute( "value", select[i].getElementsByTagName( "value" )[0].childNodes[0].nodeValue );
					node.appendChild( text );
					var result = document.getElementById( this );
					result.appendChild( node );				
				}
			} else {
//				var node = document.createElement( "option" );
//				var text = document.createTextNode( unescape( "����� ������ ����ϴ�" ) );
//				node.appendChild( text );
//				var result = document.getElementById( this );
//				result.appendChild( node );		
			}
		}
	}
}

/*
 * �̹����� ���ڳ� VR������� ����Ʈ�� Ŭ�� �ÿ� ���������� ��ġ�� ǥ��.
 * tourCode : ������ �ڵ�
 * mapX, mapY : �������� ��ǥ
 */
function showVR( tourCode, mapX, mapY ) {
	window.document.forms[ "frmTravelImgList" ].method.value = "getVrImgList";
	window.document.forms[ "frmTravelImgList" ].prmTourCode.value = tourCode;
	window.document.forms[ "frmTravelImgList" ].submit();
	
	window.document.forms[ "frmTravelInfo" ].method.value = "getVrInfo";
	window.document.forms[ "frmTravelInfo" ].prmTourCode.value = tourCode;
	window.document.forms[ "frmTravelInfo" ].submit();
	
	parent.document.getElementById( "vrImgList" ).style.display = "block";
	parent.document.getElementById( "vrInfo" ).style.display = "block";
}

function showVRpic( tourCode, panoramaCode ) {
	
	window.document.forms[ "frmTravelInfo" ].method.value = "getVrInfo";
	window.document.forms[ "frmTravelInfo" ].target = "ifrmVrInfo";
	window.document.forms[ "frmTravelInfo" ].prmTourCode.value = tourCode;
	window.document.forms[ "frmTravelInfo" ].prmPanoramaCode.value = panoramaCode;
	window.document.forms[ "frmTravelInfo" ].submit();
	
}

function openPic( imgSrc, imgTitle ) {
	window.document.forms[ "frmTravelInfo" ].action = "/explore/explore_01/popImage.jsp";
	window.document.forms[ "frmTravelInfo" ].target = "popImage";
	window.document.forms[ "frmTravelInfo" ].prmImgSrc.value = imgSrc;
	window.document.forms[ "frmTravelInfo" ].prmImgTitle.value = imgTitle; 
	window.open( "", 'popImage','location=no, directories=no,resizable=no,status=no,toolbar=no,menubar=no, left=0, top=0, scrollbars=no, width=780, height=640' );
	window.document.forms[ "frmTravelInfo" ].submit();
}
//git
function showVRpic1( tourCode, panoramaCode ) {
	
	parent.document.forms[ "frmTravelInfo" ].method.value = "getVrImgList";
	parent.document.forms[ "frmTravelInfo" ].target = "ifrmVrImgList";
	parent.document.forms[ "frmTravelInfo" ].prmTourCode.value = tourCode;
	parent.document.forms[ "frmTravelInfo" ].prmPanoramaCode.value = panoramaCode;
	parent.document.forms[ "frmTravelInfo" ].submit();
	
}
