//
// Fichier contenant les nouveaux scripts suite a la petite refonte d'Aeromorning.com 02/2011
//

var $j = jQuery.noConflict();

var action;
var mot;

var nb_bandeau = 0;

$j(document).ready(function() {
	
	// Pour la gestion de la recherche en haut de page
	$j("select[name='type_recherche']").change(function() {
		
		if($j(this).val() == 'agenda') {
		    action = "http://www.aeromorning.com/agenda/recherche.php";
		    mot = "mot";
		}
		if($j(this).val() == 'annuaire') {
		    action = "http://www.aeromorning.com/annuaire/annuaire.php";
		    mot = "mot";
		}
		if($j(this).val() == 'bonasavoir') {
		    action = "http://www.aeromorning.com/recherche_breve.php";
		    mot = "mot_chro";
		}
		if($j(this).val() == 'carnet') {
		    action = "http://www.aeromorning.com/carnet/carnet.php";
		    mot = "mot";
		}
		if($j(this).val() == 'chroniques') {
		    action = "http://www.aeromorning.com/recherche_chronique.php";
		    mot = "mot_chro";
		}
		if($j(this).val() == 'discours') {
		    action = "http://www.aeromorning.com/discours/discours.php";
		    mot = "mot";
		}
		if($j(this).val() == 'livres') {
		    action = "http://www.aeromorning.com/annonce/lire.php";
		    mot = "mot";
		}
		if($j(this).val() == 'news') {
		    action = "http://www.aeromorning.com/rech.php";
		    mot = "mot";
		}
		if($j(this).val() == 'mediateur') {
		    action = "http://www.aeromorning.com/recherche_mediateur.php";
		    mot = "mot_chro";
		}
		if($j(this).val() == 'tribunelibre') {
		    action = "http://www.aeromorning.com/recherche_tribune.php";
		    mot = "mot_chro";
		}
		
		$j("form[name='recherche']").attr("action",action);
		$j("#mot_recherche").attr("name",mot);
	    });
	// Fin gestion de la recherche en haut de page
	
	// 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':'15px'
				    });
		    }
		}
		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':'15px'
						       });
		    }
		}
	    });
	// Fin Scroll des deux sky
	
	// 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
