var map = new Array();
var x = 'home';
map[x] = new Array();
map[x][1] = "http://Costa-Rica-guide.com/index.html";
map[x][3] = "/site_map.htm";
map[x][6] = "/Search.html";
map[x][8] = "/AboutSupport.html";

x = 'maps';
map[x] = new Array();
map[x][1] = "/MapStore.html";
map[x][3] = "/Atlas.html";
map[x][5] = "/Sheet.html";
map[x][8] = "/Topo.html";
map[x][11] = "/Natural/NaturalMap.html";
map[x][15] = "/images/maps/map_rts.htm";
map[x][18] = "/GifJpg.html";
map[x][20] = "/Custom.html";
map[x][22] = "/MapLinks.html";
map[x][25] = "blank";

x = 'books';
map[x] = new Array();
map[x][1] = "/Books/Guidebooks.html";
map[x][4] = "/Books/FieldGuides.html";
map[x][7] = "/Books/Language.html";
map[x][10] = "/Books/Leisure.html";
map[x][12] = "/Books/NaturalHist.html";
map[x][16] = "/Books/CoffeeTable.html";
map[x][19] = "/Books/BooksAlphabet.html";
map[x][24] = "/Books/EBooks.html";
map[x][26] = "blank";

x = 'resources';
map[x] = new Array();
map[x][1] = "blank";
map[x][4] = "/Natural/NaturalMap.html";
map[x][8] = "/WWWLinks.html";
map[x][10] = "/BusSchedule.html";
map[x][13] = "/RentalCar.html";
map[x][16] = "/Airlines.html";
map[x][18] = "/fr_maps.htm";
map[x][20] = "/Books/Books.htm";
map[x][22] = "blank";

x = 'planning';
map[x] = new Array();
map[x][1] = "/plan.htm";
map[x][3] = "/group.htm";
map[x][6] = "/when.htm";
map[x][10] = "/alt_cent.htm";
map[x][13] = "/WhatToDo.html";
map[x][16] = "/pack.htm";
map[x][19] = "/Plan/Health.html";
map[x][21] = "/Plan/Safety.html";
map[x][23] = "/Books/Guidebooks.html";
map[x][26] = "/MapStore.html";
map[x][28] = "/stories/road_cde.htm";
map[x][30] = "blank";

x = 'photos';
map[x] = new Array();
map[x][1] = "blank";
map[x][8] = "/images/photos/other/photo_ls.htm";
map[x][12] = "/th_pages/th_coff1.htm";
map[x][15] = "/th_pages/th_peop1.htm";
map[x][17] = "/th_pages/th_anim1.htm";
map[x][20] = "/th_pages/th_bird1.htm";
map[x][22] = "/th_pages/th_inse1.htm";
map[x][25] = "/th_pages/th_flow1.htm";
map[x][27] = "/th_pages/th_orch1.htm";
map[x][29] = "blank";

x = 'travelogues';
map[x] = new Array();
map[x][1] = "blank";
map[x][21] = "/images/maps/map_rts.htm";
map[x][25] = "/tour_pgs/tour99a/tour99a.htm";
map[x][27] = "/tour_pgs/tour96/tour96.htm";
map[x][29] = "/tour_pgs/tour93.htm";
map[x][1] = "blank";

var path = "/Swap";
var ext  = ".gif";
var spacerImg = "/Swap/spacer.gif";
var preloadArr = new Array("home","maps","books","resources","planning","photos","travelogues");
var allImages = new Array();
var curOn = "";
var defOnlvl2 = null;
var defOn = "";
var tid = "";
var haveTid = false;
var delay = 3000;
var allLoaded = false;
var barImg = "bar";

function preload() {
  curOn = defOn;
  preloadImages('on','_over');
  preloadImages('off','');
  preloadImages('bar','_bar');
  allLoaded = true;
}

function preloadImages(array,suffix) {
  allImages[array] = new Array();
  if (document.images) {
    for (var i = 0; i < preloadArr.length; i++) {
      var name = preloadArr[i];
      allImages[array][name] = new Image();
      allImages[array][name].src = path+"/"+name+suffix+ext;
      //window.status = (allImages[array][name].src);
    }
  }
}

function on(imgName) {
  if (!allLoaded) return false;
  if (haveTid) {
    clearTimeout(tid);
    haveTid = false;
    swap('off', curOn, curOn);
  } else if (defOn != "") {
    swap('off', defOn, defOn);
  }
  curOn = imgName;
  swap('on', imgName, imgName);
  swaplvl2(imgName);
  return true;
}

function off(imgName) {
  if (!allLoaded) return false;
  tid = setTimeout("actOff('"+imgName+"')", delay);
  haveTid = true;
  return true;
}

function actOff(imgName) {
  if (curOn != "" && curOn != defOn) {
    swap('off', imgName, imgName);
    curOn = "";
    if (defOn != "") {
      curOn = defOn;
      swap('on', defOn, defOn);
      swaplvl2(defOn);
    }
  }
}

function onlvl2(num) {
  if (!allLoaded) return false;
  if (haveTid) {
    clearTimeout(tid);
    haveTid = false;
  }
  window.status = getURL(num);
  return true;
}

function offlvl2(num) {
  if (!allLoaded) return false;
  if (curOn != "") {
    off(curOn);
  }
  window.status = window.defaultStatus;
  return true;
}

function swap(array,imgname,srcname) {
  if (document.images) {
    //alert("array "+array+"\n"+"imagename "+imgname+"\n"+document.images[imgname].src + " = " + allImages[array][srcname].src);
   	document.images[imgname].src = allImages[array][srcname].src;
  }
}

function swaplvl2(name) {
  if (document.images) {
      document.images[barImg].src = allImages['bar'][name].src;
  }
}

function getURL(num) {
  var url = "";

  if ((defOn != "" || curOn != "") && num >= 0) {
    var onMap = defOn;
    if (curOn != "") onMap = curOn;
      
    for (var i = num; i > 0; i--) {
      var toPage = map[onMap][i];
      if (toPage != null && toPage != "") {
        if (toPage == "blank")  return ""; 
        //alert("topage: '" + window.location.host +"'\n");
		url = "http://"+window.location.hostname+toPage; 
        if (window.location.protocol == "https:") url = "http://costa-rica-guide.com"+toPage;
        if (window.location.host == "search.atomz.com") url = "http://costa-rica-guide.com"+toPage;
        if (toPage.substring(0,4) == "http")  url = toPage;
        break;
       }
     }

  }
  return url;
}


// this function is not currrenly used
function jump(num) {
  var toPage = getURL(num);
  if (toPage != "") {
    window.location.href = toPage;
  }
}

// this function is not currrenly used
function click(toPage) {
  //window.location.href = buildURL(toPage);
  window.location.href = toPage;
  return false;
}

// this function is not currrenly used
function buildURL(toPage) {
  var port = window.location.port;
  if (port != null && port != "") {
    port = ":"+port;
    if (port == ":443") port = "";
  }
  if (toPage.indexOf("://") != -1) {
    toPage = toPage.substring(toPage.indexOf('/',toPage.indexOf(":")+3),toPage.length);
  }
  return "http://"+window.location.hostname+port+toPage;
}


