function diAlbum()
{
  this.e = {
    e: _ge('album-container'),
    toptitle: _ge('album-container-top-title'),
    title:  _ge('album-container-title'),
    pic:  _ge('album-container-pic'),
    pictd: _ge('album-container-pic-td'),
    pics:  _ge('album-container-pics')
  }

  this.preview_width = 0;

  this.set_indicators_height = function()
  {
    var pic = incut_albums_ar[incut_album_id]['p'+incut_photo_id];
    if (!pic) return false;

    var h = pic.h + 40;

    var e1 = _ge('left-span');
    var e2 = _ge('right-span');

    e1.style.height = h+'px';
    e2.style.height = h+'px';
  }

  this.incut_album_show = function(a_id, p_id)
  {
    incut_album_id = a_id;

    if (this.e.e)
    {
      this.e.title.innerHTML = incut_album_titles_ar[a_id];
      if (this.e.toptitle) this.e.toptitle.innerHTML = incut_album_titles_ar[a_id];

      // pics
      this.e.pics.innerHTML = '';
      this.preview_width = 0;

      for (var j in incut_albums_ar[a_id])
      {
        var pic = incut_albums_ar[a_id][j];
        var i = j.substr(1);

        this.e.pics.innerHTML += '<a href="/photos/'+a_id+'/'+i+'/" onclick="return alb.set_incut_photo('+a_id+','+i+');"><img src="/UserFiles/photos/preview/'+pic.pic+'" width='+pic.tn_w+' height='+pic.tn_h+' style="margin-right: 3px;"></a>';
        this.preview_width += pic.tn_w + 3;
      }

      this.e.pics.style.width = this.preview_width+'px';
      //

      s62 = new diScroller('s62', 'album-container-pics', 656, this.preview_width, 0);

      this.e.e.style.display = 'block';

      this.try_to_scroll_incut_previews(a_id, p_id, 1, 1);
      this.set_incut_photo(a_id, p_id);

      gray_bg_show();
    }

    return false;
  }

  this.get_x_position_of_incut_preview = function(a_id, p_id)
  {
    var x = 0;

    for (var j in incut_albums_ar[a_id])
    {
      var pic = incut_albums_ar[a_id][j];
      var i = j.substr(1);

      if (p_id*1 == i*1)
        break;

      x += pic.tn_w + 1;
    }

    return x;
  }

  this.get_incut_previews_container_width = function()
  {
    var cont_w = this.e.pics.parentNode.offsetWidth;
    if (!cont_w)
      cont_w = 656;

    return cont_w;
  }

  this.is_incut_preview_visible = function(a_id, p_id)
  {
    var x1 = parseInt(this.e.pics.style.marginLeft);
    if (!x1 || isNaN(x1))
      x1 = 0;

    var x2 = this.get_x_position_of_incut_preview(a_id, p_id);
    var cont_w = this.get_incut_previews_container_width();
    var w = incut_albums_ar[a_id]['p'+p_id].tn_w;

    return Math.abs(x1) <= Math.abs(x2) &&
           (Math.abs(x1) + cont_w) >= (Math.abs(x2) + w);
  }

  this.try_to_scroll_incut_previews = function(a_id, p_id, dir, noscroll)
  {
    if (typeof dir == 'undefined')
      var dir = 1;

    if (typeof noscroll == 'undefined')
      var noscroll = 0;

    dir = dir > 0 ? 1 : -1;

    if (!this.is_incut_preview_visible(a_id, p_id))
    {
      var x2 = this.get_x_position_of_incut_preview(a_id, p_id);
      var w = incut_albums_ar[a_id]['p'+p_id].tn_w;
      var cont_w = this.get_incut_previews_container_width();

      var x = dir == 1 ? -x2 + cont_w - (w + 1) : -x2;

      this.set_incut_previews_position(x, noscroll);
    }
  }

  this.set_incut_previews_position = function(x, noscroll)
  {
    if (typeof noscroll == 'undefined')
      var noscroll = 0;

    var cont_w = this.get_incut_previews_container_width();

    if (x > 0) x = 0;
    else if (x - cont_w < this.preview_width * -1) x = -this.preview_width + cont_w;
                          //this.e.pics.offsetWidth

    s62.left_bound = cont_w - this.preview_width;

    if (typeof this.e.pics.style.marginLeft == 'undefined' || !this.e.pics.style.marginLeft)
    {
      this.e.pics.style.marginLeft = '0px';
    }

    var l = parseInt(this.e.pics.style.marginLeft);

    var d = Math.abs(l - x);

    if (x == l)
      return false;

    if (noscroll)
    {
      this.e.pics.style.marginLeft = x+'px';
    }
    else
    {
      if (x > l)
        s62.move_left(d);
      else
        s62.move_right(d);
    }
  }

  this.set_incut_photo = function(a_id, p_id, dir)
  {
    if (typeof dir == 'undefined')
      var dir = 1;

    dir = dir > 0 ? 1 : -1;

    var pic = incut_albums_ar[a_id]['p'+p_id];

    this.e.pic.style.background = 'url(/UserFiles/photos/'+pic.pic+') center center no-repeat';
    this.e.pic.style.width = pic.w+'px';
    this.e.pic.style.height = pic.h+'px';

    this.e.title.innerHTML = pic.title;

    incut_photo_id = p_id;

    this.set_indicators_height();

    this.try_to_scroll_incut_previews(a_id, p_id, dir);
    gray_bg_show();

    return false;
  }

  this.incut_prev_next = function(dir)
  {
    var ar = [];

    for (var i in incut_albums_ar[incut_album_id])
    {
      ar.push(i.substr(1)*1);
    }

    var x = ar_indexOf(incut_photo_id, ar);

    if (x != -1)
    {
      x = x*1 + dir*1;

      if (typeof ar[x] == 'undefined')
        x = dir > 0 ? 0 : ar.length - 1;
    }

    this.set_incut_photo(incut_album_id, ar[x], dir);

    return false;
  }

  this.incut_left_right = function(dir)
  {
    dir = dir > 0 ? -1 : 1;

    var step = 600;

    if (step > this.e.pics.offsetWidth)
      return false;

    var x = parseInt(this.e.pics.style.marginLeft);
    if (isNaN(x)) x = 0;

    x += step*dir;

    this.set_incut_previews_position(x);

    return false;
  }

  this.incut_album_hide = function()
  {
    var bg_e = _ge('gray-bg');

    if (this.e.e && bg_e)
    {
      this.e.e.style.display = 'none';
      bg_e.style.display = 'none';
    }

    /*
    for (var i = 0; i < dicalendar_instances_ar.length; i++)
    {
      eval(dicalendar_instances_ar[i]+'.hide();');
    }
    */

    return false;
  }
}

var incut_albums_ar = [];
var incut_album_titles_ar = [];
var incut_album_id = 0;
var incut_photo_id = 0;
var s62;

