$(document).ready(function() {

$.nybep = {};

// Preload rollover images
$.preLoadImages(
"pic/button-connect-glow.png",
"pic/left-glow.png",
"pic/right-glow.png",
"pic/further_info_menu.jpg",
"pic/further_info_open.jpg",
"pic/i_menu.jpg",
"pic/i_open.jpg"
);

//
// Slideshow
//

$.nybep.slide = 1;  // Start on slide 1
$.nybep.max_slide = 6; // Total number of slides
$.nybep.slide_speed = 15000; // Time each slide is shown, 1000 = 1 second
$.nybep.transition_speed = 500 // Time to change a slide, 1000 = 1 second

$.nybep.timer = setInterval('change_slide("next")',$.nybep.slide_speed); // Starts slideshow

$("div#left_arrow").hover (
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);
$("div#left_arrow").click(function() {
  clearInterval($.nybep.timer);  // Stop slideshow
  change_slide("prev"); // Go to prev slide
  $.nybep.timer = setInterval('change_slide("next")',$.nybep.slide_speed); // Resume slideshow
});

$("div#right_arrow").hover (
  function () {
    $(this).addClass("hover");
  },
  function () {
    $(this).removeClass("hover");
  }
);
$("div#right_arrow").click(function() {
  clearInterval($.nybep.timer);  // Stop slideshow
  change_slide("next"); // Go to next slide
  $.nybep.timer = setInterval('change_slide("next")',$.nybep.slide_speed); // Resume slideshow
});


//
// Menus
//

// Open menus on page load if previously open.
if ($.cookie('menu_further_info') > '0') {
  $('img#further_info').attr("src", "pic/further_info_open.jpg");
  $("div#further_info_menu").css('marginLeft',0);
  }
if ($.cookie('menu_staff_info') > '0') {
  $('img#staff_info').attr("src", "pic/i_open.jpg");
  $("div#staff_info_menu").css('marginLeft',0);
  }


$('img#further_info').click(function() {
    var $marginLefty = $("div#further_info_menu");
    var $ml_value = parseInt($marginLefty.css('marginLeft'),10)
    $.cookie('menu_further_info', $ml_value);
    if ($ml_value != 0) {
      $('img#further_info').attr("src", "pic/further_info_open.jpg");
      }
    $marginLefty.animate(
      {marginLeft: $ml_value == 0 ? 103 : 0},
      "",
      "",
      function(){$('img#further_info').attr("src", $ml_value == 0 ? "pic/further_info_closed.jpg" : "pic/further_info_open.jpg");}
      );
  });

$('img#staff_info').click(function() {
    var $marginLefty = $("div#staff_info_menu");
    var $ml_value = parseInt($marginLefty.css('marginLeft'),10)
    $.cookie('menu_staff_info', $ml_value);
    if ($ml_value != 0) {
      $('img#staff_info').attr("src", "pic/i_open.jpg");
      }
    $marginLefty.animate(
      {marginLeft: $ml_value == 0 ? 103 : 0},
      "",
      "",
      function(){$('img#staff_info').attr("src", $ml_value == 0 ? "pic/i_closed.jpg" : "pic/i_open.jpg");}
      );
  });

});



//
// Supporting functions
//

function change_slide(direction) {
  $.nybep.old_slide = $.nybep.slide;
  
  if (direction == "prev") {
    $.nybep.slide = $.nybep.slide - 1;
    if ($.nybep.slide < 1) {
      $.nybep.slide = $.nybep.max_slide;
      }
    }
  else {
    $.nybep.slide = $.nybep.slide + 1;
    if ($.nybep.slide > $.nybep.max_slide) {
      $.nybep.slide = 1;
      }
    }
  
  $(".textbox#textbox" + $.nybep.old_slide).fadeOut($.nybep.transition_speed);
  $(".textbox#textbox" + $.nybep.slide).fadeIn($.nybep.transition_speed);

  $(".slide#slide" + $.nybep.old_slide).fadeOut($.nybep.transition_speed);
  $(".slide#slide" + $.nybep.slide).fadeIn($.nybep.transition_speed);
}