
//---------------------------------
//
var oStreetView = {
	m_nWidth		:	400,
	m_nHeight		:	300,
	m_nX			:	0,
	m_nY			:	0,
	m_oElement		:	null,
	m_oCoverElement	:	null,
	m_oStreetView	:	null,
	m_oService		:	null,
	m_isLoad		:	false,
	m_isShow		:	false
};
	
//---------------------------------
//
oStreetView.Init = function()
{
	if( typeof( google ) == 'undefined' )
	{
		oStreetView.m_isLoad = false;
        return;
	}
	
	//-----
	oStreetView.m_oElement = document.getElementById( 'StreetView' ); 
	oStreetView.m_oElement.style.position	= 'absolute';
	oStreetView.m_oElement.style.zIndex		= 11; 
	
	//-----
	oStreetView.m_oStreetView = new google.maps.StreetViewPanorama ( oStreetView.m_oElement );
	
	//-----
	oStreetView.m_oService = new google.maps.StreetViewService();
	
	oStreetView.m_isLoad = true;
	
	setTimeout(function()
	{
		oStreetView.AddPos( -122.084101, 37.421137, 0 );
		oStreetView.CoverView( true );
	}, 1000 );
}

//---------------------------------
//
oStreetView.Show = function()
{
	if( oStreetView.m_oElement == null  || oStreetView.m_oStreetView == null )
	{
		oStreetView.Init();
	}
	
	if( oStreetView.m_isLoad == false )
	{
		return;
	}
	
	oStreetView.m_oElement.style.width		= oStreetView.m_nWidth + "px";
	oStreetView.m_oElement.style.height		= oStreetView.m_nHeight + "px";
	oStreetView.m_oElement.style.left		= oStreetView.m_nX + "px";
	oStreetView.m_oElement.style.top		= oStreetView.m_nY + "px";
	oStreetView.m_oElement.style.border		= "4px solid #FF8C00";
	oStreetView.m_oElement.style.display	= "block"
	oStreetView.m_oStreetView.setVisible( true );
	
	oStreetView.m_isShow = true;
}

//---------------------------------
//
oStreetView.Close = function()
{
	if( oStreetView.m_isLoad == false )
	{
		return;
	}
	oStreetView.m_oElement.style.width		= "0px";
	oStreetView.m_oElement.style.height		= "0px";
	oStreetView.m_oElement.style.border		= "0px";
	oStreetView.m_oElement.style.display	= "none"
	oStreetView.m_oStreetView.setVisible( false );
	
	oStreetView.m_isShow = false;
}

//---------------------------------
//
oStreetView.AddPos = function( nLon, nLat, nDir )
{
	if( oStreetView.m_isLoad == false || oStreetView.m_isShow == false )
	{
		return;
	}
	var oLonLat = new google.maps.LatLng( nLat, nLon ); 
	oStreetView.m_oService.getPanoramaByLocation( oLonLat, 100, function( data, status )
	{
		if( status != google.maps.StreetViewStatus.OK )
		{
			oStreetView.CoverView( true );
			return;
		}
		oStreetView.CoverView( false );
		oStreetView.m_oStreetView.setPosition( oLonLat );
		oStreetView.m_oStreetView.setPov({
			heading :	nDir,
			pitch	:	0,
	        zoom	:	1
		});
	});
}

//---------------------------------
//
oStreetView.SetXY = function( x, y )
{
	if( oStreetView.m_oElement == null )
	{
		return;
	}
	oStreetView.m_nX	= x - oStreetView.m_nWidth - 8;
	oStreetView.m_nY	= y - oStreetView.m_nHeight - 8;
	oStreetView.m_oElement.style.left	=  oStreetView.m_nX + "px";
	oStreetView.m_oElement.style.top	=  oStreetView.m_nY + "px";
}

//---------------------------------
//
oStreetView.CoverView = function( isShow )
{
	if( oStreetView.m_isLoad == false || oStreetView.m_isShow == false )
	{
		return;
	}
	if( oStreetView.m_oCoverElement == null )
	{
		oStreetView.m_oCoverElement = document.createElement('div');
		oStreetView.m_oCoverElement.style.position			= 'absolute';
		oStreetView.m_oCoverElement.style.backgroundColor	= '#FF8C00';
		oStreetView.m_oCoverElement.style.filter			= 'Alpha(Opacity=50)';
		oStreetView.m_oCoverElement.style.zIndex			= 13; 
		oStreetView.m_oCoverElement.style.opacity			= 0.5;
		
		oStreetView.m_oElement.appendChild( oStreetView.m_oCoverElement );
	}

	if( isShow )
	{
		oStreetView.m_oCoverElement.style.display	= "block";
		oStreetView.m_oCoverElement.style.width		= oStreetView.m_nWidth + "px";
		oStreetView.m_oCoverElement.style.height	= oStreetView.m_nHeight + "px";
	}
	else
	{
		oStreetView.m_oCoverElement.style.display	= "none";
		oStreetView.m_oCoverElement.style.width		= 0 + "px";
		oStreetView.m_oCoverElement.style.height	= 0 + "px";
	}
}

//---------------------------------
//
oStreetView.isLoad = function()
{
	return true;	
}
