var Street_IDChecked = false;
var shopID = ""; // id of image in streetview, used if exist in the parameter

var oneResultOnly = false; // to check if the result only 1 and show the sv snapshots
var SearchLine ;
var oneSearchResult = "";
var SearchSvId = "";
var SearchSvLong = 0;
var SearchSvLat = 0;
var SearchSvBaseAngle = "";
var SearchSvPhotoGroup = "";
var SearchSvPhotoGroupID ="";

var Streetview_FirstShow = false;
var LoadedMap=new Array();
var LoadedMap3=new Array();
var GM_Streetview=false;
var GM_StreetviewPoint=false;

var StreetviewLevel = "" ;
var Streetview_Top, Streetview_Bottom, Streetview_Left, Streetview_Right ;
var StreetviewLocation = new Array () ;
var StreetviewLine ;
var Streetview_MatchPos = 0 ;
var Streetview_MatchLoc = 0;
var Streetview_dragapproved = false ;
var LoadedStreetview = false;
var StreetViewLarge = false;
var OldStreetViewMode = false;
var StreetViewAngle = 0;
var StreetViewScale = 0.75; // small streeview scale from window innerheight/width
var ShopviewLocation = new Array();
var ShopView_Status = false;
var Shopview_Total = 0;
var baloonId = (StreetViewLarge) ? 'StreetViewPlayerLarge' : 'StreetViewLargeSmall';
var SV_URL = '';
var SV_Prev_Id = 0; /* this variable is used to hold previous id, commonly use in shopview */

$(document).ready(function() {
	var host = getCurrentHost();
	SV_URL = (host == '192.168.0.5') ? '192.168.0.15' : '116.240.201.18';
});

//for autoscroll
var scrollTimeout;
var scrollDone = false;
var animateDone = false;
// end of autoscroll variables

var SV_CV_Layer  = "GM_DrawingLayer10";
var SV_Point_Lyr = "GM_DrawingLayer9";
var SV_CV_Id     = "SV_CenterViewIcon";
var SV_CV_Src    = "images/sv-still.png";
var SV_Point_Src = "images/point.gif";
var SV_Data      = '';
var SV_CV_Obj    = '';
var SV_CV_X      = 0;
var SV_CV_Y      = 0;
var SV_CV_L      = 0;
var SV_CV_T      = 0;
var SV_CV_Long   = 0;
var SV_CV_Lat    = 0;
var SV_CV_Left   = 0;
var SV_CV_Top    = 0;
var SV_CV_Drag   = false;
var SV_FirstShow = true;
var SV_CV_xClick = 0;
var SV_CV_yClick = 0;
var SV_CV_xStart = 0;
var SV_CV_yStart = 0;
var SV_CV_Width  = 0;
var SV_CV_Height = 0;
var SV_CV_Dist   = 20;
var SV_FocusId   = '';
var SV_FocusLong = '';
var SV_FocusLat  = '';
var SV_Old_Id    = '';
var SV_Old_Long  = '';
var SV_Old_Lat   = '';
var SV_IE        = document.all;
var SV_Browser   = document.getElementById&&!document.all;
var ShopviewIconChange = '';
var SV_CurrentId = 0; /* holds sv current id */
var SV_PreviousId = 0; /* holds sv previous id */

detect_flash_player();

function detect_flash_player() 
{
	var flashURL = 'http://get.adobe.com/flashplayer/';
	
	if (!FlashDetect.installed)
	{
		alert('Flash is required to enjoy this site.');
		window.open(flashURL);
	}
	else
	{
		if (FlashDetect.versionAtLeast(10)) {} else 
		{
			alert('Flash version 10 is required to enjoy this site.');
			window.open(flashURL);
		}
	}
}

function showFacing(face)
{
    var SV_CV_Man = document.getElementById(SV_CV_Id);
    if (SV_CV_Man)
    {
	SV_CV_Src = face ? "images/sv-"+ face +".png" : "images/sv.png" ;
	SV_CV_Man.src = SV_CV_Src;
    }
}

function InitiateStreetview() {
    StreetviewLevel = GM_Level ;
    if (SV_CV_Long == 0 || SV_CV_Lat == 0) {
    	SV_CV_Long   = GM_New_X;
    	SV_CV_Lat    = GM_New_Y;
    	SV_FocusId   = '';
    	SV_FocusLong = SV_CV_Long;
    	SV_FocusLat  = SV_CV_Lat;

    }

    Streetview_GetDataList();
    StreetviewLine = new jsGraphics('StreetviewLineDiv');
    var WDBMouse = document.getElementById('StreetviewDetailBox') ;
    WDBMouse.onmousedown = Streetview_DetailDrag ;
    WDBMouse.onmouseup = new Function("Streetview_dragapproved=false") ;
}


function CheckStreetview() {
	Streetview_GetDataList();
}

function Streetview_GetDataList() {
	var TL = GM_ConvertPxToDeg(GM_Offset_Left,GM_Offset_Top);
	var BR = GM_ConvertPxToDeg(GM_Offset_Right,GM_Offset_Bottom);
	Streetview_Top = TL.Y ;
	Streetview_Bottom = BR.Y ;
	Streetview_Left = TL.X ;
	Streetview_Right = BR.X ;
	
	var url  = '/CommonLibrary/au_streetview2.php';
	var data = 'level=' + GM_Level + '&t=' + encodeURI(Streetview_Top) + '&l=' + encodeURI(Streetview_Left) + '&r=' + encodeURI(Streetview_Right) + '&b=' + encodeURI(Streetview_Bottom) + '&Ref=' + encodeURI(Math.round(Math.random(0,1)*100000000000));
	$.ajax({
		url : url,
		data: data,
		success:function(msg)
		{
			Streetview_SaveDataList_JSON(msg);
		    check_streetview();
		    Street_DisplayMenu();
		    shopPropCheck();
		    Street_PropCheck();
			if (shopID != "" && GM_Level>4)
			{
				displayBannerSV();
			}
		}
	});
}

function cekCenterViewInMap(T, L, B, R, Long, Lat)
{
  if (Long >= L && Long <= R && Lat >= B && Lat <= T) return true;
  else return false;
}

function Streetview_SaveDataList_JSON(data)
{	
	var obj = $.parseJSON(data);
	
	Shopview_Total = 0;
	Streetview_Total = obj.length;
	
	if (Streetview_Total > 0)
	{	
		for (var i=0; i<Streetview_Total; i++)
		{
			var p = obj[i];
			
			if (p.status == "IconChange") { /* changing icon for each point */
				var PX = GM_ConvertDegToPx(p.lon, p.lat);
    		    ShopviewIconChange +=  p.id + "\t" + PX.X + "\t" + PX.Y + "\t" + p.label + "\t" + p.group + "\n";
			} else {
				if (!StreetviewLocation[p.id])
				{
					var PX = GM_ConvertDegToPx(p.lon, p.lat);
					
					StreetviewLocation[p.id] = new NewStreetviewLocation(p.id) ;
					StreetviewLocation[p.id].X = PX.X ;
					StreetviewLocation[p.id].Y = PX.Y ;
					StreetviewLocation[p.id].Long = p.lon;
					StreetviewLocation[p.id].Lat  = p.lat;
					StreetviewLocation[p.id].Pid  = p.status;
					
					if (p.status == 2)
					{
						StreetviewLocation[p.id].Label  = p.label;
					} else {
						StreetviewLocation[p.id].PhotoGroup  = p.group;
						StreetviewLocation[p.id].PhotoGroupID  = p.group_id;
						StreetviewLocation[p.id].BaseAngle  = p.base_angle;
					}
				}
				
				if (p.status == 2)
				{
					Shopview_Total++;
				}
			}
		}
	}
	
	for (var i in StreetviewLocation)
	{
		var W = StreetviewLocation[i];
	}
}

function NewStreetviewLocation(ID) {
	this.ID   = ID ;
	this.X    = 0;
	this.Y    = 0;
	this.Long = 0.00;
	this.Lat  = 0.00;
	this.Pid  = 1;
	this.Label = "";
}


function Streetview_Title(Obj,S) {
	var WT = document.getElementById('StreetviewTitle') ;
	WT.innerHTML = "" ;
	if (S==0) {
		WT.style.display="none";
		WT.style.visibility="hidden";
	} else {
		WT.style.display="";
		setTimeout("Streetview_Delay('"+Obj.id+"');",10);
	}
}

