var $j = jQuery.noConflict();
$j(function() {
  // variables
  i = 0;
  y = 0;
  total = $j("#content_top_right div").length;
  // check if there is more than one page
  if(total > 1) {
    for(i = 2; i <= total; i++) {
      $j("#gallery_" + i).hide(); // hide next pages of gallery
    }
  }
  else {
    $j("#gallery_previous").hide();
    $j("#gallery_next").hide(); // hide both buttons
  }
  y = 1; // actual page
  // what to do after clicking on button in the gallery
  $j(".gallery_button").click(function() {
    button_id = $j(this).attr("id"); // get id
    if(button_id == "gallery_next") {
      $j("#gallery_" + y).hide();
      y++; // increment number of page
      $j("#gallery_previous").show(); // show previous button
      if(y == total) {
        $j("#gallery_next").hide(); // hide next button on the last page
      }
      $j("#gallery_" + y).show();
    }
    else if(button_id == "gallery_previous") {
      $j("#gallery_" + y).hide();
      y--; // decrement number of page
      $j("#gallery_next").show(); // show next button
      if(y == 1) {
        $j("#gallery_previous").hide(); // hide previous button on the first page
      }
      $j("#gallery_" + y).show();
    }
  return false;  
  });
});