
$(document).ready(function()
{

  $(".headerflashdata").find(".close").click(function()
  {
    //$(".headerflashdata").html("");
    $(".headerflashdata").remove();
  });
  window.setTimeout(function(){ $(".headerflashdata").remove(); }, 10000);

  /* homepage scroller */
  //do we have a scroller on this page?
  var numLinks = $(".bodytopleftimage").find("a").length;
  if(numLinks > 0)
  {
    //if we do, set up an array of jq objects that are the things to show and hide
    //saves time selecting them later
    var linkArray = new Array();
    var thumbArray = new Array();
    for(var i=0;i<numLinks;i++)
    {
      linkArray[i] = $(".bodytopleftimage").find("a:eq("+i+")");
      thumbArray[i] = $(".mainscroller").find("img:eq("+i+")");
    }

    //for each button, give it an attribute of which pane it'll show
    $(".mainscroller").find("a").each(function(i)
    {
      $(this).attr("page", i);
    });

    var currentPage = 0;
    //set up function to change to the next page, run it every ten seconds
    function changePage()
    {
      linkArray[currentPage%numLinks].hide();
      //thumbArray[currentPage%numLinks].attr("src",BASE_URL+"images/thumbframe.png");
      currentPage++;
      linkArray[currentPage%numLinks].show();
      //thumbArray[currentPage%numLinks].attr("src",BASE_URL+"images/thumbframe-selected.png");
    }
    var pageInterval = window.setInterval(changePage, 10000);

    //if the buttons are clicked
    $(".mainscroller").find("a").click(function(event)
    {
      //stop the default action for the anchor
      event.preventDefault();
      //get rid of the rubberband around the button
      $(this).blur();
      //hide current page, reset page, show new page
      linkArray[currentPage%numLinks].hide();
      //thumbArray[currentPage%numLinks].attr("src",BASE_URL+"images/thumbframe.png");
      currentPage = $(this).attr("page");
      linkArray[currentPage%numLinks].show();
      //thumbArray[currentPage%numLinks].attr("src",BASE_URL+"images/thumbframe-selected.png");
      //clear and restart timer for page change
      window.clearInterval(pageInterval);
      pageInterval = window.setInterval(changePage, 10000);
      return false;
    });
  }

});

