function preloadImages( imageRoot )
{
  if (document.images) {  
  preloadPics( imageRoot,
        'jetlogo',  'jetlogo-'  );
  }
  
  preloadFlag = true;
}

/**/
var currentSection;
var currentUrl;
var planetsLoaded;
var isCurrentSection;
var goingoff;

isCurrentSection = 1;

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}

function makeCall(str) {
  thisMovie("newplanets").asFunc(str);
}

function initSection( section ){
  if(!so.installedVer.versionIsValid(8)){    
    return false; 
  }
  
  currentSection = section;

  onBodyResize();
  document.body.onresize = function (){ onBodyResize() };  
  checkForPlanets();  
}

function onBodyResize(){
    pageHeight = findObj("inner").clientHeight;
    if (window.innerHeight) pageHeight = Math.max(pageHeight,window.innerHeight);
    if (document.documentElement.clientHeight)
       pageHeight = Math.max(pageHeight,document.documentElement.clientHeight);
    findObj("oversky").style.height= 
    findObj("newplanets").style.height= pageHeight+"px";
}

function onPlanetsLoaded( str ){    
  planetsLoaded = true;  
}

function prepareUnload(lnk){  
  //нажали на ссылку 
  if(!so.installedVer.versionIsValid(8)){    
    return true; 
  }
	if (!e) var e = window.event;
  if (e.shiftKey) return true; // в новом окне -- открывать как обычно
  
  u = lnk.href;
  window.setTimeout('makeCall("'+currentSection+'_off");',10);
  currentUrl = u;
  window.setTimeout('onPlanetsOff();',2500);
  return false;  
}

function checkForPlanets(){
  if (planetsLoaded) {
    //alert('planetsLoaded');
    goingoff=0;
    if (isCurrentSection)
      window.setTimeout('makeCall("'+currentSection+'_idle");',100);
    else
      window.setTimeout('makeCall("'+currentSection+'");',100);
    return; 
  }
  else {
    window.setTimeout('checkForPlanets();',100);    
  } 
}  

function animateProperty( id, property, prop_before, prop_after, val, max, step, delay ){
  if (val>=max) return;
  val += step;
  findObj(id).style[property]=prop_before+val+prop_after;
  window.setTimeout('animateProperty( "'+id+'", "'+property+'", "'+prop_before+'", "'+prop_after+'", '+val+', '+max+', '+step+', '+delay+');', delay );
}

function onPlanetsOff( str ){
  /* fly away */
  cC( 'oversky', 'active-' );
  animateProperty('oversky','opacity','','',0,1,0.1,100);
  animateProperty('oversky','-moz-opacity','','',0,1,0.1,100);
  animateProperty( 'oversky','filter','alpha(opacity=',')',0,100,10 );
  window.setTimeout('goingoff=1;',900);
  window.setTimeout('window.location.href="'+currentUrl+'";',1000);
}

function writeFlashObject( f ){
  
  if (!so.installedVer.versionIsValid(8))
    return;
    
  /* TODO вставить проверку -- если флэша нету, то не выводить его и все красоты отключить */
  document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
  document.write('id="newplanets"');
  document.write('codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="100%" height="100%">');
     
  document.write('<param name="allowScriptAccess" value="always" />');
  document.write('<param name="movie" value="'+f+'" />');
  document.write('<param name="wmode" value="transparent" />');
  document.write('<param name="menu" value="true" />');
  document.write('<param name="quality" value="high" />');
  document.write('<param name="scale" value="noscale" />');
  document.write('<param name="salign" value="rt" />');
  document.write('<param name="bgcolor" value="#fff" />');
  document.write('<param name="swliveconnect" value="true" />');

  document.write('<embed src="'+f+'" name="newplanets" wmode="transparent" wLiveConnect="true" menu="true" quality="high" scale="noscale" salign="rt" bgcolor="#fff" width="100%" height="100%"  allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" >');
  document.write('</embed>');
  document.write('</object>');
}

function returntToBegin() {
    goingoff=0;
    window.setTimeout('makeCall("'+currentSection+'");',100);
    cC( 'oversky', ' ' );
}

function onTimer() {
  if (goingoff) {
    //alert('обратно');
    returntToBegin();
  }
}

window.setTimeout( 'onTimer();', 1000 );