cur_panel = 0;
num_panels = 7;

function showThumbnails() {
  $('#jgallery').animate({top: '-332px'});
}

function showPhoto(photo) {
  $('#jgallery #single-photo a').html('<img src="'+base_url+'img/press-and-events/grand-opening-celebration/web/'+photo+'.jpg" />');
  $('#jgallery').animate({top: '0px'});
}

function fixNav() {
  if (cur_panel == 0) {
    $('#jgallery #nav-last').animate({left: '-30px'});
    $('#jgallery #nav-next').animate({left: '800px'});
  }else if(cur_panel == 6) {
    $('#jgallery #nav-last').animate({left: '0px'});
    $('#jgallery #nav-next').animate({left: '830px'});;
  }else{
    $('#jgallery #nav-last').animate({left: '0px'});
    $('#jgallery #nav-next').animate({left: '800px'});;
  };
}

function movePanels(dir) {
  if(dir == 'next'){
    cur_panel++;
    var newpos = -831*cur_panel;
    $('#jgallery #thumbs').animate({left: newpos+'px'});
  }else{
    cur_panel--;
    var newpos = -831*cur_panel;
    $('#jgallery #thumbs').animate({left: newpos+'px'});
  }
  fixNav();
}

$(document).ready(function() {
  $('#jgallery #nav-next').click(function() {
    movePanels('next');
    return false;
  });
  $('#jgallery #nav-last').click(function() {
    movePanels('last');
    return false;
  });
  $('#jgallery a.thumb').click(function() {
    var photo_name = $(this).attr('href').replace('#','');
    showPhoto(photo_name);
    return false;
  });
  $('#jgallery a#photo-link').click(function() {
    showThumbnails();
    return false;
  });
  fixNav();
});