/******************************************************************************
* hadcmpCarousel.js
*******************************************************************************

*******************************************************************************
*                                                                             *
* Copyright 2006									                          *
*                                                                             *
******************************************************************************/


var aListeGid = new Array();

var aCarouselNavBtn = new Array();

function highlightBtn(myCarousel, currentPage){	
		var current_index = currentPage;		
		var yui_current_item = myCarousel.getItem(current_index);		
		var current_html_el = YAHOO.util.Dom.getFirstChild(YAHOO.util.Dom.getFirstChild(YAHOO.util.Dom.get(yui_current_item.id)));
		var current_clean_id = current_html_el.id.substring(4, current_html_el.id.length);
		
		var nav_button_on = YAHOO.util.Dom.get("btn_"+current_clean_id);
		
		//alert("nav_button_on : " + nav_button_on.id);
		
		YAHOO.util.Dom.removeClass(aCarouselNavBtn, "on");	
		YAHOO.util.Dom.addClass(nav_button_on, "on");
	}
	
isoYUILoader.onReady( function() {
	
	YAHOO.namespace("HELIOS");
	
	

	YAHOO.HELIOS.listeCarousels = {
		aGid: {},  
		aCarousels: {},
		addCarousel: function(unGid)
		{
			var myCarousel = new YAHOO.widget.Carousel("carouselContainer_"+unGid, 
			{ 
				autoPlayInterval: 5000, 
				isCircular: true, 
				animation: {
					speed: 0.5
				}, 
				numVisible: 1,
				carouselItemEl: 'DIV',
				carouselEl: 'OL'
			}); 
			
			this.aCarousels[unGid] = myCarousel;
			
			var old_selectedId = "";

			myCarousel.on("pageChange", function(currentPage){
				highlightBtn(myCarousel, currentPage);
			});
			
			
			highlightBtn(myCarousel, 0);
			
			YAHOO.util.Event.onDOMReady(function(){
				myCarousel.render();
				myCarousel.show();
				myCarousel.startAutoPlay();
			});
		},
		
		init: function(){
			aCarouselNavBtn = YAHOO.util.Dom.getElementsByClassName("carousel_nav_btn ","li");
			for(var i=0;i<this.aGid.length;i++){
				this.addCarousel(this.aGid[i]);
			}
		},
		
		launch: function(){
			//alert("launch in");
			this.init();
			/*for(var i=0;i<this.aCarousels.length;i++){
				//this.aCarousels[i].carousel.render();
				//this.aCarousels[i].carousel.show();
				//this.aCarousels[i].carousel.startAutoPlay();
			}*/
			//alert("launch out");
		}
	};	

	YAHOO.util.Event.onDOMReady(
		function (ev) {
			YAHOO.HELIOS.listeCarousels.aGid = aListeGid;
			YAHOO.HELIOS.listeCarousels.launch();
		}
	);
});

function clickNavBar(gid, i, idLi){
	isoYUILoader.onReady( function() {
		YAHOO.HELIOS.listeCarousels.aCarousels[gid].scrollTo(i);
		/*
		YAHOO.util.Dom.removeClass(aCarouselNavBtn, "on");	
		YAHOO.util.Dom.addClass(idLi, "on");
		*/
	});
}
