(function() {

  var closeSlide = function (area) {
       // this method will be executed under the area's scope,
       // which means that you can store values in the scope and get it later in another execution (like this.anim)
       var s = this.slide || this.def || null;
       if (s) {
	        // if there is an animation underway, stop it.
    	    if ((this.anim) && (this.anim.isAnimated())) { this.anim.stop(); }
	        // starting a new animation to close the openned element
    		this.anim = new YAHOO.util.Anim(s, { height: { to: 0} }, 1.5, YAHOO.util.Easing.easeOutStrong);
    		this.anim.animate();
    		this.slide = null;
	   }
  };
  var openSlide = function (el, area) {
       // this method will be executed under the area's scope,
       // which means that you can store values in the scope and get it later in another execution (like this.anim)
	    var s = null;
	    // if there is an animation underway, stop it.
	    if ((this.slide) && (this.anim) && (this.anim.isAnimated())) { this.anim.stop(); }
	    // finding the selected yui-cms-item has a child with class yui-cms-slide
	    s = YAHOO.util.Dom.getElementsByClassName( 'yui-cms-slide', '*', el );
	    if ((s.length > 0) && (s = s[0])) {
	        // starting a new animation to open the element: .yui-cms-item .yui-cms-slide
    		this.anim = new YAHOO.util.Anim(s, { height: { to: s.scrollHeight } }, 1.5, YAHOO.util.Easing.easeOutStrong);
    		this.anim.animate();
    		this.slide = s;
	    }
  };

  YAHOO.util.Event.onDOMReady ( function() {
      YAHOO.util.Selector.add( 'anim-slides', {
        persistent: true, // true if you want to keep an item selected even when the mouse go out of the area
    	onReset: closeSlide,
    	onSelect: openSlide,
    	def: YAHOO.util.Dom.get('anim-slides-default')
      });
  });
}());