

// for the search function
function searchSubmit() {
    document.getElementById('googlevalue').value += " site:www.quest.org";
}

var navData = new Array(
/*
 Top nav parameters are: Display name, URL, code id
*/
["Home", "/", "home"],

["About Us", "/about", "about",
 ["What's Quest?", "/about"],
 ["How a LARP Works", "/about/larp.shtml"],
 ["FAQ", "/about/faq.shtml"],
 ["Sitemap", "/about/sitemap.shtml"]
], 

["Events", "/events", "events",
 ["Directions", "/events/directions.shtml"],
 ["Prices", "/events/prices.shtml"],
 ["Lodging", "/events/lodging.shtml"],
 ["List of Past Events", "/events/gamelist.shtml"],
 ["Tips for Weekend Events", "/events/tips-weekend.shtml"]
], 

["Rules", "/rules", "rules",
 ["Introduction", "group",
  ["Getting Started", "/rules/intro/gettingstarted.shtml"],
  ["Player Conduct", "/rules/intro/playerconduct.shtml"]
 ],
 ["Character Creation", "group",
  ["Character Generation Reference", "/rules/characters/chargenref.shtml"],
  ["Natural Talents", "/rules/characters/naturaltalents.shtml"],
  ["Abilities", "/rules/characters/abilities.shtml"],
  ["Weapon Skill", "/rules/characters/weaponskill.shtml"],
  ["Disadvantages", "/rules/characters/disadvantages.shtml"],
  ["Natural Limitations", "/rules/characters/naturallimits.shtml"],
  ["Mystic Magic", "/rules/characters/mystic.shtml"]
 ],
 ["Rules of Gameplay", "group",
  ["Rules of Combat", "/rules/rog/rulesofcombat.shtml"],
  ["Rules of Magic", "/rules/rog/rulesofmagic.shtml"],
  ["Reacting to Skills", "/rules/rog/reacting.shtml"],
  ["Using Items", "/rules/rog/usingitems.shtml"],
  ["Theft", "/rules/rog/theft.shtml"],
  ["Other Effects", "/rules/rog/othereffects.shtml"],
  ["What's In-Game", "/rules/rog/ingame.shtml"],
  ["Optional Conventions", "/rules/rog/optional.shtml"],
  ["Making Your Own Quest Equipment", "/rules/rog/yourown.shtml"]
 ],
 ["Spell List and Glossary", "group",
  ["Spell Lists", "/rules/spells/lists.shtml"],
  ["Mage Spell Glossary", "/rules/spells/magegloss.shtml"],
  ["Cleric Spell Glossary", "/rules/spells/clergloss.shtml"],
  ["Meta-Magic Glossary", "/rules/spells/metagloss.shtml"]
 ],
 ["The Continuing Game", "group",
  ["Introduction", "/rules/cg/intro.shtml"],
  ["CG Rules", "/rules/cg/rules.shtml"],
  ["The World of the CG", "/rules/cg/world.shtml"],
  ["Kingdoms of Hesket", "/rules/cg/countries.shtml"],
  ["Religion in the CG", "/rules/cg/pantheonintro.shtml"],
  ["The Gods of the Pantheon", "/rules/cg/pantheongods.shtml"],
  ["Player Races in the CG", "/rules/cg/races.shtml"]
 ],
 ["Download Rules and Spells", "/rules/downloads.shtml"],
 ["Current Rules Interpretations", "/rules/interpretations.shtml"],
 ["What's New This Year", "/rules/whatsnew.shtml"]
], 

["Players", "/players", "players",
 ["New Player Guide", "/newplayer"],
 ["Glossary", "/newplayer/glossary.shtml"],
 ["Skill Cards", "/players/cards.shtml"],
 ["Making a Flail", "/players/flail.shtml"]
],

["GMs", "/gm", "gm",
 ["The GM Process", "/gm/gmprocess.shtml"],
 ["Teaser Format", "/gm/teaser-format.shtml"],
 ["Spaces and Reservations", "/gm/spaces.shtml"],
 ["Game Packets", "/gm/packets.shtml"],
 ["How to NPC Well", "/gm/howtonpc.shtml"],
 ["Character Survey", "/gm/charactersurvey.shtml"],
 ["Maps of Wesleyan", "/gm/maps-wesleyan.shtml"],
 ["Maps of Pomfret", "/gm/maps-pomfret.shtml"],
 ["Uncle Lloyd's Tips and Tricks", "group",
  ["Overview", "/ul"],
  ["Advice for Aspiring GMs", "/ul/gm-advice.shtml"],
  ["Giving Characters Foreign Names", "/ul/foreignnames.shtml"],
  ["Town Name  Generator", "/ul/townnames.shtml"],
  ["Ancient Languages", "/ul/lang.shtml"],
  ["Old or Weathered Documents", "/ul/agedoc.shtml"],
  ["How to Be Old", "/ul/oldage.shtml"],
  ["Horde Banner", "/ul/hordebanner.shtml"],
  ["In-Game Alcohol", "/ul/booze.shtml"],
  ["Foreign Fonts", "/ul/foreignlang.shtml"],
  ["Materials", "/ul/materials.shtml"],
  ["Props in Unlikely Places", "/ul/propsunlikely.shtml"],
  ["Songbook", "/ul/songbook.shtml"],
  ["Swimming", "/ul/swimming.shtml"],
  ["Underwater", "/ul/underwater.shtml"],
  ["Burning", "/ul/burning.shtml"],
  ["Flying", "/ul/flying.shtml"],
  ["Hardship", "/ul/hardship.shtml"],
  ["Handy Links", "/ul/links.shtml"],
  ["Quest Style Guide", "/ul/style.shtml"]
 ]
], 


["the CG", "/cg", "cg",
 ["Your Character", "group",
  ["Curses", "/cg/curses.shtml"],
  ["Making a Proposal", "/cg/characterguidelines.shtml"],
  ["Proposal Examples", "/cg/characterguidelines-examples.shtml"],
  ["Mage Archetypes", "/cg/mage-archetypes.shtml"],
  ["Magical Traditions", "/cg/magicaltraditions.shtml "],
  ["Player Packets", "/cg/playerpackets.shtml"]
 ],
 ["Countries", "group",
  ["Overview", "/cg/countries/index.shtml"],
  ["Allondell", "/cg/countries/allondell.shtml"],
  ["Bilgosh", "/cg/countries/bilgosh.shtml"],
  ["Bonalba", "/cg/countries/bonalba.shtml"],
  ["Cadfaigh", "/cg/countries/cadfaigh.shtml"],
  ["Castagna", "/cg/countries/castagna.shtml"],
  ["Chardreau", "/cg/countries/chardreau.shtml"],
  ["Delona", "/cg/countries/delona.shtml"],
  ["Grendarr", "/cg/countries/grendarr.shtml"],
  ["Iņarra", "/cg/countries/inarra.shtml"],
  ["Kiljukan", "/cg/countries/kiljukan.shtml"],
  ["Kislevia", "/cg/countries/kislevia.shtml"],
  ["Kjolnir", "/cg/countries/kjolnir.shtml"],
  ["Linneraigh", "/cg/countries/linneraigh.shtml"],
  ["Malema", "/cg/countries/malema.shtml"],
  ["Marakhin", "/cg/countries/marakhin.shtml"],
  ["Philiathos", "/cg/countries/philiathos.shtml"],
  ["Ragnorack", "/cg/countries/ragnorack.shtml"],
  ["Roudoigne", "/cg/countries/roudoigne.shtml"],
  ["Shenga", "/cg/countries/shenga.shtml"],
  ["Steinlands", "/cg/countries/steinlands.shtml"],
  ["Tamplonia", "/cg/countries/tamplonia.shtml"],
  ["Trenzano", "/cg/countries/trenzano.shtml"],
  ["Valenne", "/cg/countries/valenne.shtml"],
  ["Vallino", "/cg/countries/vallino.shtml"],
  ["Veneza", "/cg/countries/veneza.shtml"],
  ["Yamamoto (and Seiguntou)", "/cg/countries/yamamoto.shtml"],
  ["Zdunarova", "/cg/countries/zdunarova.shtml"]
 ],
 ["Atlas of Hesket", "/cg/atlas"],
 ["Churches", "group",
  ["The Pantheon","/cg/churches/"],
  ["Organization and Terminology","/cg/churches/organization.shtml"],
  ["The Collegium ","/cg/churches/collegium.shtml"],
  ["Cosmology","/cg/churches/cosmology.shtml"],
  ["Saints","/cg/churches/saints.shtml"],
  ["the Liber Precium","/cg/churches/liberprecium.shtml"],
  ["divider","/"],
  ["Nen","/cg/churches/nen.shtml"],
  ["Alia","/cg/churches/alia.shtml"],
  ["Balthazar","/cg/churches/balthazar.shtml"],
  ["Brinnig","/cg/churches/brinnig.shtml"],
  ["Dorial","/cg/churches/dorial.shtml"],
  ["Elune","/cg/churches/elune.shtml"],
  ["Furthane","/cg/churches/furthane.shtml"],
  ["Kahla-ran","/cg/churches/kahlaran.shtml"],
  ["Kintaka","/cg/churches/kintaka.shtml"],
  ["Kyta","/cg/churches/kyta.shtml"],
  ["Majenir","/cg/churches/majenir.shtml"],
  ["Perinnia","/cg/churches/perinnia.shtml"],
  ["Rannash","/cg/churches/rannash.shtml"],
  ["Sarana","/cg/churches/sarana.shtml"],
  ["Tiranon","/cg/churches/tiranon.shtml"],
  ["Tralados","/cg/churches/tralados.shtml"],
  ["Ubrialla","/cg/churches/ubrialla.shtml"],
  ["Zotra","/cg/churches/zotra.shtml"]
 ],
 ["History & News", "group",
  ["Gameworld News","/cg/news.shtml"],
  ["CG History","/cg/history.shtml"],
  ["Sturia","/cg/sturia.shtml"]
 ],
 ["Groups in the World","/cg/groups.shtml"],
 ["People With Status","/cg/status.shtml"],
 ["Law and Justice","/cg/law.shtml"],
 ["Nobility","/cg/nobility.shtml"],
 ["Heraldry","/cg/heraldry/"],
 ["Common Holidays","/cg/holidays.shtml"],
 ["Milieu","/cg/milieu.shtml"]
], 

["Contact Us", "/contact", "contact",
 ["How to Reach Us", "/contact"],
 ["Org Chart", "/contact/members/orgchart.shtml"],
 ["Board of Directors", "/board"],
 ["Rules Committee", "/rc"],
 ["CG Game World Committee", "/gwc"],
 ["Props Staff", "/props"]
], 

["Forums", "/forums", "forums"], 

["Shop", "/shop", "shop"] 
);


