jQuery.noConflict();

var nb_promos = 0;
var current_promo_id = 0;

jQuery(document).ready(function(){
	
	nb_promos = jQuery('.encart_promo').length;	
	if (nb_promos == 0)
	{
		jQuery('#promo_defaut').show();
	}
	else if (nb_promos == 1)
		jQuery('.encart_promo').show();
	else 
	{
		if (current_promo_id == 0)
		{
			jQuery('.encart_promo:first').show();
			current_promo_id = jQuery('.encart_promo:first').attr('promo');
		}
		setTimeout("ChangePromo();", 10000);
	}
	
	// déplier les contenus des services
	jQuery("#content .bt_fulldesc").click (function () {		
		var showType = jQuery(this).attr("type");
		var docid = jQuery(this).attr("article");
		
		// modif RS >> si c'est un bouton "s'inscrire" rediriger vers la page de formulaire
		if (jQuery(this).hasClass("bt_subscribe_70"))
		{
			document.location.href="InscriptionPromotion.html?promo=" + docid;
			return;
		}
		
		jQuery("#bottom").css("visibility", "hidden");    	
		jQuery("#plain_" + docid).toggle('middle', function() {    		
			jQuery("#bottom").css("visibility", "visible");
			
			// switcher le bouton show/hide
			if (showType == "show")
			{
				jQuery("#bt_show_article_"+docid).hide();
				jQuery("#bt_hide_article_"+docid).show();
			}
			else
			{
				jQuery("#bt_show_article_"+docid).show();
				jQuery("#bt_hide_article_"+docid).hide();
			}    
			ResizeSiteHeight();
			ReCenterSite();
			
		    jQuery(window).bind('resize', function() {
		   		ReCenterSite();
			});
		});    	
	});
	
	
	// EXPAND ACTU DESCRIPTION FROM ID
	var nReq = location.search.substring(1,location.search.length);
    var id_promo = nReq.substring(nReq.indexOf("=")+1, nReq.length);
    jQuery("#plain_" + id_promo).toggle('middle', function() { 
		jQuery("#bt_show_article_"+id_promo).hide();
		jQuery("#bt_hide_article_"+id_promo).show();
   		
   		ResizeSiteHeight();
   		ReCenterSite();
   		
   	    jQuery(window).bind('resize', function() {
   	   		ReCenterSite();
   		});
   	});
	
});

function ChangePromo()
{
	var idToShow = 0;
	jQuery('.encart_promo').each(function(i) {
		var id_promo = jQuery(this).attr('promo');
		if (current_promo_id == id_promo)
		{
			idToShow = i + 1;
		}
		if (idToShow >= nb_promos)
		{
			jQuery('.encart_promo:first').show();
			current_promo_id = jQuery('.encart_promo:first').attr('promo');
			jQuery(this).hide();
			setTimeout("ChangePromo();", 10000);
		}
		else if (idToShow != 0 && i == idToShow)
		{
			jQuery(this).show();
			current_promo_id = id_promo;
			setTimeout("ChangePromo();", 10000);
		}
		else
			jQuery(this).hide();
	});
}