function Streetview_Delay(Objn) {
	var WT = document.getElementById('StreetviewTitle');
	var Obj = document.getElementById(Objn);
	var P = ShowOffSet(Obj.id);
	if ((P.left+Obj.offsetWidth+WT.offsetWidth)+30>=window.screen.width) {
		WT.style.left = P.left-WT.offsetWidth-16 + 'px';
	} else {
		WT.style.left = P.left+Obj.offsetWidth+16 + 'px';
	}
	WT.style.top = P.top;
	WT.style.visibility="visible";
}

function Streetview_DetailDrag(e) {
	Streetview_dragapproved=true;
	z= document.getElementById('StreetviewDetailBox');
	temp1=parseInt(z.style.left);
	temp2=parseInt(z.style.top);
	x = DD_nn6 ? e.clientX : event.clientX ;
	y = DD_nn6 ? e.clientY : event.clientY ;
	document.onmousemove=Streetview_DetailMove;
}

function Streetview_DetailMove(e) {
	if (Streetview_dragapproved){
		XMouseClick = DD_nn6 ? e.clientX : event.clientX ;
		YMouseClick = DD_nn6 ? e.clientY : event.clientY ;
		z.style.left=temp1+XMouseClick-x + 'px';
		z.style.top=temp2+YMouseClick-y + 'px';
//		Streetview_SetArrow();
		return false;
	}
}

function Street_DisplayMenu() {
    var W = document.getElementById('StreetviewCheck');
    var CStreet = (Street_IDChecked)?"checked":"";
    var CShop   = (ShopView_Status)?"checked":"";
    var BSS = document.getElementById('Button_Switch_streetview');

    // to remove checkbox and streetview button when no streetview point in this area
    if (Streetview_Total>0)
    {
	W.innerHTML="<b><input type=\"checkbox\" id=\"Streetview_checkbox\" onclick=\"Street_PropCheck();\" "+CStreet+"> <img src=\"images/centerview2.png\" align=\"absmiddle\">&nbsp;&nbsp;Street View </b> <img src=\"images/icon_beta.gif\" align=\"absmiddle\"> ";
	if (Shopview_Total > 0)
		W.innerHTML += "<br><b><input type=\"checkbox\" id=\"Shopview_checkbox\" onclick=\"shopPropCheck();\" "+CShop+"> <img src=\"images/shopview2.png\" align=\"absmiddle\">&nbsp;&nbsp;Shop View (" + Shopview_Total + ")</b> <img src=\"images/icon_beta.gif\" align=\"absmiddle\">";
		BSS.style.visibility = 'visible' ;
		BSS.style.display='';
    } else {
		W.innerHTML="<b><img src=\"images/centerview2.png\" align=\"absmiddle\">&nbsp;&nbsp;Street View</b>";
		BSS.style.visibility = 'hidden' ;
		BSS.style.display='none';
    }
	if (document.getElementById('StreetviewDetailBox').innerHTML == "") {
		showSnapshot();
	}
}


function check_streetview() {
    GM_Streetview = true;
    GM_StreetviewPoint = (GM_Level < 5)?false:true;
}

function SV_updateCenterViewIconByLongLat(Long, Lat)
{
	var PX     = GM_ConvertDegToPx(Long, Lat);
	SV_CV_X    = PX.X;
	SV_CV_Y    = PX.Y;
	SV_CV_Long = Long;
	SV_CV_Lat  = Lat;
	if (GM_StreetviewPoint)
	{
		SV_showCenterViewIcon();
	}
}

function SV_updateCenterViewIconByPixel( X, Y )
{
  var LL     = GM_ConvertPxToDeg(X, Y);
  SV_CV_X    = X;
  SV_CV_Y    = Y;
  SV_CV_Long = LL.X;
  SV_CV_Lat  = LL.Y;
  if (GM_StreetviewPoint)
  {
	  SV_showCenterViewIcon();
  }
}


function SV_showCenterViewIcon()
{
  var CVL = document.getElementById(SV_CV_Layer);
  CVL.innerHTML = "";
  var CV  = null;

  if ( !document.getElementById(SV_CV_Id) )
  {
     CV      = document.createElement('img');
     CV.id   = SV_CV_Id;
     CV.name = SV_CV_Id;
     CV.src  = SV_CV_Src;
	 CV.className = "trans";
	 CV.style.width = 34;
	 CV.style.height = 52;
     CV.onload = function() {
	    this.style.visibility = 'visible' ;
     }

	CVL.width  = CV.style.width;
	CVL.height = CV.style.height;
    CVL.appendChild(CV);

  }

    CV      = document.getElementById(SV_CV_Id);
    CV.X    = SV_CV_X;
    CV.Y    = SV_CV_Y;
    CV.Long = SV_CV_Long;
    CV.Lat  = SV_CV_Lat;
    CV.style.position = 'absolute';

    SV_CV_Left        = CV.X - Math.round(parseInt(CV.width)/2);
    SV_CV_Top         = CV.Y - Math.round(parseInt(CV.height)/3*2);

//    CV.style.left     = SV_CV_Left + 'px';
//    CV.style.top      = SV_CV_Top + 'px';
//// change to opera compatible /////////////

    CV.style.left     = SV_CV_Left - GM_XCenter + 'px';
    CV.style.top      = SV_CV_Top - GM_YCenter + 'px';

/////////////////////////////////////////////
    CV.style.cursor   = 'default';
    CV.style.visibility = 'visible';
    CV.style.display    = '';
//    CVL.style.zIndex  = 99999999;
	CVL.style.zIndex  = 99997;

    document.onmousedown = SV_startDrag;
    document.onmouseup   = SV_stopDrag;
}


function SV_startDrag(e)
{
    if (e) {
      if (e.button == 2 || e.button == 3) return;
    }

    var objClick   = (SV_Browser) ? e.target : event.srcElement;
    var topelement = (SV_Browser) ? "HTML" : "BODY";
    if (objClick.id != SV_CV_Id) {
       document.onmousedown=StartDrag;
       document.onmouseup=StopDrag;
       StartDrag(e);
       return false;
    }
    while(objClick.tagName != topelement && objClick.id != SV_CV_Id)
    {
      objClick = (SV_Browser) ? objClick.parentNode : objClick.parentElement;
    }

    if (objClick.id == SV_CV_Id)
    {

       SV_CV_Drag   = true;
       SV_CV_Obj    = objClick;
       SV_CV_xStart = SV_Browser ? e.clientX : event.clientX;
       SV_CV_yStart = SV_Browser ? e.clientY : event.clientY;
       SV_CV_L      = SV_CV_X;
       SV_CV_T      = SV_CV_Y;
//     SV_CV_Obj.style.left = SV_CV_Left + 'px';
//     SV_CV_Obj.style.top  = SV_CV_Top  + 'px';
//// change to opera compatible /////////////
    // SV_CV_Obj.style.left = SV_CV_Left - GM_XCenter + 'px';
    // SV_CV_Obj.style.top  = SV_CV_Top - GM_YCenter + 'px';
/////////////////////////////////////////////
       document.onmousemove = SV_moveDrag;

	   Streetview_Close();
       showFacing('');
       return false;
    }
}


function SV_moveDrag(e)
{
  if (SV_CV_Drag)
  {
     SV_CV_xClick = SV_Browser ? e.clientX : event.clientX ;
     SV_CV_yClick = SV_Browser ? e.clientY : event.clientY ;
     SV_CV_X      = (SV_CV_L + (SV_CV_xClick - SV_CV_xStart) ) ;
     SV_CV_Y      = (SV_CV_T + (SV_CV_yClick - SV_CV_yStart) ) ;
     SV_CV_Left   = SV_CV_X - GM_XCenter - Math.round(parseInt(SV_CV_Obj.width)/2);
     SV_CV_Top    = SV_CV_Y - GM_YCenter - Math.round(parseInt(SV_CV_Obj.height)/3*2);
     SV_CV_Obj.style.left = SV_CV_Left + 'px';
     SV_CV_Obj.style.top  = SV_CV_Top + 'px';
//// change to opera compatible /////////////
//     SV_CV_Obj.style.left = SV_CV_Left - GM_XCenter + 'px';
//     SV_CV_Obj.style.top  = SV_CV_Top - GM_YCenter + 'px';
/////////////////////////////////////////////
     return false;
  }
}

