var str_names = ["League President", "League Vice President", "League Secretary"];
var str_emails = ["president@cwlittlescouts.com", "vice_president@cwlittlescouts.com", 
"secretary@cwlittlescouts.com"];
var current_xml_item = new Number(0); // current item we are viewing
var xml_document = new String(""); // xml-document with fun-facts
var xml_elements = null; // get xml-elements from the document

$(document).ready(function() {
 
 if($.browser.msie && $.browser.version <= 6) {
  // check for microsoft internet explorer; if the version is less or 
  // equal to 6.0; then make sure to tell them that their browser is not
  // supported by the website.
  window.location.href = rel + "support/index.php";
 };
 
 var emails = ($(".mail")); // get all the email names
 for(var i = 0; i < emails.length; i++) {
  emails[i].cw_name = str_names[i];
  emails[i].cw_email = str_emails[i];
  $(emails[i]).hover(emailOver, emailOut);
 }; // end of for-loop
 
 $.ajax({type: "GET", url: rel + "lib/xml/facts.xml", dataType: "xml", 
  success: function(xml) {
   
   xml_document = xml; // load the xml-document into our variable
   xml_elements = (xml_document.getElementsByTagName("fact"));
   change_element_data( 0 ); // update the current fun-fact
   
 } });
 
 $("#btnBackward").click(factsClick);
 $("#btnForward").click(factsClick);
 
}); // end of readys-state

function factsClick(event) {
 switch(event.target.id) {
  case "btnBackward": change_element_data( -1 ); break;
  case "btnForward": change_element_data( 1 ); break;
 }; // end of switch-statement
}; // end of factsClick();

function emailOver(event) {
 event.target.innerHTML = event.target.cw_email;
}; // end of emailOver();

function emailOut(event) {
 event.target.innerHTML = event.target.cw_name;
}; // end of emailOut();

function change_element_data(do_change) {
 
 if(do_change != 0) { 
  // if do_change is equivalent to 0 then we aren't actually going to
  // change anything, but if it equals something else; we will update
  current_xml_item += do_change;
 }; 
 
 if(current_xml_item > (xml_elements.length - 1)) current_xml_item = 0;
 if(current_xml_item < 0) current_xml_item = (xml_elements.length - 1);
 // retrieve the value from the current xml-document-item, then update
 var value = (xml_elements[current_xml_item].childNodes[0].nodeValue);
 $("#fact")[0].innerHTML = value; // update the current fun-fact.
 
}; // end of change_element_data();
