(function() {
  var $L = YAHOO.lang,
      $D = YAHOO.util.Dom;
  YAHOO.CMS.Bubble.addDefaultAction('actionAccordion', function (layer, args) {
    var closing = [],
        opening = null;
    if (!args[1].decrepitate) {
        // searching the slide element
        opening = $D.getElementsByClassName('yui-cms-slide','div',$D.getAncestorByClassName (args[1].target, 'yui-cms-item'))[0];
        // searching the opened elements (can be more that one element)
        $D.batch ($D.getElementsByClassName('yui-cms-slide','div',$D.getAncestorByClassName (args[1].target, 'accordion-slides')), function(el){
          var h = parseInt($D.getStyle(el, 'height'), 10);
          // if the element is not the active and is opened
          if ((el !== opening) && (!$L.isNumber(h) || (h > 0))) {
            if (!$L.isNumber(h)) {
                // forcing to number... to avoid misbehavior on "auto" height...
                $D.setStyle(el, 'height', el.scrollHeight+'px');
            }
            closing.push(el);
          }
        });
        // starting a new animation to open the element: .yui-cms-item .yui-cms-slide
        if ($L.isObject(opening)) {
		  var anim1 = new YAHOO.util.Anim(opening, { height: { to: opening.scrollHeight } }, 0.3, YAHOO.util.Easing.easeInStrong);
		  anim1.animate();
	    }
		if (closing.length > 0) {
		  var anim2 = new YAHOO.util.Anim(closing, { height: { to: 0 } }, 0.3, YAHOO.util.Easing.easeInStrong);
		  anim2.animate();
		}
        // reclaiming the behavior
        return true;
    }
  });
}());