function SV_stopDrag(e)
{
  SV_CV_Drag   = false;
  if (SV_CV_Obj)
  {
    SV_CV_xClick = SV_Browser ? e.clientX : event.clientX ;
    SV_CV_yClick = SV_Browser ? e.clientY : event.clientY ;

    SV_CV_X      = (SV_CV_L + (SV_CV_xClick - SV_CV_xStart));
    SV_CV_Y      = (SV_CV_T + (SV_CV_yClick - SV_CV_yStart));

    SV_CV_Left   = SV_CV_X - GM_XCenter - Math.round(parseInt(SV_CV_Obj.width)/2);
    SV_CV_Top    = SV_CV_Y - GM_YCenter - Math.round(parseInt(SV_CV_Obj.height)/3*2);
    SV_CV_Obj.style.left = SV_CV_Left  + 'px';
    SV_CV_Obj.style.top  = SV_CV_Top  + 'px';

    SV_updateCenterViewIconByPixel(SV_CV_X, SV_CV_Y);
    SV_moveCenterViewToNearestPoint();
    SV_CV_Obj = '';
    showFacing('still');
    document.onmousedown=StartDrag;
    document.onmouseup=StopDrag;
    return false;
  }
}


function SV_getDistance (Long1, Lat1, Long2, Lat2)
{ var Distance = 0 ;
	if (!(Long1 == Long2 && Lat1 == Lat2))
	{
		Distance = (20001.6/Math.PI)*Math.acos(Math.sin(Math.PI*(Lat1)/180)*Math.sin(Math.PI*(Lat2)/180)+Math.cos(Math.PI*(Lat1)/180)*Math.cos(Math.PI*(Lat2)/180)*Math.cos(((Long2)-(Long1))*Math.PI/180)) ;
	}
	return Distance ;
}

function SV_moveCenterViewToNearestPoint (longlat)
{
    var minDistance    = 999999999;
    if(longlat) {
	var D = longlat.split(",");
	SV_CV_Long= D[0];
	SV_CV_Lat= D[1];
	Streetview_Close();
    }

    SV_Old_Id    = SV_FocusId;
    SV_Old_Long  = SV_FocusLong;
    SV_Old_Lat   = SV_FocusLat;

    for (var i in StreetviewLocation)
    {
		var W = StreetviewLocation[i] ;
		if (W.Pid == 1) /* only apply this for streetview only */
		{
			var temp  = SV_getDistance(SV_CV_Long, SV_CV_Lat, W.Long, W.Lat);
			if (temp < minDistance)
			{
				SV_FocusId   = W.ID;
				SV_FocusLong = W.Long;
				SV_FocusLat  = W.Lat;
				minDistance  = temp;
			}
		}
    }

    minDistance = Math.round(minDistance*1000);

    if ( minDistance <= SV_CV_Dist) { } else {
		SV_FocusId   = (SV_Old_Id)?SV_Old_Id:SV_FocusId;
		SV_FocusLong = (SV_Old_Long)?SV_Old_Long:SV_FocusLong;
		SV_FocusLat  = (SV_Old_Lat)?SV_Old_Lat:SV_FocusLat;
    }

    if (SV_FocusLong != SV_CV_Long || SV_FocusLat != SV_CV_Lat) {
		SV_updateCenterViewIconByLongLat(SV_FocusLong, SV_FocusLat);
    }

    if ((!LoadedStreetview) && SV_FocusId && (SV_FocusId != SV_Old_Id || SV_CV_Obj)) //&& (SV_FocusId != SV_Old_Id))
    {
		Streetview_MatchPos = 0;
		pointOnclick(SV_FocusId);
		setTimeout('Streetview_OpenDialogBox('+SV_FocusId+');', 1000);
    }
}

function shopPropCheck()
{
    var Obj = document.getElementById('Shopview_checkbox');
    var SVO = document.getElementById('Streetview_checkbox');

    if (Obj && SVO)
    {
	var FN = eval("document.CurrentMap");
	if (Obj.checked)
	{
	    ShopView_Status = true;
	    FN.shopview.value = ShopView_Status;
	    if (SVO.checked == false)
	    {
		SVO.checked = ShopView_Status;
		Street_PropCheck();
	    }
	} else {
	    FN.shopview.value = "";
	    ShopView_Status = false;
	}
	ViewStreetviewPoints();
    }
}


function DrawIconChangePoints()
{

  var WL = document.getElementById('GM_DrawingLayer9');

	var D = ShopviewIconChange.split("\n");

	for(var i = 0 ; i < D.length-1 ; i ++)
	{
	   var W = D[i].split("\t");

   		var altDiv = document.createElement('div');
    	altDiv.id  = 'GM_Streetview_Div_' + W[0] ;
      altDiv.style.position = 'absolute' ;
      altDiv.style.top = parseFloat(W[2]) - 5 - GM_YCenter + "px";      
      altDiv.style.left = parseFloat(W[1]) + 15 - GM_XCenter + "px";      
		  altDiv.innerHTML = "<font face='verdana' size='2px'><b>" + W[4] + "</b></font>";
      WL.appendChild(altDiv);  
 	   
	   if (document.getElementById('GM_Streetview_' + W[0])) {
     		var Img = document.getElementById('GM_Streetview_' + W[0]);
    		Img.src = (GM_StreetviewPoint)?"svicon/"+W[3]:"images/shopview2.png";
     } else {
     		var Img = document.createElement('img');
    		Img.id     = 'GM_Streetview_' + W[0] ;
    		Img.name   = Img.id ;
    		Img.src = (GM_StreetviewPoint)?"svicon/"+W[3]:"images/shopview2.png";
    		Img.LX     = W[1] ;
    		Img.LY     = W[2] ;
    		Img.MyID   = W[0] ;
    		Img.style.position = 'absolute' ;
    		Img.style.cursor = 'pointer' ;
    		Img.alt = (W[4])?W[4]:'Click To View Detail' ;
    		Img.title = Img.alt;
    		
    		/* change to opera compatible */
    		var tmpTop = Img.LY - Math.round(parseInt(Img.height)/2) - GM_YCenter;
    		var tmpLeft = Img.LX - Math.round(parseInt(Img.width)/2) - GM_XCenter;

    		Img.style.top = tmpTop + 'px';
    		Img.style.left = tmpLeft + 'px';
    		/* end of change to opera compatible */
    
    		if (Img.src.indexOf('shop')>=0 && ShopView_Status == false) {
    		    Img.style.visibility = 'hidden';
    		    Img.style.display = 'none';
    		    ShopviewLocation[Img.id] = Img.src;
    		} else {
    		    Img.style.visibility = 'visible';
    		    Img.style.display = '';
    		}
    
    		Img.onload = function() {
    		/* change to opera compatible */
      		tmpTop = this.LY - Math.round(parseInt(this.height)/2) - GM_YCenter;
      		tmpLeft = this.LX - Math.round(parseInt(this.width)/2) - GM_XCenter;
      		this.style.top =  tmpTop + 'px';
      		this.style.left =  tmpLeft + 'px';
    		/* end of change to opera compatible */
    		}
    
      	Img.onclick = function() {
          if (GM_StreetviewPoint) {
      			Streetview_Close();
      			showFacing('still');
      
      			if ((!LoadedStreetview))
      			{
      			    Streetview_MatchPos =0;
      			    pointOnclick(this.MyID);
      			    setTimeout('Streetview_OpenDialogBox('+this.MyID+')', 800);
      			}
      		} else {
      			PanChangeLevelStreetView(this.MyID);
      		}
    		}
    		
    		WL.appendChild(Img);
    		Img = null ;
  	}
  }
}



