// JQuery Code for the Events panel
// Writen by: Monte Windsor
// Written: November 28, 2009

// Updated 6/11/2010 by Monte Windsor
// Modified the timers on the Hover and Unhover events

// Updated 6/26/2010 by Monte Windsor
// Change the code so that after a hover event the next panel would be called ranther than starting over with the first panel
// Added logic to bring up a next and previous button on the hover actions.

$(document).ready(function() {
    $("#HomePageEventsPanel").oneTime("10s", "rotate", function() {
        ShowSecondEventPanel();
    });
    $("#HomePageEventsPanel").hover(
              function() {
                  //$("#MainMenuHome").replaceWith('<a id="MainMenuHome" class="selected" href="index.htm">Hover</a>')
                  $("#HomePageEventsPanel").stopTime("rotate");
                  $("#EventPanelPrevious").show();
                  $("#EventPanelNext").show();
              },
              function() {
                  //$("#MainMenuHome").replaceWith('<a id="MainMenuHome" class="selected" href="index.htm">Unhover</a>')
                  $("#HomePageEventsPanel").stopTime("rotate");
                  $("#EventPanelPrevious").hide();
                  $("#EventPanelNext").hide();
                  if ($("#FirstEventPanel").is(':visible')) {
                      $("#HomePageEventsPanel").oneTime("2s", "rotate", function() {
                          ShowSecondEventPanel();
                      });
                  }
                  else if ($("#SecondEventPanel").is(':visible')) {
                      $("#HomePageEventsPanel").oneTime("2s", "rotate", function() {
                          ShowThirdEventPanel();
                      });
                  }
                  else if ($("#ThirdEventPanel").is(':visible')) {
                      $("#HomePageEventsPanel").oneTime("2s", "rotate", function() {
                          ShowFourthEventPanel();
                      });
                  }
                  else if ($("#FourthEventPanel").is(':visible')) {
                      $("#HomePageEventsPanel").oneTime("2s", "rotate", function() {
                          ShowFirstEventPanel();
                      });
                  };


              });
    $("#EventPanelNext").click(
        function() {
            if ($("#FirstEventPanel").is(':visible'))
            { ShowSecondEventPanel() }
            else if ($("#SecondEventPanel").is(':visible'))
            { ShowThirdEventPanel() }
            else if ($("#ThirdEventPanel").is(':visible'))
            { ShowFourthEventPanel() }
            else if ($("#FourthEventPanel").is(':visible'))
            { ShowFirstEventPanel() };
            $("#HomePageEventsPanel").stopTime("rotate");
        });
    $("#EventPanelPrevious").click(
        function() {
            if ($("#FirstEventPanel").is(':visible'))
            { ShowFourthEventPanel() }
            else if ($("#SecondEventPanel").is(':visible'))
            { ShowFirstEventPanel() }
            else if ($("#ThirdEventPanel").is(':visible'))
            { ShowSecondEventPanel() }
            else if ($("#FourthEventPanel").is(':visible'))
            { ShowThirdEventPanel() };
            $("#HomePageEventsPanel").stopTime("rotate");
        });
});

function ShowFirstEventPanel() {
    $("#FirstEventPanel").fadeIn("slow");
    $("#SecondEventPanel").fadeOut("slow");
    $("#ThirdEventPanel").fadeOut("slow");
    $("#FourthEventPanel").fadeOut("slow");
    $("#HomePageEventsPanel").stopTime("rotate");
    $("#HomePageEventsPanel").oneTime("10s", "rotate", function() {
        ShowSecondEventPanel();
    });
}
function ShowSecondEventPanel() {
    $("#FirstEventPanel").fadeOut("slow");
    $("#SecondEventPanel").fadeIn("slow");
    $("#ThirdEventPanel").fadeOut("slow");
    $("#FourthEventPanel").fadeOut("slow");
    $("#HomePageEventsPanel").stopTime("rotate");
    $("#HomePageEventsPanel").oneTime("10s", "rotate", function() {
        ShowThirdEventPanel();
    });
}
function ShowThirdEventPanel() {
    $("#FirstEventPanel").fadeOut("slow");
    $("#SecondEventPanel").fadeOut("slow");
    $("#ThirdEventPanel").fadeIn("slow");
    $("#FourthEventPanel").fadeOut("slow");
    $("#HomePageEventsPanel").stopTime("rotate");
    $("#HomePageEventsPanel").oneTime("10s", "rotate", function() {
        ShowFourthEventPanel();
    });
}
function ShowFourthEventPanel() {
    $("#FirstEventPanel").fadeOut("slow");
    $("#SecondEventPanel").fadeOut("slow");
    $("#ThirdEventPanel").fadeOut("slow");
    $("#FourthEventPanel").fadeIn("slow");
    $("#HomePageEventsPanel").stopTime("rotate");
    $("#HomePageEventsPanel").oneTime("10s", "rotate", function() {
        ShowFirstEventPanel();
    });
}
