// FlexibleAccordion www.joomlation.com c2009 Laurent BELLOEIL GPL license

jQuery.fn.flexAccordion = function(options){
     options = jQuery.extend({
         speed: 'fast',
         activeitem: 'none',
         showheaders: true,
         headerEl: 'span',
         contentEl: 'div',
         targetdelimiter: ' '
     }, options);

     // Current hover status
     var thisSlide = jQuery(this);
     var parts = thisSlide.children('li.accPart');

     // Switch to an specific slide based on its index (from 0) and hide the others
    function activate(item){
		jQuery(parts).each( function(i){
			if( item == i )
			{
				jQuery(this).children(options.contentEl+'.accContent').slideDown( options.speed );
				jQuery(this).addClass('active');
			}else{
				jQuery(this).children(options.contentEl+'.accContent').slideUp( options.speed );
				jQuery(this).removeClass('active');
			}
		});
	}
	// hide (slideUp) all sliders
	function hidesParts(){
		jQuery(thisSlide).find(options.contentEl+'.accContent').each( function(){
			jQuery(this).hide( );
		});
		jQuery(thisSlide).children('li.accPart').each( function(){
			jQuery(this).removeClass('active');
		});
	}
	
	// main section : trigger click event if headers are shown
	jQuery(parts).each( function(i){
		var header = jQuery(this).children(options.headerEl+'.accHeader');
		if( options.showheaders )
		{
			header.click( function(){
//			header.mouseover( function(){ // lau sz : du click au survol ;)
			activate(i);
			});
		}else{
			header.hide();
		}
	});

	// trigger click event for specific buttons
        jQuery(this).find("input[title='next']").click(function(){
            var content = jQuery(this).attr('name');
				var target = content.substring( content.lastIndexOf( options.targetdelimiter, content.length )+1 );
            activate(target);
        });
	if( options.activeitem == 'none' ){
		hidesParts();
	}else{
		activate(options.activeitem);
	}
   return this;
}