function ViewStreetviewPoints()
{
    var WL = document.getElementById('GM_DrawingLayer9');
    WL.innerHTML = "" ;
	
    for (var i in StreetviewLocation)
    {		
		var W = StreetviewLocation[i] ;
	
	// changed by Bayu
	if (W.Pid && W.Pid != 1)
	/////////////////////////
	{
	    if (Street_IDChecked)
	    {
		var Img = document.createElement('img');
		Img.id     = 'GM_Streetview_' + W.ID ;
		Img.name   = Img.id ;
		Img.src = (GM_StreetviewPoint)?"images/shopview2.png":"images/centerview.png";
		Img.LX     = W.X ;
		Img.LY     = W.Y ;
		Img.Long   = W.Long;
		Img.Lat    = W.Lat;
		Img.MyID   = W.ID ;
		Img.style.position = 'absolute' ;
		Img.style.cursor = 'pointer' ;
		Img.alt = (W.Label)?W.Label:'Click To View Detail' ;
		Img.title = Img.alt;
		
		/* change to opera compatible */
		Img.style.top = Img.LY - Math.round(parseInt(Img.height)/2) - GM_YCenter + 'px';
		Img.style.left = Img.LX - Math.round(parseInt(Img.width)/2) - GM_XCenter + 'px';
		/* end of change to opera compatible */

		if (Img.src.indexOf('shop')>=0 && ShopView_Status == false) {
		    Img.style.visibility = 'hidden';
		    Img.style.display = 'none';
		    ShopviewLocation[Img.id] = Img.src;
		} else {
		    Img.style.visibility = 'visible';
		    Img.style.display = '';
		}

		Img.onload = function() {
		/* change to opera compatible */
		this.style.top = this.LY - Math.round(parseInt(this.height)/2) - GM_YCenter + 'px';
		this.style.left = this.LX - Math.round(parseInt(this.width)/2) - GM_XCenter + 'px';
		/* end of change to opera compatible */
		}

	    	Img.onclick = function() {
		    if (GM_StreetviewPoint) {
			Streetview_Close();
			showFacing('still');

			if ((!LoadedStreetview))
			{
			    Streetview_MatchPos =0;
			    pointOnclick(this.MyID);
			    setTimeout('Streetview_OpenDialogBox('+this.MyID+')', 800);
			}
		    } else {
			PanChangeLevelStreetView(this.MyID);
		    }
		}

		WL.appendChild(Img);
		Img = null ;
	    }
	}
    }
    
// change icon for each shopview point 
    if (ShopviewIconChange != "") {
  	   DrawIconChangePoints();
  	}
    
    
}



function Street_PropCheck()
{
    var Obj = document.getElementById('Streetview_checkbox');
    var GM_S1 = document.getElementById('Button_Switch_streetview') ;

    if (Obj)
    {
	var FN = eval("document.CurrentMap");
	if (Obj.checked)
	{
	    Streetview_FirstShow = true;
	    Street_IDChecked = true ;
	    FN.streetview.value = "checked";
	    GM_S1.src = GM_S1.OnImage.src ;

	    if(GM_Streetview) {
		//show_streetview_map(100);

		var DRObj3 = document.getElementById('GM_DrawingLayer_Streetview');
		DRObj3.style.visibility = 'visible';
		DRObj3.style.display    = '';



		SV_CV_Drag   = false;
		if (GM_StreetviewPoint) SV_updateCenterViewIconByLongLat(SV_CV_Long, SV_CV_Lat);
		ViewStreetviewPoints();
	    }
	} else {
	    GM_S1.src = GM_S1.OffImage.src ;
	    Street_IDChecked = false ;
	    Streetview_FirstShow = false;

	    FN.streetview.value = "";
//	    show_streetview_map(0);

		var DRObj3 = document.getElementById('GM_DrawingLayer_Streetview');
		DRObj3.style.visibility = 'hidden';
		DRObj3.style.display    = 'none';

		if (!ShoppingCenterClick) {
			Streetview_Close();
		}
	    var CVL = document.getElementById(SV_CV_Layer);
	    CVL.innerHTML = "";
	    var WL = document.getElementById('GM_DrawingLayer9');
	    WL.innerHTML = "" ;
	    var SHP = document.getElementById('Shopview_checkbox');
	    if (SHP) { SHP.checked = false; }
	    ShopView_Status = false;
	}
    }

    if (cekCenterViewInMap(Streetview_Top, Streetview_Left, Streetview_Bottom, Streetview_Right,SV_CV_Long, SV_CV_Lat))
    {
	if (Street_IDChecked && SV_FirstShow) {
	    /* SV_moveCenterViewToNearestPoint(); */
	    SV_FirstShow = false;
	}
    }
}

function PanChangeLevelStreetView(ID) {

  var W = StreetviewLocation[ID] ;
	var FN = eval("document.CurrentMap");
	FN.x.value = W.Long ;
	FN.y.value = W.Lat ;
	FN.level.value = 6 ;
	FN.rural.value = 0 ;
	FN.rent_rural.value = 0 ;
	FN.submit();
}


function pointOnclick(ID) {
    if (StreetviewLocation[ID])
    {
		var W = StreetviewLocation[ID] ;
		var tmpPixel = GM_ConvertDegToPx(W.Long,W.Lat) ;
		var tmpLonglat = GM_ConvertPxToDeg(tmpPixel.X,parseInt(tmpPixel.Y-200));
		SV_FocusId   = W.ID;
		SV_FocusLong = W.Long;
		SV_FocusLat  = W.Lat;
		GM_RecenterDeg(tmpLonglat.X,tmpLonglat.Y,1);
		SV_updateCenterViewIconByLongLat(W.Long, W.Lat);
		Streetview_MatchLoc = W.ID ;
    } else {
		SV_FocusId = ID;
    }
}

function Streetview_Larger() {
    var photoAngle = getPhotoAngle();
    StreetViewAngle = photoAngle-10;
    StreetViewLarge = true;
    baloonId = 'StreetViewPlayerLarge';
    Streetview_MatchPos = 0;
    Streetview_MatchLoc = SV_FocusId ;
    setTimeout('Streetview_OpenDialogBox('+SV_FocusId+');', 800);
}

function Streetview_Smaller() {
    var photoAngle = getPhotoAngle();
    StreetViewAngle = photoAngle-10;

//	StreetViewAngle = getPhotoAngle()-10;
	StreetViewLarge = false;
	baloonId = 'StreetViewLargeSmall';
	Streetview_MatchPos = 0;
	Streetview_MatchLoc = SV_FocusId ;
	setTimeout('Streetview_OpenDialogBox('+SV_FocusId+');', 800);
}

function getInnerWH() {
	var d = new Object();
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		d.w = window.innerWidth;
		d.h = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		d.w = document.documentElement.clientWidth;
		d.h = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		// IE 4 compatible
		d.w = document.body.clientWidth;
		d.h = document.body.clientHeight;
	}
	return d;
}


// function to check the streetview large or not
function Streetview_OpenDialogBox(streetview_ID) {

    var tmpInnerWidth  = 0;
    var tmpInnerHeight = 0;
    var temp = getInnerWH();
    tmpInnerWidth  = temp.w;
    tmpInnerHeight = temp.h;

    if (tmpInnerWidth > 1024 && !StreetViewLarge) tmpInnerWidth  = 1030;
    if (tmpInnerHeight > 598 && !StreetViewLarge) tmpInnerHeight = 610;

//    scrollDone = animateDone = false;

    var LDB = document.getElementById('StreetviewDetailBox') ;

    if (StreetViewLarge) {
		LDB.style.left = 0 + 'px' ;
		LDB.style.top = 0 + document.body.scrollTop + 'px' ;
		displayBox(streetview_ID);
    } else {

		var tmpleft = (document.getElementById('GenMapDiv').offsetWidth-parseInt(tmpInnerWidth*StreetViewScale)) ;

		if(parseInt(tmpInnerHeight*StreetViewScale)>(parseInt(tmpInnerWidth*StreetViewScale)/2)) {
			var tmptop    = (document.getElementById('GenMapDiv').offsetHeight-(parseInt(tmpInnerWidth*StreetViewScale)/2))/2 ;
			LDB.style.top = document.getElementById('GenMapDiv').offsetTop + tmptop + 145 - (parseInt(tmpInnerHeight*StreetViewScale)/2) + 'px' ;
		} else {
			var tmptop    = (document.getElementById('GenMapDiv').offsetHeight-parseInt(tmpInnerHeight*StreetViewScale))/2 ;
			LDB.style.top = document.getElementById('GenMapDiv').offsetTop + tmptop + 120 - (parseInt(tmpInnerHeight*StreetViewScale)/2) + 'px' ;
		}

		LDB.style.left = document.getElementById('GenMapDiv').offsetLeft + tmpleft + 'px';
		scrollPosition = document.getElementById('GenMapDiv').offsetTop;
		clearTimeout(scrollTimeout);
		//autoScrollPage(streetview_ID);
		checkRecenter(streetview_ID);
    }
}


