model = {
 reload: function(){
  $('#photoList').hide();
  albumId=$('#modelAlbumId').val();
  $.getJSON(
   '/ajax/modelPhotoListLoader',
   { albumId: albumId },
   function(g){
    $('#photoList').html(g.content);
    $('#photoList').show();
   }
  );
 }
}

fancyboxSettings =
{
	'hideOnContentClick': true,
	'overlayShow': true,
	'itemArray': photoList,
	'callbackOnStart': function(){keysEnabled = false},
	'callbackOnStop': function(){keysEnabled = true}
}

gallery = {
 step: 4,
 albumId: 0,
 from: 0,
 total: 0,
 init: function(){
  $('a.photoStart').fancybox(fancyboxSettings);
  $("#container-main a.photo").fancybox(fancyboxSettings);
  gallery.reloadLinks();
  $('#gallery-l').click(function(){
   gallery.showPrevious();
   return false;
  });
  $('#gallery-r').click(function(){
   gallery.showNext();
   return false;
  });
  $("#gallery a.photo").fancybox(fancyboxSettings);
 },
 reloadLinks: function(){
  $('#gallery-l').removeClass();
  if(this.from>0){
   $('#gallery-l').addClass('enabled');
  }
  $('#gallery-r').removeClass();
  if(this.from<(this.total-this.step)){
   $('#gallery-r').addClass('enabled');
  }
 },
 showPrevious: function(){
  if(this.from>0){
   this.loadGallery(-this.step);
  }
 },
 showNext: function(){
  if(this.from<(this.total-this.step)){
   this.loadGallery(this.step);
  }
 },
 loadGallery: function(step){
  $.getJSON(
   '/ajax/galleryLoader',
   { albumId: this.albumId, f: (this.from+step) },
   function(g){
	gallery.from=parseInt(g.from);
	$('#photos-list-mini').fadeOut('fast',function(){
     $('#photos-list-mini').html(g.content);
	 $('#photos-list-mini').fadeIn('slow');
     $("#photos-list-mini a").fancybox(fancyboxSettings);
	});
    gallery.reloadLinks();
   }
  );
 }
}

$(document).ready(gallery.init);
