/* Cpage page produits */
jQuery.fn.exists = function(){return jQuery(this).length>0;}

function produits_open_item(o) {

	if(o.exists()){
		if(o.parent().hasClass('active')){
			o.parent().removeClass('active');
			o.parent().find('div.produits_item_content').hide('blind');
		}
		else {
			/*
			$jQuery('li.produits_item.active div.produits_item_content').each(function(index){
				$jQuery(this).hide();
				$jQuery(this).parent().removeClass('active');
			});
			*/
			o.parent().addClass('active');
			o.parent().find('div.produits_item_content').show('blind');
		}
	}

}

function produits_set_open_btn() {

	$jQuery('.btn_all_open a').click(function(){
		$jQuery('a.produits_item_header').each(function(index){
			jQuery(this).parent().find('div.produits_item_content').show('blind');
			$jQuery(this).parent().addClass('active');
		});
		$jQuery('.btn_all_open').html('<a href="#">Tout fermer</a>&nbsp; <a href="#"><img style="vertical-align:middle;" src="http://cpagedev.tevolys.com/assets/templates/cpage/images/fond_btn_moins_vert.png" alt="" /></a>');
		produits_set_close_btn();
		
		return false;
	});

}

function produits_set_close_btn() {

	$jQuery('.btn_all_open a').click(function(){
		$jQuery('a.produits_item_header').each(function(index){
			jQuery(this).parent().find('div.produits_item_content').hide('blind');
			$jQuery(this).parent().removeClass('active');
		});
		$jQuery('.btn_all_open').html('<a href="#">Tout ouvrir</a>&nbsp; <a href="#"><img style="vertical-align:middle;" src="http://cpagedev.tevolys.com/assets/templates/cpage/images/fond_btn_plus_vert.png" alt="" /></a>');
		produits_set_open_btn();
		
		return false;
	});

}

$jQuery(document).ready(function($){ 

	$jQuery('a.produits_item_header').each(function(index){
		$jQuery(this).click(function(){
		    produits_open_item($jQuery(this));
			return false;
		});
	});
	
	produits_set_open_btn();

});
