// Setup and toggle 'more' and 'less' controls for long descriptions
function setTruncate(element, more_or_less) {
  if(!element.down('a.truncate')) {
    // init DOM elements
    var a = new Element('a', {class: 'truncate accent', href: '#'});
    element.insert(a, {position: 'bottom'});

    var fadeout = new Element('div', {class: 'fadeout'});
    element.down('.description_wrap').insert(fadeout, {position: 'bottom'});
  }

  if(more_or_less == 'more') {
    element.down('.description_wrap .fadeout').show();
    element.down('.description_wrap').removeClassName('all');
    element.down('a.truncate').update("more").writeAttribute({'onclick': 'setTruncate($(this).up(), "less"); return false;'})
  }
  else {
    element.down('.description_wrap .fadeout').hide();
    element.down('.description_wrap').addClassName('all');
    element.down('a.truncate').update("less").writeAttribute({'onclick': 'setTruncate($(this).up(), "more"); return false;'})
  }
}
  
Event.observe(window, "load", function() {
  $$('.items .attributes').each(function(e) {
    if (e.down('.description').clientHeight > e.down('.description_wrap').clientHeight) {
      setTruncate(e, 'more');
    }
  });
});