function displayBox(streetview_ID) {
    var tmpInnerWidth  = 0;
    var tmpInnerHeight = 0;
    var temp = getInnerWH();
    tmpInnerWidth  = temp.w;
    tmpInnerHeight = temp.h;

    baloonId = (StreetViewLarge) ? 'StreetViewPlayerLarge' : 'StreetViewLargeSmall';
    if (tmpInnerWidth > 1024 && !StreetViewLarge) tmpInnerWidth  = 1030;
    if (tmpInnerHeight > 598 && !StreetViewLarge) tmpInnerHeight = 610;

    var LDB = document.getElementById('StreetviewDetailBox') ;

    if (LDB.innerHTML == "")
    {
		var HTML = "<table id='mainSV_Table' title=\"Drag & Drop is Available For This Layer\" cellpadding=2 cellspacing=1 border=0 bgcolor=\"#000000\" width="+parseInt(tmpInnerWidth*StreetViewScale)+">";
		HTML += "<tr>";
		HTML += "<td class=content bgcolor=\"#D8DEED\" style=\"height: 10px;\">";
		HTML += "<table cellpadding=0 cellspacing=2 border=0 width=\"100%\" >";
		HTML += "<tr>";
		HTML += "<td class=content align='left'><span id='spanHeader' align='left'></span></td><td class=content align=\"right\" id='tdHeader'><a href=\"javascript: Streetview_Larger();\"><b>Large View</b></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript: Streetview_Close();\"><img src=\"images/prop_close.gif\" border=0></a></td>";
//		HTML += "<td class=content align='left'><span id='spanHeader' align='left'></span></td><td class=content align=\"right\" id='tdHeader'><a href=\"javascript: Streetview_Larger();\"><img src='images/prop_max.gif' alt='see larger view' border='0'></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript: Streetview_Close();\"><img src=\"images/prop_close.gif\" border=0></a></td>";
		HTML += "</tr>";
		HTML += "</table>";
		HTML += "</td>";
		HTML += "</tr>";
		HTML += "<tr>";
		HTML += "<td class=content bgcolor=\"#FFFFFF\" id=\"Streetview_Tbl\">";
		HTML += "<style>";
		HTML += ".font_w { color: #FFFFFF; font-size: 12px; };";
		HTML += "</style>";
		HTML += "<table cellpadding=2 cellspacing=2 border=0 width=\"100%\" height=\"100%\">";
		HTML += "<tr><td id='tdFlash'><div id=\"baloonSmall\" width='100%' height='100%'></div><div id=\"baloonLarge\" width='100%' height='100%'></div><td></tr>";
		HTML += "</table>";
		HTML += "</td>";
		HTML += "</tr>";
		HTML += "</table>";
		LDB.innerHTML = HTML ;
    }

    LDB.style.visibility = 'visible';
    LDB.style.display    = '';
    LDB.style.zIndex = 1000000099;

    var TBL = document.getElementById('mainSV_Table');
    var TDH = document.getElementById('tdHeader');
    if (StreetViewLarge)
    {
		if (typeof( window.innerWidth ) == 'number') {
			TBL.width   = parseInt(tmpInnerWidth-32) + 'px';
			TBL.height  = parseInt(tmpInnerHeight-50) + 'px';
		} else {
			TBL.width   = parseInt(tmpInnerWidth) + 'px';
			TBL.height  = parseInt(tmpInnerHeight) + 'px';
		}

//		TDH.innerHTML = '<a href=\"javascript: Streetview_Smaller();\"><img src="images/prop_min.gif" alt="see smaller view" border="0"></a>&nbsp;<a href=\"javascript: Streetview_Close();\"><img src=\"images/prop_close.gif\" border=0></a>';
		TDH.innerHTML = '<a href=\"javascript: Streetview_Smaller();\"><b>Small View</b></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript: Streetview_Close();\"><img src=\"images/prop_close.gif\" border=0></a>';

		var BS = document.getElementById('baloonSmall');

		if (BS) {
			BS.style.visibility = 'hidden';
			BS.style.display    = 'none'
		}
		var BL = document.getElementById('baloonLarge');
		if (BL) {
			BL.style.visibility = 'visible';
			BL.style.display    = ''
		}
    } else {
		TBL.width     = parseInt(tmpInnerWidth*StreetViewScale) + 'px';
		TBL.height    = (parseInt(tmpInnerWidth*StreetViewScale)/2) + 'px';
		TDH.innerHTML = '<a href=\"javascript: Streetview_Larger();\"><b>Large View</b></a>&nbsp;&nbsp;&nbsp;<a href=\"javascript: Streetview_Close();\"><img src=\"images/prop_close.gif\" border=0></a>';

		//TDH.innerHTML = '<a href=\"javascript: Streetview_Larger();\"><img src="images/prop_max.gif" alt="see larger view" border="0"></a>&nbsp;<a href=\"javascript: Streetview_Close();\"><img src=\"images/prop_close.gif\" border=0></a>';
		var BL = document.getElementById('baloonLarge');
		if (BL) {
			BL.style.visibility = 'hidden';
			BL.style.display    = 'none'
		}
		var BS = document.getElementById('baloonSmall');
		if (BS) {
			BS.style.visibility = 'visible';
			BS.style.display    = '';
		}
    }

    if (StreetViewLarge) {
		showBaloon(streetview_ID,parseInt(tmpInnerWidth-35), parseInt(tmpInnerHeight-52));
    } else {
		if(parseInt(tmpInnerHeight*StreetViewScale)>(parseInt(tmpInnerWidth*StreetViewScale)/2)) {
			showBaloon(streetview_ID,parseInt(tmpInnerWidth*StreetViewScale), parseInt(tmpInnerWidth*StreetViewScale)/2);
		} else {
			showBaloon(streetview_ID,parseInt(tmpInnerWidth*StreetViewScale), parseInt(tmpInnerHeight*StreetViewScale));
		}
    }
}


// function to scroll the page
function autoScrollPage(ID)
{
    var scrollStep = 10;
    if(document.body.scrollTop != document.getElementById('GenMapDiv').offsetTop)
    {
	if (document.body.scrollTop < document.getElementById('GenMapDiv').offsetTop){
	    if((document.body.scrollTop+scrollStep) > document.getElementById('GenMapDiv').offsetTop) {
		scrollStep = document.getElementById('GenMapDiv').offsetTop - document.body.scrollTop;
	    }
      	    window.scrollBy(0,scrollStep);
      	    scrollTimeout=setTimeout("autoScrollPage('"+ID+"')",100);
      	} else {
      	    if((document.body.scrollTop-scrollStep) < document.getElementById('GenMapDiv').offsetTop) {
		scrollStep = document.body.scrollTop - document.getElementById('GenMapDiv').offsetTop;
	    }
      	    window.scrollBy(0,scrollStep*-1);
      	    scrollTimeout=setTimeout("autoScrollPage('"+ID+"')",100);
      	}
    } else {
	scrollDone = true;	// flag for done scrolling
	if (animateDone)
	{
		displayBox(ID);
	}
    }
}


