//Positionne le background des nouvelles sur l'accueil
function backgroundNouvelles() {
	var offset = $("#nouvelles_box").offset();
	offsetTop = Math.round(offset.top);
	//alert(offsetTop)
	if (offset.top > 568) {
		positionBackground = 15;
	} else {
		baseNouvelles = 569;
		//basePositionBackground = 22;
		basePositionBackground = 15;
		positionBackground = (baseNouvelles - offsetTop) + basePositionBackground;
	}
	if(typeof document.body.style.maxHeight === "undefined") {
		positionBackground = positionBackground - 10;
	}
	$(".nouvelles_contenu").css({ backgroundPosition: '0px ' + positionBackground + 'px' });
}


/* Slideshow de photos sur l'accueil */
function slideSwitch() {
    var $active = $('#photos IMG.active');

    if ( $active.length == 0 ) $active = $('#photo IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#photos IMG:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

/* Slideshow de nouvelles sur l'accueil */
function newsSwitch() {
    var $active = $('#nouvelles_dyn div.active');

    if ( $active.length == 0 ) $active = $('#nouvelles_dyn div:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#nouvelles_dyn div:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');
    
    $active.slideUp(function() {
    		$next.slideDown(function() {
    			$next.addClass('active');
            	$active.removeClass('active last-active');
        	});
        });

}



$(document).ready(function(){ 

	backgroundNouvelles();
	
	setInterval( "slideSwitch()", 5000 );
	
	setInterval( "newsSwitch()", 8000 );
	
} );
