$(function() {
  $('.exhb_img1').cycle({
    fx: 'fade',
    timeout: 0,
    pager: '#exhb_thumbs',
    pagerAnchorBuilder: function(idx, slide) {
      return '<a href="#" class="exhb_thubms">' + $(slide).find('.square').html() + '</a>';
    },
    after: function() {
      $('.phot_info_1').html($(this).find("img").attr("title"));
      $('.phot_info_2').html($(this).find(".xlarge").html());
      $('a.thickbox').each(function(i) {
        $(this).unbind('click');
      });
      tb_init('a.thickbox');
    }
  });
  $('.phot_info_1').html($(".exhb_img1 .entry img").attr("title"));
  $('.phot_info_2').html($(".exhb_img1 .entry .xlarge").html());
  $('.go_top').css('visibility','hidden').data('hidden','hidden');
  var mytop = 1;
  if ($('.exhb_img1 .entry').length <= 5) $('.go_bottom').css('visibility','hidden').data('hidden','hidden');
  $('.go_top').click(function(event) {
    mytop -= 1;
    $('.go_bottom').css('visibility','visible').data('hidden','visible');
    if (mytop == 1) $('.go_top').css('visibility','hidden').data('hidden','hidden');
    event.preventDefault();
  });
  $('.go_bottom').click(function(event) {
    mytop += 1;
    $('.go_top').css('visibility','visible').data('hidden','visible');
    if (($('.exhb_img1 .entry').length - 4) <= mytop) $('.go_bottom').css('visibility','hidden').data('hidden','hidden');
    event.preventDefault();
  });
  $('.go_top, .go_bottom').click(function(event) {
    $('#exhb_thumbs').animate({'marginTop': ((mytop-1)*-85)+'px'});
  });
  $('.exhb_thubms').click(function() {
    a = (mytop - $(this).prevAll('a').length);
    if (a < -1) {
      if ($('.go_bottom').data('hidden') != "hidden") $('.go_bottom').trigger('click');
    } else if (a > -1) {
      if ($('.go_top').data('hidden') != "hidden") $('.go_top').trigger('click');
    }
  });
  tb_init('a.thickbox');
});