// generic image/text-swapping code.
// example:  <script>stack_init("#collectionthumbs img", "mouseover", "data-txt-ix", "collectiondescs");</script>
// note: beware of empty text nodes in the stack

function stack_init(jqSelector, jqEventName, ixAttribute, stackId, callback) {
  if(!callback) callback = null;
  $(document).ready(function() {
    var stack = document.getElementById(stackId);
    stack._currentStackIx = 0;
    $(jqSelector)[jqEventName](function() {
      stack_swap_content(stack, this.getAttribute(ixAttribute), callback);
    });
  });
}

function stack_swap_content(stackNode, ix, callback) {
  if(!stackNode || ix == stackNode._currentStackIx) return;
  stackNode.childNodes[ix].style.display = "block";
  stackNode.childNodes[stackNode._currentStackIx].style.display = "none";
  stackNode._currentStackIx = ix;
  if(callback) callback(stackNode.childNodes[ix]);
}
