jQuery(document).ready(function(){
	if (jQuery("#miseEnAvantPartenaire"))
	{
		setTimeout("miseEnAvantPartenaire()",2000);
	}
	showRandomAutopromo();
	// setTimeout("detectActivePage()",4000);
});
var activeRandomAutoPromo = 0;
function detectActivePage()
{
	jQuery("body").mouseover(function() {
		if (jQuery(".displayAutopromo"))
		{
			if (activeRandomAutoPromo == 0)
			{
				activeRandomAutoPromo = 1;
				showRandomAutopromo();
			}
		}
	});
}

var apDuration = 7000;
var currentAp = 1;
var cellCount = 0;
function showRandomAutopromo()
{
	var arrayDuration = new Array();

	jQuery(".displayAutopromo").each(function(i){
		var idAndDuration = this.id.split("_");
		arrayDuration[i] = idAndDuration[2];
	});
	var firstDuree = arrayDuration[0] * 1000;
	setTimeout(function(){
    	changeAp(arrayDuration);
	},firstDuree);
}

function changeAp(duree) {
	dureeForFunction = duree;
	j = duree.length;
	apToHide = currentAp;
	cellTab = cellCount;
	if (currentAp < j)
	{
		currentAp = currentAp + 1;
		cellCount = cellCount + 1;
	}
	else
	{
		currentAp = 1;
		cellCount = 0;
	}
	jQuery(".displayAutopromo").hide();
	var cheminAp = jQuery("#autopromo_" + currentAp + "_" + dureeForFunction[cellCount]).children("a").children("img").attr("src");
	var cheminAp = jQuery("#autopromo_" + currentAp + "_" + dureeForFunction[cellCount]).children("a").children("img").attr("src",cheminAp);
	jQuery("#autopromo_" + currentAp + "_" + dureeForFunction[cellCount]).fadeIn("slow");
	setTimeout(function(){
    	changeAp(dureeForFunction);
	},dureeForFunction[cellCount] * 1000);
}


/*function changeAp(nbAp) {
	j = nbAp;
	apToHide = currentAp;
	if (currentAp < j)
	{
		currentAp = currentAp + 1;
	}
	else
	{
		currentAp = 1;
	}
	jQuery("#autopromo_" + apToHide).hide();
	jQuery("#autopromo_" + currentAp).fadeIn("slow");
	setTimeout("changeAp(j)",apDuration);
}*/

// Gestion de l'affichage des partenaire
function miseEnAvantPartenaire()
{
	jQuery("#miseEnAvantPartenaire").slideRight();

}

jQuery.fn.extend({
	slideRight: function() {
		return this.each(function() {
		jQuery(this).animate({width: 'show'},1000);
	});
	},
	slideLeft: function() {
		return this.each(function() {
		jQuery(this).animate({width: 'hide'});
	});
	},
	slideToggleWidth: function() {
		return this.each(function() {
		var el = jQuery(this);
		if (el.css('display') == 'none') {
			el.slideRight();
		} else {
			el.slideLeft();
		}
	});
	}
});