// function to check if the recenter map is done
function checkRecenter(ID) {

	if (ShoppingLocation[ID]) {
		StreetviewLocation[ID] = new NewStreetviewLocation(ID);
		StreetviewLocation[ID].X = ShoppingLocation[ID].X ;
		StreetviewLocation[ID].Y = ShoppingLocation[ID].Y ;
		StreetviewLocation[ID].Long = ShoppingLocation[ID].Long;
		StreetviewLocation[ID].Lat  = ShoppingLocation[ID].Lat;					
	}

    var useID = (StreetviewLocation[ID])?ID:SV_Prev_Id;

    if (StreetviewLocation[useID])
    {
		var W = StreetviewLocation[useID] ;
		var tmpPixel = GM_ConvertDegToPx(W.Long,W.Lat) ;

		var RObj = document.getElementById('GM_Tiling_Div') ;
		var NGM_XCenter = Math.round(GM_Width/2) - parseInt(RObj.style.left,10) + GM_XCenter ;
		var NGM_YCenter = Math.round(GM_Height/2) - parseInt(RObj.style.top,10) + GM_YCenter ;
		var tmpCount1 = Math.abs(NGM_XCenter - tmpPixel.X);
		var tmpCount2 = Math.abs(NGM_YCenter - tmpPixel.Y-200);

		if (tmpCount1 >2 && tmpCount2 >2)
		{
			setTimeout("checkRecenter('"+ID+"');",500);
		} else {
//			animateDone = true; // flag recenter is done
//			if (scrollDone)
//			{
				displayBox(ID);
//			}
		}
    }
}



function Streetview_Close() {

	ShoppingCenterClick = false; // flag for showing shopping center floor plan
	
	var LDB = document.getElementById('StreetviewDetailBox') ;
	if (!LDB) return false;
	LDB.style.visibility = 'hidden' ;
	LDB.style.display = 'none' ;
	LDB.style.zIndex = '0' ;
	//StreetviewLine.clear();
	LoadedStreetview = false;
	StreetViewLarge = false;
	SV_Old_Id = '';
	showFacing('still');

	if(document.frmEmailThisPage) {
		var fn = eval('document.frmEmailThisPage');
		fn.emailsvid.value = "" ;
		fn.svX.value = "" ;
		fn.svY.value = "" ;
	}
}

function Streetview_SetArrow() {
	StreetviewLine.clear();
	var LDB = document.getElementById('StreetviewDetailBox') ;
	if (LDB.style.visibility == 'visible')
	{
		var left = parseInt(LDB.style.left);
		var top = parseInt(LDB.style.top);
		var right = left + LDB.clientWidth;
		var bottom = top + LDB.clientHeight;

		var ICN = document.getElementById('GM_Streetview_'+Streetview_MatchLoc) ;

		var IconLeft = document.getElementById('GenMapDiv').offsetLeft + ICN.LX - GM_Offset_Left;
		var IconTop = document.getElementById('GenMapDiv').offsetTop + ICN.LY - GM_Offset_Top;

		var XB = (IconLeft > (left+right)/2)?right-1:left+1;
		var YB = (IconTop > (top+bottom)/2)?bottom-1:top+1;

		GM_SetLine(StreetviewLine,2,'#02287B',IconLeft,IconTop,XB,YB);
		GM_SetLine(StreetviewLine,1,'#D8DEED',IconLeft,IconTop,XB,YB);

		var WDD = document.getElementById('StreetviewLineDiv');
		WDD.style.zIndex = 10000000 ;

		if (!(ICN.LX >= GM_Offset_Left && ICN.LX <= GM_Offset_Right && ICN.LY >= GM_Offset_Top && ICN.LY <= GM_Offset_Bottom))
		{
			Streetview_Close();
		}
	}
}







function show_streetview_map(opa) {

//		alert('You\'re using ' + BrowserDetect.browser + ' ' + BrowserDetect.version + ' on ' + BrowserDetect.OS + '!');

		var GM_StreetOpa = opa;
		var tmpDiv = document.getElementById('GM_DrawingLayer_Streetview');
    tmpDiv.style.visibility = 'visible';
    tmpDiv.style.display    = '';
		for (var i in LoadedMap3) {
			if (document.getElementById(i))
			{
				var C = document.getElementById(i) ;
				if (SV_Browser) {
					C.style.MozOpacity = (GM_Streetview)?GM_StreetOpa/100:0;
					C.style.opacity= (GM_Streetview)?GM_StreetOpa/100:0; // this for opera
				} else {
					C.style.filter = 'alpha(opacity='+((GM_Streetview)?GM_StreetOpa-40:0)+')';
				}


/*				switch(BrowserDetect.browser)
				{
				    case "Firefox"	:
					C.style.MozOpacity = (GM_Streetview)?GM_StreetOpa/100:0;
					break;
				    case "Explorer"	:
//					C.style.filter = 'alpha(opacity='+((GM_Streetview)?GM_StreetOpa:0)+')';
//					C.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + document.getElementById(i).src + "',sizingMethod='scale');" ;
					if(BrowserDetect.version<7) {
					C.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="
+ ((GM_Streetview)?GM_StreetOpa:0) + ");";
					} else {
//					    C.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0,finishOpacity=0)";
					C.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + document.getElementById(i).src + "',sizingMethod='scale')";
					C.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
					//C.style.backgroundImage='none';
					}

					break;
				    case "Safari"	:
					C.style.MozOpacity = (GM_Streetview)?GM_StreetOpa/100:0;
					break;
				}
*/
				if (document.getElementById("MyDiv_"+i))
				{
					var CC = document.getElementById("MyDiv_"+i) ;
					if (Street_IDChecked) {
						CC.style.visibility = 'visible' ;
						C.style.visibility = 'visible' ;
					} else {
						CC.style.visibility = 'hidden' ;
						C.style.visibility = 'hidden' ;
					}
				}
			}
		}

}


function getNewEncode (str)	// function untuk mengembalikan hasil encrypt code level, row, 'n col gambar peta
{
	str = str+"" ;
	//var code = "J-o-h-k-y-Z-2-4-7-9" ;	// string code
	var code = "I-n-T-1-m-4-P-S-7-d" ;  // new string code
	var arrCode = code.split("-") ;

	for(var i = 0 ; i < arrCode.length ; i ++)
	{
		var Regex = new RegExp(i+"","g") ;
		str = str.replace(Regex,arrCode[i]) ;
	}
	return str ;
}


function DrawTileMapStreetview(ObjName,L,C,R,W,H) {

//	if (GM_Level>4) {
		CheckMapBoundary();

		var BufX = Math.ceil(((1/2)*W)/GM_PieceW[L]) ;
		var BufY = Math.ceil(((1/2)*H)/GM_PieceH[L]) ;
		var DRObj = document.getElementById(ObjName) ;
		var DRObj3 = document.getElementById('GM_DrawingLayer_Streetview');
		if (Streetview_FirstShow == false)
		{
		  DRObj3.style.visibility = 'hidden';
		  DRObj3.style.display    = 'none';
		} else {
		  DRObj3.style.visibility = 'visible';
		  DRObj3.style.display    = '';
		}

		var Buffer = (BufX>BufY)?BufX:BufY ;

		for (var i in LoadedMap3) {
			if (document.getElementById(i))
			{
				var Img = document.getElementById(i) ;
				if (!Img.complete || Img.src.indexOf("blank.gif") > 0)
				{
					LoadedMap3[i] = "" ;
				}
			}
		}
		for (var B=0; B<=Buffer; B++)
		{
			for (var i=C-B;i<=C+B;i++){
				for (var j=R-B;j<=R+B;j++){
					var TileID3 = "GM_Tile3_" + j + "_" + i ;

	if (GM_Level>=5) {
		var MapURL3 = "http://"+SV_URL+"/map/r_streetview_au/" + getNewEncode(GM_Level+7) + "/" + getNewEncode(j) + "/" + getNewEncode(i) + ".png";
	} else {
		var MapURL3 = "http://"+SV_URL+"/map/r_streetview_au/L" + GetEncode(GM_Level+'') + "/R" + GetEncode(j+'') + "C" + GetEncode(i+'') + ".png" ;
	}

					if (LoadedMap3[TileID3] != 1)
					{
						LoadedMap3[TileID3] = 1 ;
						if (document.getElementById(TileID3))
						{
							var Img = document.getElementById(TileID3) ;
							Img.src = MapURL3 ;
							Img.className = "trans";
						} else {
/*							if ((!(SV_Browser || IEV >= 7)) && (GM_Level > 4))
							{
								var Div = document.createElement('div') ;
								Div.border = 0 ;
								Div.style.position = 'absolute' ;
								Div.id = "MyDiv_"+TileID3 ;
								Div.name = "MyDiv_"+TileID3 ;
								Div.style.width = (GM_PieceW[GM_Level]) + "px" ;
								Div.style.height = (GM_PieceH[GM_Level]) + "px" ;
//								Div.style.top = ((j-1) * GM_PieceH[GM_Level]) + "px" ;
//								Div.style.left = ((i-1) * GM_PieceW[GM_Level]) + "px" ;
							////// change to opera compatible /////////
								Div.style.top = ((j-1) * GM_PieceH[GM_Level]) - GM_YCenter + "px" ;
								Div.style.left = ((i-1) * GM_PieceW[GM_Level]) - GM_XCenter + "px" ;
								/////////////////////////////
								Div.ProgIDLoaded = false ;
								setTimeout("SetProgID('"+TileID3+"');",10);
							}
*/
							var Img = document.createElement('img') ;
							BlockRightClick(Img);
							Img.border = 0 ;
							Img.style.position = 'absolute' ;
							Img.id = TileID3 ;
							Img.name = TileID3 ;
							Img.width = GM_PieceW[GM_Level];
							Img.height = GM_PieceH[GM_Level];
//							Img.style.top = ((j-1) * GM_PieceH[GM_Level]) + "px" ;
//							Img.style.left = ((i-1) * GM_PieceW[GM_Level]) + "px" ;

							////// change to opera compatible /////////
							Img.style.top = ((j-1) * GM_PieceH[GM_Level]) - GM_YCenter + "px" ;
							Img.style.left = ((i-1) * GM_PieceW[GM_Level]) - GM_XCenter + "px" ;
							///////////////////////////////////////////
							Img.src = MapURL3 ;
							Img.className = "trans";
							Img.onload = function() {
//								this.style.visibility = 'hidden' ;
//								this.style.visibility = 'visible' ;
/*								if (document.getElementById("MyDiv_"+this.id))
								{
									var C = document.getElementById("MyDiv_"+this.id);
									if (C.ProgIDLoaded == false)
									{
										C.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"', sizingMethod='scale')" ;
										C.ProgIDLoaded = true ;
									}
								}
*/							}
							Img.onerror = function() {
								this.src = GM_ServerName+"/sd_new/images/blank.gif" ;
								LoadedMap[this.id] = "" ;
							}

/*							if ((!(SV_Browser || IEV >= 7)) && (GM_Level > 4))
							{
								Div.appendChild(Img);
								DRObj3.appendChild(Div);
							} else {
*/								DRObj3.appendChild(Img);
//							}
						}
					} else {
						var Img = document.getElementById(TileID3) ;
						if (Img.src.indexOf(MapURL3) < 0)
						{
							Img.src = MapURL3 ;
							Img.className = "trans";
						}
					}

				}
			}
		}
//	}
}






