var $j = jQuery.noConflict();
var action;
var mot;

$j(document).ready(function() {
	$j("select[name='type_recherche']").change(function() {
	
		if($j(this).val() == 'agenda') {
			action = "http://www.aeromorning.com/en/agenda/recherche.php";
			mot = "mot";
		}
		if($j(this).val() == 'annuaire') {
			action = "http://www.aeromorning.com/en/annuaire/annuaire.php";
			mot = "mot";
		}
		if($j(this).val() == 'carnet') {
			action = "http://www.aeromorning.com/en/carnet/carnet.php";
			mot = "mot";
		}
		if($j(this).val() == 'chroniques') {
			action = "http://www.aeromorning.com/en/recherche_chronique.php";
			mot = "mot_chro";
		}
		if($j(this).val() == 'discours') {
			action = "http://www.aeromorning.com/en/discours/discours.php";
			mot = "mot";
		}
		if($j(this).val() == 'livres') {
			action = "http://www.aeromorning.com/en/annonce/lire.php";
			mot = "mot";
		}
		if($j(this).val() == 'news') {
			action = "http://www.aeromorning.com/en/rech.php";
			mot = "mot";
		}
	
		$j("form[name='recherche']").attr("action",action);
		$j("#mot_recherche").attr("name",mot);
	});
	
	// Le Scroll des deux sky
	var offsetPubGauche = $j('#pubs_gauche').offset();
	var offsetPubDroite = jQuery('#pubs_droite').offset();

	$j(window).scroll(function() {
		if(offsetPubGauche != null) {
			if($j(window).scrollTop() <= offsetPubGauche.top) {
				$j('#pubs_gauche').css({
					'position':'absolute',
					'margin-top':'167px'
				});	
			} else {
				$j('#pubs_gauche').css({
					'position':'fixed',
					'margin-top':'0'
				});
			}
		}
		if(offsetPubDroite != null) {
			if(jQuery(window).scrollTop() <= offsetPubDroite.top) {
				$j('#pubs_droite').css({
					'position':'absolute',
					'margin-top':'167px'
				});
			} else {
				$j('#pubs_droite').css({
					'position':'fixed',
					'margin-top':'0'
				});
			}
		}
	});
	
	// Rotation des bandeaux
	nb_bandeau = $j("div.bandeau").length - 1;
	if($j("div.bandeau").length != '' || $j("div.bandeau").length != 0) {
		$j("div.bandeau").hide();
		change_bandeau(0);
	}
	// Fin Rotation des bandeaux

});

// Fonction permettant la rotation des bandeaux
function change_bandeau(index) {
	if(index > nb_bandeau) {
		change_bandeau(0);
	}
	else {
		$j("div.bandeau").each(function(i, elem){
			if(index == i) {
				$j(elem).show();
				var next_time = parseInt($j(elem).attr("temps")) * 1000;
				setTimeout(function(){change_bandeau(index+1)}, next_time);
			}
			else {
				$j(elem).hide();
			}
		});
	}
}
// Fin Fonction permettant la rotation des bandeaux
