
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver >= 8.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  alert( msg );
}

var sv=false;
var svd=false;
var myPano;   
var panoClient;
var currentLatLng;
var currentYaw = 0;  
var fovMarker; 
var fovIcon = new GIcon(G_DEFAULT_ICON);
var iconSize = 75;  

var svd;
function turnsvon() {
	$('gmap').style.width='49%';
	 strv="a";
	 loc=getUrl();
	 
	 window.location=loc;
	if (!svd) {
	   map.removeOverlay(svd);	
	} else {
		map.removeOverlay(svd);
	}

	svd = new GStreetviewOverlay();
	map.addOverlay(svd);
	
	GEvent.addListener(map,"dblclick", function(overlay,latlng) {
		
		newfow(latlng);
	});
	
	newfow(map.getCenter());
	 


}

function showPanoData(panoData) {	
  myPano.setLocationAndPOV(panoData.location.latlng);	  
}
var gw=false;

function handleNoFlash(errorCode) {
	
	if (errorCode == 600) {
		panoClient.getNearestPanorama(map.getCenter(), showPanoData);
		
	}
	if (errorCode == 603) {
		alert("Error: Flash doesn't appear to be supported by your browser");
		return;
  }
} 

function newfow(latlng) {
	$('streetv').style.display='';
	canresize=false;
	var ver = getInternetExplorerVersion();
	if(ver < 7){
		 if ( ver > -1 )
		  {
			
			var e=getWindowSize();
			$('streetv').style.width=((e.width/2)-10)+'px';
		  }
	} 

	if (gw==false) {
		gw=$('gmap').style.width;
		}
		$('gmap').style.width='49%';

		map.checkResize();
		$('streetv').style.height=$('gmap').style.height; 
	if (sv==true ){
		map.removeOverlay(fovMarker);
		myPano.remove();
		$('streetcamera').innerHTML='';
	}
	$('streetcamera').innerHTML='';
	$('streetcamera').style.display='';
	currentLatLng = latlng;
panoClient = new GStreetviewClient(); 
	
	
	myPano = new GStreetviewPanorama(document.getElementById("streetcamera"));
	
	GEvent.addListener(myPano, "error", handleNoFlash);
    
	 
	var rv=myPano.setLocationAndPOV(currentLatLng, {yaw:currentYaw, pitch:0});
	
	fovIcon.image = "http://77.236.192.248/api.tixik.com/fov.php?yaw=180";
	fovIcon.iconSize = new GSize(iconSize, iconSize);
	fovIcon.iconAnchor = new GPoint(iconSize/2, iconSize/2); //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);
	
	
	
	sv=true;
	
}

function handleInitialized(location) {
	currentLatLng = location.latlng;	
	placeFovMarker();			 
	return;	
}
function handleYawChange(yaw){
	currentYaw = Math.round(yaw);
	placeFovMarker();
	return;
}
function placeFovMarker(){
	map.removeOverlay(fovMarker);
	var point=fovMarker.getPoint();
	map.panTo(point);
	
	
	fovIcon.image = "http://77.236.192.248/api.tixik.com/fov.php?yaw="+currentYaw+"&rand="+Math.random();
	fovMarker = new GMarker(currentLatLng, {icon: fovIcon, clickable: false});
	map.addOverlay(fovMarker);
	return;
}

 
function turnsvoff() {
	$('gmap').style.width=gw;
	map.checkResize();
	map.removeOverlay(svd);
	sv=false;
	$('streetv').style.display='none';
	$('streetcamera').style.display='none';
	
	map.removeOverlay(fovMarker);		
	
}

