var ready = 0;

function declareReady()		{ ready = 1; }
function runScript(fkt) 	{ if (ready) { document.getElementById('bgapplet').runScript(fkt); } }
function startPlay() 		{ runScript("bg:startAutoPan(0.5,0,1);"); }
function stopPlay() 		{ runScript("bg:stopAutoPan();"); }
function zoomIn()			{ runScript("bg:startAutoPan(0,0,0.97);"); }
function zoomOut()			{ runScript("bg:startAutoPan(0,0,1.03);"); }
function toggleSpots()		{ runScript("bg:toggleLinks();"); }
function gotoPano(id)		{ curAct = -1; runScript("bg:gotoPano(" + id + ");"); }
function actSpot(panoID)	{ runScript("bg:activateSpot(" + panoID + ");") }
function deactSpot(panoID)	{ runScript("bg:deactivateSpot(" + panoID + ");") }
function showMapImg(id)		{ runScript("bg:showMapImg(" + id + ");") }
function hideMapImg()		{ runScript("bg:hideMapImg();") }
function viewCone(id)		{ runScript("bg:viewCone(" + id + ");") }
function viewMapSpots(id)	{ runScript("bg:viewMapSpots(" + id + ");") }

// --- S Y N C --- //

var lastDetail = "";
var marker = 0;
var activ = window.setInterval("cycle()",200);

function cycle(){
   if (marker == 1 && lastDetail != ""){
      marker = 2;
      loc_detail = lastDetail;
      lastDetail = "";
      showDetail(loc_detail);
   }
   if (marker == 0 && lastDetail != ""){  // neuzugang, warten auf abarbeitung
      marker = 1;
   }
}

function showDetail(detail) { viewCone(0); viewMapSpots(0); showMapImg(detail); }
function hideDetail() 		{ if (marker == 2) { viewCone(1); viewMapSpots(1); hideMapImg(); } marker = 0; lastDetail = ""; }
function prepareDetail(detail)	{ lastDetail = detail; marker = 0; }

// --- S Y N C 2 --- //

function actSpot(panoID)	{ if (ready) _nhl = panoID; }
function deactSpot(panoID)	{ if (ready) _nhl = -1; };

var activ2 = window.setInterval("cycle2()",150);
var _chl = -1;   // current highlight
var _nhl = -1;   // new highlight
var chl = -1;   // current highlight local
var nhl = -1;   // new highlight local

function cycle2(){
   chl = _chl; // to prevent changes during cycle from evants...
   nhl = _nhl;
   if (chl == nhl){  // same spot, do nothing...
      return;
   }
   if (chl != -1){  // left the spot, deactivate current...
      var fkt = "bg:deactivateSpot(" + chl + ");";
      runScript(fkt);
      _chl = -1;
   }
   if (nhl != -1){
      var fkt = "bg:activateSpot(" + nhl + ");";
      runScript(fkt);         
      _chl = nhl;
   }
}
