/*
	8 novembre 2009
	Alex
	a.lepage@difuzer.com
	
	Rotation des réalisations sur la
	homepage avec jQuery
	
	ajout 27 janvier 2009
	+ bloc annonces s_init et s_next
	prennent un paramètre de plus
*/
var p_previous = new Array();
var p_current = new Array();
var p_next = new Array();
var pictures = new Array();
var loop = new Array();

function s_init(inst) {

	p_current[inst] = pictures[inst].length-1;
	p_previous[inst] = p_current[inst]-1;
	p_next[inst] = 0;
	loop[inst] = true;
	s_next(false, inst);
}
function s_next(force, inst) {

	if (loop[inst] || force) {
		p_previous[inst] = p_current[inst];
		p_current[inst] = p_next[inst];
		++p_next[inst];
		if (p_next[inst] == pictures[inst].length)
		     p_next[inst] = 0;

		//hide previous and show current
		$(".rea"+inst+"_"+pictures[inst][p_previous[inst]]).fadeOut(2000, function () {	});
		if (document.getElementById('frame'+pictures[inst][p_previous[inst]])) {
		document.getElementById('frame'+pictures[inst][p_previous[inst]]).style.backgroundImage = 'url(\'/img/cadre_not.png\')';
		document.getElementById('frame'+pictures[inst][p_current[inst]]).style.backgroundImage = 'url(\'/img/cadre_on.png\')';
		}
		$(".rea"+inst+"_"+pictures[inst][p_current[inst]]).fadeIn(2000);
		if (inst == 2)
		document.getElementById('linkrea').href = 'http://'+url[p_current[inst]];

		setTimeout('s_next(false, '+inst+')', 10000);
		
		return p_current[inst];
	}
	else
	     loop[inst] = true;
	return false;
}
function s_prev(force, inst) {

	if (loop[inst] || force) {
		p_next[inst] = p_current[inst];
		p_current[inst] = p_previous[inst];
		--p_previous[inst];
		if (p_previous[inst] == -1)
			p_previous[inst] = pictures[inst].length-1;

		//hide next and show current
		$(".rea"+inst+"_"+pictures[inst][p_next[inst]]).fadeOut(2000, function () {});
		$(".rea"+inst+"_"+pictures[inst][p_current[inst]]).fadeIn(2000);
		if (inst == 2)
		document.getElementById('linkrea').href = 'http://'+url[p_current[inst]];
		
		setTimeout('s_next(false, '+inst+')', 10000);
		
		return p_current[inst];
	}
	else
	     loop[inst] = true;
	return false;
}