function drawNav() {
 
 // hide the default nav
 document.getElementById("defaultNav").style.display="none";

 topNav = document.createElement('div');
 topNav.id = "topNav";
 document.getElementById("navAnchor").appendChild(topNav);
 qLogo = document.createElement('a');
 qLogo.className = "questLogo";
 qLogo.href = "/";
 topNav.appendChild(qLogo);

 topNavTabs = document.createElement('div');
 topNavTabs.id = "topNavTabs";
 topNav.appendChild(topNavTabs);

 for(i=0;i<navData.length;i++) {
  // draw each navData[i]
  thisTab = document.createElement('div');
  thisTab.className = "topNavTab";
  thisTab.id = "topNav" + navData[i][2]; 
  topNavTabs.appendChild(thisTab);

  thisTabLeft = document.createElement('div');
  thisTabLeft.className = "topNavTabLeft";
  thisTab.appendChild(thisTabLeft);
  thisTabRight = document.createElement('div');
  thisTabRight.className = "topNavTabRight";
  thisTab.appendChild(thisTabRight);
  thisA = document.createElement('a');
  thisA.href= navData[i][1];
  thisTabRight.appendChild(thisA);
  thisText = document.createTextNode(navData[i][0]);
  thisA.appendChild(thisText);
 }

}

