function clearItemOnComplete( e, minItem, maxItem, loop )
{
  if (loop)
  {
    var showNext = function(){ nextItem( e, minItem, maxItem, loop ) };
    $(e).set('tween', {duration: 'short', onComplete: function(){ $(e).display = 'none'; window['temp' + $(e).id].inject($(e).id, 'after'); $(e).destroy(); window[$(e).id] = showNext.delay(5000); }});
  }
  else
    $(e).set('tween', {duration: 'short', onComplete: function(){ $(e).display = 'none'; window['temp' + $(e).id].inject($(e).id, 'after'); $(e).destroy(); } });
}

function nextItem( e, minItem, maxItem, loop )
{
  if (loop)                                                      
    $clear(window[$(e).id]);
  currentItem = $(e).getProperty('currentItem');
  currentItem++;
  if ( currentItem > maxItem )
    currentItem = minItem;
  $(e).setProperty('currentItem', currentItem);
  dissolveItem(e, minItem, maxItem, loop);
}

function prevItem( e, minItem, maxItem, loop )
{                                                                                      
  if (loop)
    $clear(window[$(e).id]);
  currentItem = $(e).getProperty('currentItem');
  currentItem--;
  if ( currentItem < minItem )
    currentItem = maxItem;
  $(e).setProperty('currentItem', currentItem);
  dissolveItem(e, minItem, maxItem, loop);
}

function dissolveItem( e, minItem, maxItem, loop )
{
  window['temp' + $(e).id] = $(e).clone(true, true);
  $(e).set('tween', {onComplete:function(h){ clearItemOnComplete(e, minItem, maxItem, loop); currentItem = $(e).getProperty('currentItem'); window['temp' + $(e).id].innerHTML = $(e+currentItem).innerHTML; $(e).innerHTML = $(e+currentItem).innerHTML; $(e).fade('in'); }});
  
  if ($(e).getElement('div.client_question'))
  {
    $(e).getElement('div.client_question').set('tween', {duration: 'short'});
    $(e).getElement('div.case_img').set('tween', {duration: 'short'});
    $(e).getElement('div.client_question').fade('out');
    $(e).getElement('div.case_img').fade('out');
  }

  $(e).fade('out');
}