//v1.7
// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2007 Adobe Systems Incorporated.  All rights reserved.location
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful.

			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}

	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?');
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs)
{
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }

  //document.write(str);
  return str;
}

function AC_FL_RunContent(){
  var ret =
    AC_GetArgs
    (  arguments, ".swf?t=" +new Date().getTime()+"", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret =
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  return AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();

    switch (currArg){
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace":
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function showSV()
{
  var temp = document.getElementById('baloon');
  temp.style.visibility = 'visible';
  temp.style.display    = '';
}

function hideSV()
{
  var temp = document.getElementById('baloon');
  temp.style.visibility = 'hidden';
  temp.style.display    = 'none';
}

function showBaloon(streetview_ID, tmpWidth, tmpHeight)
{

	shopID = "";

    var b = (StreetViewLarge) ? document.getElementById("baloonLarge") : document.getElementById("baloonSmall");

    var parameters = "init=streetview-init.php&pid="+streetview_ID+"&pdeg="+StreetViewAngle+"&ref="+Math.round(Math.random(0,1)*100000000000) ;
    var width 	= Math.round(tmpWidth);
    var height 	= Math.round(tmpHeight); //need exact value for IE

    b.width  = (width+5) + 'px';
    b.height = (height+5) + 'px';
    b.style.visibility = 'hidden';

    if (b.innerHTML == "" || typeof( window.innerWidth ) == 'number')
    {
	var obj = AC_FL_RunContent(
	    'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
	    'width', width+'px',
	    'height', height+'px',
	    'src', 'StreetViewPlayer',
	    'quality', 'high',
	    'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
	    'align', 'middle',
	    'play', 'true',
	    'loop', 'true',
	    'scale', 'showall',
	    'wmode', 'window',
	    'devicefont', 'false',
	    'id', baloonId,
	    'bgcolor', '#000000',
	    'name', baloonId,
	    'menu', 'false',
	    'allowFullScreen', 'true',
	    'allowScriptAccess','sameDomain',
	    'movie', 'StreetViewPlayer',
	    'salign', '',
	    'FlashVars', parameters
  	);
   	b.innerHTML = obj;
   	OldStreetViewMode = false;
    } else {
	var objSwf = getFlashRef();
	objSwf.goPano(streetview_ID, StreetViewAngle, width, height);
    }
    b.style.visibility = 'visible';
    b.style.display    = '';
}

function showLocation(loc)
{
    LoadedStreetview = true;
    var tmpData = loc.split(";");

    var tmpID = tmpData[2];
    SV_Prev_Id = (StreetviewLocation[tmpID])?tmpID:SV_Prev_Id;
    
    writeToLog(tmpID, SV_CurrentId); /* write to statistic log */
    SV_CurrentId = tmpID; /* update current sv id */
    
    var sh = document.getElementById('spanHeader');
    sh.innerHTML = loc;

    pointOnclick(tmpID);

	if(document.frmEmailThisPage) {
		var fn = eval('document.frmEmailThisPage');
		fn.emailsvid.value = tmpID ;
		fn.svX.value = tmpData[3] ;
		fn.svY.value = tmpData[4] ;
	}
}

/**
 * write current location into statistic table
 * 
 * @param {Integer} currentId
 * @param {Integer} previousId
 */
function writeToLog(currentId, previousId)
{
	var url = "StreetviewStats.php";
	var data = 'c=' + currentId + '&p=' + previousId;
	$.ajax({
		url:url,
		data:data,
		beforeSend:function(){},
		success:function(msg){}
	});
}

/**
* function to get swf name
* @return swfName
*/

function getFlashRef()
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{

    return window[baloonId];
		//return window.StreetViewPlayer;
	} else {
		//return window.document.StreetViewPlayer;

		return document[baloonId];
	}
}


/**
* function to get photo angle from flash movie
*/

function getPhotoAngle()
{
    var camAngle = getFlashRef().getAnglePhoto();
    if (camAngle)	{
        camAngle = Math.round(camAngle);
        return camAngle;
    }
    else return 50;
}

//browser detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


// banner sponsor position
// http://192.168.0.5/sd_new_bk/mapsearch.cgi?x=145.03238940&y=-37.80648940&level=5&shopID=115308 <-- SASH


function displayBannerSV() {

//	CompassMove(GM_XCenter,GM_YCenter-210);
	Street_IDChecked = true ;
	ShopView_Status = true;
/*	StreetViewLarge = false;
	Streetview_MatchPos =0;
	pointOnclick(shopID);
	setTimeout('Streetview_OpenDialogBox('+shopID+')', 800);
	shopID = ""; // clear shopID after showing to prevent display it again
*/
//		    if (GM_StreetviewPoint) {
//				Streetview_Close();
				showFacing('still');
			    Streetview_MatchPos =0;
			    pointOnclick(shopID);				
			    setTimeout('Streetview_OpenDialogBox('+shopID+')', 800);
//			}
}

function getStreetviewStats(pid)
{
alert(pid);
}

// add by BK to show snapshot if the result of search only 1
function showSnapshot() {

	SearchLine = new jsGraphics('SearchLineDiv');
	//SearchLine = new jsGraphics('GM_DrawingLayer12');
	SearchGetThumbnailLocation (GM_X+","+GM_Y); // to get the sv id	
	if (oneResultOnly != false) {
		var Regex = new RegExp(",","g") ;
		oneResultOnly = oneResultOnly.replace(Regex,"<br />") ;
		//Search_SetArrow();
		oneResultOnly_OpenDialogBox();
	}
}


function oneResultOnly_OpenDialogBox() {
	SearchLine.clear();
	var HTML = "<table title=\"Drag & Drop is Available For This Layer\" cellpadding=2 cellspacing=1 border=0 bgcolor=\"#000000\" width=350>";
	HTML += "<tr><td class=content bgcolor=\"#D8DEED\">";
	HTML += "<table  id=\"Search_Title\" cellpadding=0 cellspacing=2 border=0 width=\"100%\"><tr>";
	HTML += "<td class=content align=\"right\"><a href=\"javascript: Search_Close();\"><img src=\"images/prop_close.gif\" border=0></a></td></tr></table></td></tr><tr>";
	HTML += "<td class=content bgcolor=\"#FFFFFF\">";
	HTML += "<table cellpadding=2 cellspacing=2 border=0 width=\"100%\"><tr>";
	if (SearchSvPhotoGroup != "") {
		HTML += "<td nowrap valign=top align=center class=content id=Search_Det_Left><a href=\"javascript: show_sv();\"><img src=\"displaysvimage.php?img="+ SearchSvPhotoGroup + "/" +SearchSvPhotoGroupID+".jpg&a1="+SearchSvBaseAngle+"&a2="+ StreetViewAngle +"\" width=\"140px\" height=\"100px\" border=0></a></td>";
		HTML += "<td valign=top class=content width=\"100%\" id=Search_Det_Right>"+ oneResultOnly +"<br /><br /><a href=\"javascript: show_sv();\">streetview</a></td></tr></table></td></tr></table>" ;
	} else {
		HTML += "<td valign=top class=content width=\"100%\" id=Search_Det_Right>"+ oneResultOnly +"<br /><br /></td></tr></table></td></tr></table>" ;
	}
	
	var PDB = document.getElementById('SearchDetailBox') ;
	PDB.innerHTML = HTML ;

	var P_DBMouse = document.getElementById('Search_Title') ;
	P_DBMouse.onmousedown = Search_DetailDrag ;
	P_DBMouse.onmouseup = new Function("p_dragapproved=false") ;

	PDB.style.visibility = 'visible' ;
	PDB.style.display = '' ;
	PDB.style.zIndex = '99999' ;
	var PX = GM_ConvertDegToPx(GM_X,GM_Y);
	PDB.style.left = document.getElementById('GenMapDiv').offsetLeft + PX.X - GM_Offset_Left + 10 ;
	PDB.style.top = document.getElementById('GenMapDiv').offsetTop + PX.Y - GM_Offset_Top + 10 ;	

	if (parseInt(PDB.style.left) + PDB.clientWidth >=  window.screen.width-20)
	{
		PDB.style.left = parseInt(PDB.style.left) - PDB.clientWidth - 38 ;
	}
	if (parseInt(PDB.style.top) + PDB.clientHeight >=  window.screen.height-180)
	{
		PDB.style.top = parseInt(PDB.style.top) - PDB.clientHeight - 38 ;
	}
}

function Search_DetailDrag(e) {
	p_dragapproved=true;
	z= document.getElementById('SearchDetailBox');
	temp1=parseInt(z.style.left);
	temp2=parseInt(z.style.top);
	x = DD_nn6 ? e.clientX : event.clientX ;
	y = DD_nn6 ? e.clientY : event.clientY ;
	document.onmousemove=Search_DetailMove;
}

function Search_DetailMove(e) {
	if (p_dragapproved){
		XMouseClick = DD_nn6 ? e.clientX : event.clientX ;
		YMouseClick = DD_nn6 ? e.clientY : event.clientY ;
		z.style.left=temp1+XMouseClick-x;
		z.style.top=temp2+YMouseClick-y;
		//Search_SetArrow();		
		return false;
	}
}



function Search_SetArrow() {
	SearchLine.clear();
	var PDB = document.getElementById('SearchDetailBox') ;
	if (PDB.style.visibility == 'visible')
	{
		var left = parseInt(PDB.style.left);
		var top = parseInt(PDB.style.top);
		var right = left + PDB.clientWidth;
		var bottom = top + PDB.clientHeight;

		var ICN = GM_ConvertDegToPx(GM_X,GM_Y); 
		
		var IconLeft = document.getElementById('GenMapDiv').offsetLeft + ICN.X - GM_Offset_Left;
		var IconTop = document.getElementById('GenMapDiv').offsetTop + ICN.Y - GM_Offset_Top;

		var XB = (IconLeft > (left+right)/2)?right-1:left+1;
		var YB = (IconTop > (top+bottom)/2)?bottom-1:top+1;

		GM_SetLine(SearchLine,2,'#02287B',IconLeft,IconTop,XB,YB);
		GM_SetLine(SearchLine,1,'#D8DEED',IconLeft,IconTop,XB,YB);
	
		var PDD = document.getElementById('SearchLineDiv');
		PDD.style.zIndex = 99982 ;

		if (!(ICN.X >= GM_Offset_Left && ICN.X <= GM_Offset_Right && ICN.Y >= GM_Offset_Top && ICN.Y <= GM_Offset_Bottom))
		{
			Search_Close();
		}
	}
}

function Search_Close() {
	var PDB = document.getElementById('SearchDetailBox') ; 
	PDB.style.visibility = 'hidden' ;
	PDB.style.display = 'none' ;
	PDB.style.zIndex = '0' ;
	SearchLine.clear();
}

function show_sv() {

	Search_Close();
	document.getElementById("Streetview_checkbox").checked = true;
	Street_PropCheck();
	var longlat = GM_X+","+GM_Y;
	SV_moveCenterViewToNearestPoint (longlat);

}	

function SearchGetThumbnailLocation (longlat)
{
     var minDistance    = 0.05;
	var tmpSV_CV_Long=0;
	var tmpSV_CV_Lat=0;
	
    if(longlat) {
		var D = longlat.split(",");
		tmpSV_CV_Long= D[0];
		tmpSV_CV_Lat= D[1];
    }

    SV_Old_Id    = SV_FocusId;
    SV_Old_Long  = SV_FocusLong;
    SV_Old_Lat   = SV_FocusLat;

    for (var i in StreetviewLocation)
    {
		var W = StreetviewLocation[i] ;
		if (W.Pid == 1) /* only apply this for streetview only */
		{
			var temp  = SV_getDistance(SV_CV_Long, SV_CV_Lat, W.Long, W.Lat);
			if (temp < minDistance)
			{
				SearchSvId   = W.ID;
				SearchSvLong = W.Long;
				SearchSvLat  = W.Lat;
				SearchSvPhotoGroup  = W.PhotoGroup;
				SearchSvPhotoGroupID  = W.PhotoGroupID;
				SearchSvBaseAngle = W.BaseAngle;
				minDistance  = temp;
			}
		}
    }
	
	var Regex  = /^[1-9]/;
	var a = Regex.test(oneResultOnly);
	if (a) {
		StreetViewAngle = (getAnglefor2Point(SearchSvLong,SearchSvLat,GM_X,GM_Y)+360-parseInt(SearchSvBaseAngle))%360;	
	} else {
		StreetViewAngle = 0;
	}
}
	
function getAnglefor2Point(x1,y1,x2,y2) {

	var pie = 360.0/2.0/Math.PI;
	var dx = (x2-x1);
	var dy = (y2-y1);
	var finalAngle = 0;

	if (dx ==0 && dy == 0) {
		finalAngle = 0;
	} else if (dx == 0 && dy >0) {
		finalAngle = 90;	
	} else if (dx == 0 && dy<0) {
		finalAngle = 270;		
	} else if (dx >= 0 && dy >=0) {
		var result = Math.abs(dy/dx);
		finalAngle = Math.atan(result)*pie;
	} else if (dx <0 && dy>=0) {
		var result = Math.abs(dy/dx);
		finalAngle = 180 - (Math.atan(result)*pie); 		
	} else if (dx<0 && dy <0) {
		var result = Math.abs(dy/dx);
		finalAngle = 180 + (Math.atan(result)*pie);
	} else if (dx>=0 && dy<0) {
		var result = Math.abs(dy/dx);
		finalAngle = 360 - (Math.atan(result)*pie);		
	} 
	if (finalAngle <= 90) {
		finalAngle = 90 - finalAngle;
	} else {
		finalAngle = 360 + 90 - finalAngle;
	}
	return finalAngle;
}	

/**
 * get the current host location
 * 
 * @return	{string}
 */
function getCurrentHost()
{
	return top.location.host;
}