function selectNav(tab) {

 // light top nav
 if (typeof(tab) == "string") {
  document.getElementById("topNav" + tab).className="topNavTab topNavTabLit";
  // figure out number from string
  for (z=0; z<navData.length;z++) {
   if (navData[z][2] == tab) {tab = z}
  }
 } else {
  document.getElementById("topNav" + navData[tab][2]).className="topNavTab topNavTabLit";
 }
 
 thisData = navData[tab];
 // if length is 3, this tab has no sidenav
 if (thisData.length != 3) {

  sideNav = document.createElement('div');
  sideNav.id = "sideNav";
  document.getElementById("navAnchor").appendChild(sideNav);

  sideNavTitle = document.createElement('h3');
  sideNavTitle.className = "sideNavTitle";
  sideNav.appendChild(sideNavTitle);
  sideNavTitleA = document.createElement('a');
  sideNavTitleA.href= thisData[1];
  sideNavTitle.appendChild(sideNavTitleA);
  sideNavTitleText = document.createTextNode(thisData[0]);
  sideNavTitleA.appendChild(sideNavTitleText);

  sideNavUL = document.createElement('ul');
  sideNav.appendChild(sideNavUL);

  for(i=3;i<thisData.length;i++) {
   thisLI = document.createElement('li');
   sideNavUL.appendChild(thisLI);

   if (thisData[i][1] == "group") {
    // it's a group
    thisLI.className = "sideNavGroup";
    thisText = document.createTextNode(thisData[i][0]);
    thisLI.appendChild(thisText);
    subUL = document.createElement('ul');
    thisLI.appendChild(subUL);
    for(j=2;j<thisData[i].length;j++) {  
     subLI = document.createElement('li');
     subUL.appendChild(subLI);
	 if(thisData[i][j][0] == "divider") { 
      subDivider = document.createElement('div');     
	  subDivider.className = "sideNavDivider";
	  subLI.appendChild(subDivider);
	 } else {
      subA = document.createElement('a');
      subA.href = thisData[i][j][1];
      subLI.appendChild(subA);
      subText = document.createTextNode(thisData[i][j][0]);
      subA.appendChild(subText);
     }
    }
   } else {
    // it's an orphan
    thisA = document.createElement('a');
    thisA.href = thisData[i][1];
    thisLI.appendChild(thisA);
    thisText = document.createTextNode(thisData[i][0]);
    thisA.appendChild(thisText);
   }
  }
 }

}

// deprecated; here for backwards compatibility
function lightTopNav(tab) {
 selectNav(tab);
}
function expandLeftNavGroup() {
 var expandGroup="null";
}

drawNav();

// iphone menu
$("#menuButton").click(function () {
 $("#topNavTabs").toggle();
 $("#sideNav").toggle();
 $("#menuButtonOpen").toggle();
 $("#menuButtonClosed").toggle();
});
