var pendingSelection = null;
var visible = null;

function setSelectedCollection(id) {
  pendingSelection = id;
  new Ajax.Request("/gallery/getCollectionInfo?cid=" + id);
  new Ajax.Request("/gallery/getCollectionPreview?cid=" + id);
}

function setCollectionInfo(cid, owner_name, owner_id, title, views) {
  if (pendingSelection != cid) {
    return;
  }
  var html = '<a class="GalleryUsername" target="_parent" href="/user/viewProfile?uid=' + owner_id + '">' + owner_name + '</a>&nbsp;|&nbsp;'
  html = html + '<a class="GalleryCollection" target="_parent" href="/collection/viewCollection?cid=' + cid + '">' + title + '</a>&nbsp;|&nbsp;'
  html = html + '<span> Views: ' + views + '</span>'
  $('CollectionInfo').innerHTML = html;  
}

function setCollectionPreview(cid, html) {
  if (pendingSelection != cid) {
    return;
  }
  if (visible == null) {
    visible = 'CollectionPreview1';
    $(visible).innerHTML = html;
    $('EntireCollectionLink').href = '/collection/viewCollection?cid=' + cid
    $('EntireCollectionLink').innerHTML = '&lt;&lt;&nbsp;View Entire Collection&nbsp;&gt;&gt;'
    $('EntireCollectionLink').style.display = 'block';
  }
  else {
    var fadeIn = null;
    if (visible == 'CollectionPreview1') {
      fadeIn = 'CollectionPreview2';
    }
    else {
      fadeIn = 'CollectionPreview1';
    }
    $(fadeIn).innerHTML = html;
    Effect.Appear(fadeIn, { duration: 1.0 });
    Effect.Fade(visible, { duration: 1.0 });
    visible = fadeIn;
    $('EntireCollectionLink').href = '/collection/viewCollection?cid=' + cid
  }
}
