  YUI({
	 // gallery: 'gallery-2010.10.20-19-33'
	 modules: {
		 'gallery-carousel':{requires:['widget']},
		 'gallery-carousel-anim' :{requires:['gallery-carousel','anim', 'plugin', 'pluginhost']}

	 }
  })
         .use( "gallery-carousel-anim","substitute", function(Y) {
          var carousel = new Y.Carousel({ boundingBox: "#container",
           contentBox: "#container > ol", numVisible: 1, height:'649px', hidePagination: true }
			);
          carousel.plug(Y.CarouselAnimPlugin,{animation: { speed: 1, effect: Y.Easing.easeBothStrong }});
			carousel.before('render', function(e){Y.one('#carousel_prev').setStyle('opacity', 0).setStyle('display', 'block');Y.one('#carousel_next').setStyle('display', 'block');});
          carousel.render();
		  
		  Y.on('click', function(e){
			  var opacity =  0;
			  var nodes = [];
							if (e.target.get('id') == 'carousel_prev' && this.get('selectedItem') > 0){
								this.scrollPageBackward();
								if (this.get('selectedItem') == 1){
									opacity = 0;
									nodes = [e.target];
								}
									else {
									opacity = 1;
									nodes = [Y.one('#carousel_next')];
								}
								
							}
							else if(e.target.get('id') == 'carousel_next' && this.get('selectedItem') < (this.get('numItems') -1)) {
								this.scrollPageForward();
								//alert((this.get('selectedItem'))+" == "+ (this.get('numItems') -2));
								if (this.get('selectedItem') == (this.get('numItems') -2)){
									opacity = 0;
									nodes = [e.target];
								//e.target.setStyle('display', 'none');
								}
								else {
									
									nodes = [Y.one('#carousel_next'), Y.one('#carousel_prev')]
									opacity = 1;
								}
							}							
							for(var i = 0; i < nodes.length; i++){

							var node = nodes[i];
							var anim = new Y.Anim({
									node:node,
									to: {

										opacity: opacity
									},
									duration : .3
								});
								if (opacity == 1){
									anim.on('end', function(e){this.get('node').setStyle('filter', '')});
								}
								
								anim.run();
							}
							
							




					}, ['#carousel_prev', '#carousel_next'], carousel);
			carousel.subscribe('afterScroll', function(e){alert('scroll');} );
        });
