var PhotoGalleryObj = new function () {
  this.data = new Array();

  this.obj = function(param_id, div_name_photo, div_name_title, div_name_comments) {
      if (!this.data[''+param_id]) {
         this.data[''+param_id] = new PhotoGallery(param_id, div_name_photo, div_name_title, div_name_comments);
      }
      return this.data[''+param_id];
  }

  this.get_obj = function(param_id) {
      if (this.data[''+param_id]) {
        return this.data[''+param_id];
      }else{
        return false;
      }
  }
}



function PhotoGallery(param_id,div_name_photo, div_name_title, div_name_comments) {
  this.param_id = param_id;
  this.div = div_name_photo;
  this.div_title = div_name_title;
  this.div_comments = div_name_comments;
  this.current_photo = 0;
  this.full_photo='';
  this.total_photos = 0;
  sajax_do_call('initPhotoGallery',Array(this.param_id, xaction));
}

PhotoGallery.prototype.init = function(total,current) {
  this.total_photos = total;
  this.current_photo = current;
  this.preview();
}

PhotoGallery.prototype.prev = function() {
  if (this.current_photo>1) {
    this.current_photo=this.current_photo-1;
    this.preview();
  }
}

PhotoGallery.prototype.next = function() {
  if (this.total_photos==0) {
     //do nothing as gallery was not yet loaded fully
     return;
  }else{
    if (this.current_photo<this.total_photos) {
      this.current_photo=this.current_photo+1;
      this.preview();
    }
  }
}

PhotoGallery.prototype.preview = function() {
  //send ajax request to show photo
  update_div(this.div,'Loading...');

  if (this.current_photo==1) {
    showObj('gallery'+this.param_id+'p_prev','hide');      
  }else{
    showObj('gallery'+this.param_id+'p_prev','show');      
  }
  if (this.current_photo>=this.total_photos) {
    showObj('gallery'+this.param_id+'p_next','hide');      
  }else{
    showObj('gallery'+this.param_id+'p_next','show');
  }
  sajax_do_call('getPhotoGallery',Array(this.param_id, this.current_photo, xaction));
}

PhotoGallery.prototype.show_photo = function(photo,photo_full,title,comments) {
  update_div(this.div,'<img src="'+photo+'" width="366" height="266" border="0">');
  update_div(this.div_title,'<b>'+title+'</b>');
  update_div(this.div_comments,comments);
  this.full_photo=photo_full;
}

PhotoGallery.prototype.fullphoto = function() {
  loadPhoto(this.full_photo,'');
}

