var selHistSlide = "1986"

$(document).ready(
function() {

  //-- check for incompatible browsers
  if (BrowserDetect.browser == 'Opera' && BrowserDetect.version < 9) {
    //alert('dont go');
    return;
  }

  /* ==================================================================== */
  /* -- Form Box show / hide function ------------------------------------ */
  /* -- show / hide - send to a friend box */
  $('.frmSendFriendArea').hide();
  $('a.bEmail').click(function() {
    //$('.frmSendFriendArea').visible = true;
    $('.frmSendFriendArea').toggle(10);

    //$(this).toggleClass("toggleFormBoxActive");

    return false;
  });
  $('a.bCloseEmailFriend').click(function() {
    //alert('ok');
    $('.frmSendFriendArea').toggle(10);
    //$('.frmSendFriendArea').visible = false;
    return false;
  });

  /* ==================================================================== */

  /* -- FAQ Box show / hide function ------------------------------------ */
  $('.faqText').hide();
  $('a.toggleBox').click(function() {
    var id = $(this).attr('id');
    $('#faqTextBox' + id).toggle(200);

    $(this).toggleClass("toggleBoxActive");

    return false;
  });
  /* ==================================================================== */

  /* -- Glossary Box show / hide function ------------------------------------ */
  $('.glosText').hide();
  $('a.toggleBox').click(function() {
    var id = $(this).attr('id');
    $('#glosTextBox' + id).toggle(200);

    $(this).toggleClass("toggleBoxActive");

    return false;
  });
  /* ==================================================================== */

  /* -- Eye Condition Box show / hide function ------------------------------------ */
  $('.eyeConText').hide();
  $('a.toggleBox').click(function() {
    var id = $(this).attr('id');
    $('#eyeConTextBox' + id).toggle(200);

    $(this).toggleClass("toggleBoxActive");

    return false;
  });
  /* ==================================================================== */

  /* -- Distributor Map Functions --------------------------------------- */
  $('.distInfo').hide();

  function resetButtons() {
    /*-- loop through all elements in map and find the selected button - change class to normal button --*/
    $(".distributorMap").children().each(function() {
      var child = $(this);
      //alert($(this).attr('class'));
      if ($(this).attr('class') == "disLocationSel") {
        $(this).removeClass("disLocationSel");
        $(this).addClass("disLocation");
      }
    });
  }

  $('a.disLocation').click(function() {
    /*
    --hide all info boxes--
    --reset all buttons --  
    */
    $('.distInfo').hide();
    resetButtons();

    var id = $(this).attr('id');
    /*-- if the info block is visible then the dot must be selected || else change to animated gif class -- */
    //alert($('#info' + id).is(":visible"));
    if ($('#info' + id).is(":visible")) {
      $(this).removeClass("disLocationSel");
      $(this).addClass("disLocation");
    } else {
      $(this).removeClass("disLocation");
      $(this).addClass("disLocationSel");
    }

    /*-- toggle visibility of info box --*/
    $('#info' + id).toggle(10);

    return false;
  });
  /*-- close button --*/
  $('a.closeBox').click(function() {
    /*-- get id of this element --*/
    var id = $(this).attr('id');
    /*-- call function to reset all buttons to original state --*/
    resetButtons();

    /*-- toggle box --*/
    $('#infoBlock' + id).toggle(10);


    return false;
  });
  
  /*-- uk location button --*/
  $('a.ukLocation').click(function() {
    /*
    --hide all info boxes--
    --reset all buttons --  
    */
    $('.distInfo').hide();
    resetButtons();
    /*-- get id of this element --*/
    var id = $(this).attr('id');

    /*-- toggle visibility of info box --*/
    $('#info' + id).toggle(10);

    return false;
  });
  
  /*-- uk close button --*/
  $('a.closeBoxUK').click(function() {
    /*-- get id of this element --*/
    var id = $(this).attr('id');
    /*-- call function to reset all buttons to original state --*/
    resetButtons();
    $('#infoBlock' + id).toggle(10);

    return false;
  });


  /* ==================================================================== */


  /* -- History Timeline functions --------------------------------------- */
  $('.hSlide').hide();
  $("'.historyDisplay .hSlide#h" + selHistSlide + "'").fadeIn("70");
  $('a#y' + selHistSlide).addClass("btnYearSel");
  $('a.btnYear').click(function() {
    var y = $(this).attr('y');

    //alert(selHistSlide + ' || ' + y);

    /*-- change slide --*/
    $("'.historyDisplay .hSlide#h" + selHistSlide + "'").fadeOut("700",
      function() { $("'.historyDisplay .hSlide#h" + y + "'").fadeIn("1000"); }
    );

    /*-- change a link selector --*/
    /* reset current selector */
    $('a#y' + selHistSlide).removeClass("btnYearSel");
    $('a#y' + selHistSlide).addClass("btnYear");
    /* set new selector */
    $('a#y' + y).removeClass("btnYear");
    $('a#y' + y).addClass("btnYearSel");

    /*-- set the selected variable to the current (selected) id --*/
    selHistSlide = y;

    return false;
  });

});

