   function gallery_active_index() {
      this.value = 0;
   }

   function gallery_image_substitute(gallery_id, gidxobject, new_gidx, num_images, image_array) {
      var href = image_array[0];
      var js_href = image_array[1];
      var src = image_array[2];
      var title = image_array[3];
      var width = image_array[4];
      var height = image_array[5];
      
      var link_id = gallery_id+'-image-a';
      var cont_id = gallery_id+'-image';
      
      var imgcontainer_id = href.length > 0 ? link_id : cont_id;

      var img_id = gallery_id+'-image-img';
      var prevlink_id = gallery_id+'-prevlink';
      var nextlink_id = gallery_id+'-nextlink';

      if (new_gidx > 0) {
    	  $('#' + prevlink_id).show();
      } else {
    	  $('#' + prevlink_id).hide();    	  
      }
      
      if (new_gidx < num_images - 1) {
    	  $('#' + nextlink_id).show();    	  
      } else {
    	  $('#' + nextlink_id).hide();
      }
      
      gidxobject.value = new_gidx;
      
      if (href.length > 0) {
    	  $('#' + link_id).each( function() {
     	     $(this).attr('href', href);
    	     $(this).attr('onclick', js_href);
    	  });
      }
      
      var img = document.createElement('img');
      $(img).attr({
    	 id: img_id,
         alt: title,
         title: title,
         width: width,
         height: height,
         src: src
      });
      
      $('#' + imgcontainer_id + ' #' + img_id).replaceWith(img);
      $('#' + gallery_id + ' .activeimg').html(new_gidx + 1);
      
   }
   