
function addLoadEvent (func) {
  var oldonload = window.onload;

  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

var currentNavId;

function navOn() {
  if (document.getElementById) {
    $('#' + currentNavId + ' a').css('color', 'white');
    $('#' + currentNavId + ' img').width($('#' + currentNavId).width());
  }
}

var orginalImageInfo = new Array();
var imagePointers = new Array();

for (g=1;g<=10;g++) {
  imagePointers[g] = 3;
}

jQuery(document).ready(
  function() {
    if (jQuery('ul.jcarousel-skin-ddb').length > 1) {
      // replace hidden images with nothing
      for (g=1;g<=10;g++) {
        orginalImageInfo[g] = new Array();

        $('#gallery' + g + ' img').each(
          function(index) {
            orginalImageInfo[g][index] = [$(this).attr("src"), $(this).width(), $(this).height()];

            if ((index > 2) && (index < 6)) {
              $(this).attr("src", "/images/gallery_loading.gif");
            } else if (index > 2) {
              $(this).width('40px');
              $(this).height('40px');
              $(this).removeAttr("src", "");
            }
          }
        );
      }

      jQuery('ul.jcarousel-skin-ddb').jcarousel(
        {
          initCallback: jcarousel_initCallback
        }
      );
    }
  }
);

initCallbackCount = 0;

function jcarousel_initCallback (carousel) {
  g = initCallbackCount + 1;
  $('.jcarousel-next-horizontal:eq(' + initCallbackCount + ')').addClass("g" + g + "click");

  $('.jcarousel-next-horizontal:eq(' + initCallbackCount + ')').click(
    function() {
      myClass = $(this).attr('class');

      var matches = myClass.match(/g(.*)click/g);

      g = matches[0].replace(/^g/, '');
      g = g.replace(/click$/, '');

      to = imagePointers[g] + 3;

      for (i=imagePointers[g];i<to;i++) {
        $('#gallery' + g + ' img:eq(' + i + ')').removeAttr("src", "");
        $('#gallery' + g + ' img:eq(' + i + ')').attr("src", orginalImageInfo[g][i][0]);
        $('#gallery' + g + ' img:eq(' + i + ')').width(orginalImageInfo[g][i][1] + 'px');
        $('#gallery' + g + ' img:eq(' + i + ')').height(orginalImageInfo[g][i][2] + 'px');
      }

      imagePointers[g] = to;

      to = to + 3;

      for (i=imagePointers[g];i<to;i++) {
        $('#gallery' + g + ' img:eq(' + i + ')').attr("src", "/images/gallery_loading.gif");
      }
    }
  );

  initCallbackCount++;
}

jQuery(document).ready(
  function() {
    for (g=1;g<=10;g++) {
      if (jQuery('#gallery' + g + ' a')) {
        jQuery('#gallery' + g + ' a').lightBox({fixedNavigation:true});
      }
    }
  }
);

var scrollPane;
var scrollPaneAPI;
var scrolling = 0;

function scrollY () {
  scrollPaneAPI.scrollByY(3);

  if (scrolling == 1) {
    var t = setTimeout("scrollY()", 30);
  }
}

jQuery(document).ready(
  function() {
    my_href = window.location.href;

    if ((!my_href.match(/gallery\.htm$/)) && (!my_href.match(/\/video\.htm$/)))  {
      scrollPane = $('#content')
        .bind(
          'jsp-initialised',
          function(event, isScrollable) {
            if (isScrollable) {
              $('#content_container').append('<div class="jspDown"><a href=""><img src="/images/down.png" border="0" /></a></div>');
            }
          }
        )
        .jScrollPane();

      scrollPaneAPI = scrollPane.data('jsp');

      $('.jspDown a').hover(
        function() {
          scrolling = 1;
          scrollY();
        },
        function() {
          scrolling = 0;
        }
      );
    } else {
      $('#content').css('height', 'auto');
      $('#content').css('overflow', 'visible');
    }
  }
);
