// astronomy for kids site navigation script

var navDir = "/afk/images/navbuttons/";
var atmospheredef = "The gases that surround a body, like the air here on Earth.";
var axisdef = "An imaginary line going from top to bottom through a body, like the spindle of a top.";
var crypticdef = "Something that appears to be in some kind of code or is expressed in a very short fashion. Also can mean not very clear at first glance.";
var cometdef = "A comet is a like a dirty snowball with lots of stuff in it besides snow.";
var desolatedef = "Empty, uninhabited, deserted. A wasteland";
var ellipsedef = "Like a circle that has been squeezed to flatten it.";
var enigmaticdef = "Something that is mysterious, not easily understood or not obvious.";
var equatordef = "An imaginary line going around a body at its center.";
var equivalentdef = "The same as or equal to";
var infrareddef = "The part of the light spectrum beyond the red band in a rainbow. Invisible to humans.";
var mythologydef = "Old religions, tales, stories. An interesting subject in itself";
var novadef = "A nova is a very bright light that usually results from a star exploding";
var omendef = "An omen is a sign, or hint, of things to come.";
var ominousdef = "Threatening, evil, bad, sinister";
var orbitdef = "The path that one object follows while it moves around another body.";
var remnantsdef = "Things that are left behind after an event, like puddles after a storm.";
var shroudeddef = "Covered up, not easily seen, like a blanket over a chair.";
var tantalyzingdef = "Exciting, interesting, like looking forward to dessert.";
var turbulentdef = "Turbulent means greatly disturbed, like boiling water or the clouds in a thunderstorm.";

var definitionDiv;var defWidth = 200;var rollover = true;
var switcher = true;var pageLoaded = false;var moz;

// page start function
function pageStart(){
  s = navigator.userAgent;
  if(s.indexOf("Gecko") != -1)
    moz = true;
  loadImages();
  definitionDiv = gE('definition');pageLoaded = true;
}

// show the definition
function showDef(evt,word) {
  var x = evt.clientX;var y = evt.clientY;var sT = gsT();var bW = gbW();var bH = gbH();
  var def = "";var defLeft = defWidth / 2;var defTop = 0;var wordDef = word.toLowerCase();
  var def = eval(wordDef + 'def');var dH = 0;var counter = 0;
  wH(definitionDiv,"<span class='word'>"+ word + "</span><br>" + def);
  dH = gcH(definitionDiv);
  dH += 20;
  // check and adjust the vertical position of the popup if necessary
  defTop = y + sT - dH;    // guess at a pretty good average vertical position
  if((sT + bH - defTop) < dH){np = sT + bH - y;while(np < dH + 30){defTop -= 20;np += 20;}}
  else if(defTop < sT){defTop = sT;while(defTop < sT + y){defTop += 20;counter += 20;}}
  defLeft = x - defLeft;defLeft = defLeft < 0 ? x : defLeft;sX(definitionDiv,defLeft);
  sY(definitionDiv,defTop);sE(definitionDiv);
  return false;
}

function hideDef() {hE(definitionDiv);return false;}

// frame breakout stuff
var breakText = '<tr width="100%"><td width="100%" align="right"><font face="verdana,arial" size="-1"><b>Break out of the frames by clicking <a href="#" onClick="frameBreak()"><b>here</b></a></td></tr>';

function frameBreak() {top.location.href = "http://www.dustbunny.com/afk";}

// load the navigation images
function loadImages() {
  // home button
  home_on = new Image(70,100);home_on.src = navDir + "home_on.gif";home_off = new Image(70,100);home_off.src = navDir + "home_off.gif";
  // top nav bar buttons
  pl_on = new Image(80,20);pl_on.src = navDir + "pl_on.gif";pl_off = new Image(80,20);pl_off.src = navDir + "pl_off.gif";
  sm_on = new Image(80,20);sm_on.src = navDir + "sm_on.gif";sm_off = new Image(80,20);sm_off.src = navDir + "sm_off.gif";
  sw_on = new Image(80,20);sw_on.src = navDir + "sw_on.gif";sw_off = new Image(80,20);sw_off.src = navDir + "sw_off.gif";
  co_on = new Image(80,20);co_on.src = navDir + "co_on.gif";co_off = new Image(80,20);co_off.src = navDir + "co_off.gif";
  be_on = new Image(80,20);be_on.src = navDir + "be_on.gif";be_off = new Image(80,20);be_off.src = navDir + "be_off.gif";
  // bottom nav bar buttons
  po_on = new Image(80,25);po_on.src = navDir + "po_on.gif";po_off = new Image(80,25);po_off.src = navDir + "po_off.gif";
  pz_on = new Image(80,25);pz_on.src = navDir + "pz_on.gif";pz_off = new Image(80,25);pz_off.src = navDir + "pz_off.gif";
  ga_on = new Image(80,25);ga_on.src = navDir + "pz_on.gif";ga_off = new Image(80,25);ga_off.src = navDir + "pz_off.gif";
  // left side nav buttons
  lhb_on = new Image(70,15);lhb_on.src = navDir + "lhb_on.gif";lhb_off = new Image(70,15);lhb_off.src = navDir + "lhb_off.gif";
  lsm_on = new Image(70,15);lsm_on.src = navDir + "lsm_on.gif";lsm_off = new Image(70,15);lsm_off.src = navDir + "lsm_off.gif";
  lsi_on = new Image(70,15);lsi_on.src = navDir + "lsi_on.gif";lsi_off = new Image(70,15);lsi_off.src = navDir + "lsi_off.gif";
  lcn_on = new Image(70,15);lcn_on.src = navDir + "lcn_on.gif";lcn_off = new Image(70,15);lcn_off.src = navDir + "lcn_off.gif";
  lre_on = new Image(70,15);lre_on.src = navDir + "lre_on.gif";lre_off = new Image(70,15);lre_off.src = navDir + "lre_off.gif";
  lsh_on = new Image(70,15);lsh_on.src = navDir + "lsh_on.gif";lsh_off = new Image(70,15);lsh_off.src = navDir + "lsh_off.gif";
}

function puzzlePop(puzzleName){
  if(! op){var puzzleUrl = "/afk/puzzles/" + puzzleName + "pop.html";var pw = window.open(puzzleUrl,"puzzle","width=600,height=450");}
  else {alert("Sorry! The puzzle will not work in your browser.")}
}

function contact(){
    var pw = window.open("/afk/contact/popcontact.html","contact","width=620,height=500,scrollbars,resizable");
}

function navOn(navImg) {onSrc = navDir + navImg + "_on.gif";document.images[navImg].src = onSrc;}

function navOff(navImg) {offSrc = navDir + navImg + "_off.gif";document.images[navImg].src = offSrc;}

// style sheet switching stuff
function setStyle(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title)
      {
        a.disabled = false;
        if((title != "default") && pageLoaded && moz)
        {
          location.reload();
        }
      }
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");var title = cookie ? cookie : getPreferredStyleSheet();setStyle(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setStyle(title);
window.defaultStatus="Astronomy for Kids";



