$(document).ready(function() {
		var largeur = $("#menu").outerWidth();
		var hauteur = document.documentElement.scrollHeight;
		/*$("#menu").css('width', largeur+'px');
		$("#menu").css('height', hauteur+'px');*/

		//$("#menu").hide();
		$("#gauche").css('height', hauteur+'px');
		$("#gauche-accueil").css('height', hauteur+'px');

		/*function taillePage() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else {
				xScroll = document.body.offsetWidth;
				yScroll = document.documentElement.scrollHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) {
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			if(xScroll < windowWidth){
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		}*/
		taillePage();
	});

	function cacheMenu() {
		$(".article iframe").show();
		document.getElementById("id_fondMenu").cacheFond();
		$("#menu").hide();

		/*setTimeout(function(){
						$("#menu").hide();
					},100);*/
		/*
		$("#fondMenu").hide("slow",function(){
										$("#menu").hide();
									});
		*/
	}
	function cacheFond() {
		$("#fondMenu").hide();
	}
	function cacheChargement() {
		document.getElementById("id_FlashGauche").cacheChargement();
	}
	function afficheChargement() {
		document.getElementById("id_FlashGauche").afficheChargement();
	}
	function affMentions(url){
		var adresse = url || "/mentions.php";
		var fen = window.open(adresse,"Mentions","width=700,height=500,menubar=yes,status=no,resizable=no,location=no,toolbar=no,scrollbars=yes");
		fen.focus();
	}


	/*******  ACTUALITES ********/

	var rubActuRedim = false;
	var interRubActuRedim = '';
	var cptRubActuRedim = 0;
	var cpt2RubActuRedim = 0;
	function redimRubActus(){
		cptRubActuRedim++;
		if(!rubActuRedim){
			rubActuRedim = true;

			interRubActuRedim = setInterval(function(){

						if(cptRubActuRedim == cpt2RubActuRedim){

						/*
							$(".jScrollPaneTrack").remove();
							$(".jScrollPaneTrack2").remove();

							var tailleScroll = document.documentElement.clientWidth - 315;
							$("#listeActualites").css('width', tailleScroll+'px');
							$(".jScrollPaneContainer").css('width', (tailleScroll-20)+'px');
						*/

							var listeActus = $("#listeActualites").clone();
							$("#contenuActualite").empty();
							listeActus.prependTo("#contenuActualite");

							var tailleScroll = document.documentElement.clientWidth - 315;
							$("#listeActualites").css('width', tailleScroll+'px');
							$('#listeActualites').jScrollHorizontalPane({reset:true,aintellianceMargin:-20, scrollbarHeight:22, scrollbarMargin:0});


							clearInterval(interRubActuRedim);
							rubActuRedim = false;
						}
						else{
							cpt2RubActuRedim = cptRubActuRedim;
						}

					} , 300);
		}
	}

	function rubriqueActus(){

		rubActu_creerScrollPane();

		var url = window.location.href;
		var parsed_url = url.split('#');
		if (parsed_url[1] != undefined && parsed_url[1] != "") {
			var posActu = $("#"+parsed_url[1]).position();
			//alert(typeof(posActu));
			if(typeof(posActu)=='object'){
				$('#listeActualites')[0].scrollTo(posActu.left);
			}
		} else {

			/*setTimeout(function(){
						// Pour l'effet de démo du début
						$('#listeActualites')[0].scrollTo(80, true, function(e) {
							$('#listeActualites')[0].scrollTo(0);
						});
					},1000);*/
		}

		setTimeout(function(){
			if($("#texteBloc")[0]){
				var hauteur = $("#texteBloc").position().top + $("#texteBloc").height();

					var dimensions = {width: 0, height: 0};
				    if (document.documentElement) {
				        dimensions.width = document.documentElement.offsetWidth;
				        dimensions.height = document.documentElement.offsetHeight;
				    } else if (window.innerWidth && window.innerHeight) {
				        dimensions.width = window.innerWidth;
				        dimensions.height = window.innerHeight;
				    }
					//alert(dimensions.height);
					if( hauteur > dimensions.height ){
						$("#gauche").css('height', hauteur+'px');
					}
					else{
						$("#gauche").css('height', dimensions.height+'px');
					}
			  }
			},1000);

	}


	function taillePage() {
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.documentElement.scrollHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth;
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else {
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){
			pageWidth = xScroll;
		} else {
			pageWidth = windowWidth;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
		return arrayPageSize;
	}


	function rubActu_creerScrollPane(){
		var tailleScroll = document.documentElement.clientWidth - 315;
		//alert(tailleScroll);
		$("#listeActualites").css('width', tailleScroll+'px');
		// Agrandit la largeur du bloc article en fonction du contenu
		var hauteurMaxi = 335;
		var tailleArticle = 0;
		var taillePremierArticle = 0;

		$(".cadreActualite").each(function(){
			var hauteur = $(this).height();
			var largeur = $(this).width();
			if(hauteur > 320) {
				tailleArticle = largeur;
				while(hauteur > hauteurMaxi) {
					tailleArticle = tailleArticle + 10;
					$(this).css({'width': tailleArticle+'px'});
					hauteur = $(this).height();
				}
				if(taillePremierArticle==0){
					taillePremierArticle = tailleArticle;
				}
				//on rajoute un peu :
				tailleArticle = tailleArticle + 50;
				$(this).css({'width': tailleArticle+'px'});
				hauteur = $(this).height();
				//--------------------------
			}
			$(this).css({'height': hauteurMaxi+'px'});
		});

		// Donne la taille globale du div qui contient les articles
		var tailleArticles = 0;
		var dernierArticle;
		var i = 0;

		$(".cadreActualite").each(function(){
			i++;
			var taille = $(this).outerWidth();
			tailleArticles = tailleArticles + taille;
			dernierArticle = $(this).attr("name");
		});
		$("#actu_"+dernierArticle).css({'margin-right': '0px'});
		tailleArticles = tailleArticles + (i*3) - 3 +(tailleScroll-$("#actu_"+dernierArticle).width());
var correction = 0;
if(taillePremierArticle-tailleScroll>0){
	correction = taillePremierArticle-tailleScroll+50;
}
		$("#bande_grise").css({'height': '386px'});

		$(".bloc").css({'width': tailleArticles+20+correction+'px'});
//alert(tailleScroll + " / " + taillePremierArticle + " / " + $(".bloc").width());
//alert(taillePremierArticle-tailleScroll+50);
		$('#listeActualites').jScrollHorizontalPane({reset:true, scrollbarHeight:22, scrollbarMargin:0});


	}

	function ancreArticle(idActu) {
		var posActu = $("#actu_"+idActu).position();
		$('#listeActualites')[0].scrollTo(posActu.left);
		//$('#lienActu_'+idActu).animate({backgroundColor : "#FFFFFF"}, 500).addClass('courant');
		//$('.lienActu:not(#lienActu_'+idActu+')').animate({backgroundColor : "#666666"}, 500).removeClass('courant');
		return false;
	}

/******************************************************************/

/**** REVUE DE PRESSE ****/

	var rubRevueRedim = false;
	var interRubRevueRedim = '';
	var cptRubRevueRedim = 0;
	var cpt2RubRevueRedim = 0;
	function redimRubRevue(){
		cptRubRevueRedim++;
		if(!rubRevueRedim){
			rubRevueRedim = true;

			interRubRevueRedim = setInterval(function(){

						if(cptRubRevueRedim == cpt2RubRevueRedim){
							/*
							$(".jScrollPaneTrack").remove();
							$(".jScrollPaneTrack2").remove();

							var tailleScroll = document.documentElement.clientWidth - 315;
							$("#listeRevuesPresse").css('width', tailleScroll+'px');
							$(".jScrollPaneContainer").css('width', (tailleScroll-20)+'px');
							$('#listeRevuesPresse').jScrollHorizontalPane({reset:true,intellianceMargin:-20, scrollbarHeight:22, scrollbarMargin:0});
							*/

							var listeRevue = $("#listeRevuesPresse").clone();
							$("#contenuRevuePresse").empty();
							listeRevue.prependTo("#contenuRevuePresse");

							var tailleScroll = document.documentElement.clientWidth - 315;
							$("#listeRevuesPresse").css('width', tailleScroll+'px');
							var hauteurRevue = 0;
							$(".cadreRevuePresse").each(function(){
								if($(this).height() > hauteurRevue) {
									hauteurRevue = $(this).height();
								}
							});
							$('#listeRevuesPresse').jScrollHorizontalPane({reset:true,aintellianceMargin:-20, hauteurContenu:(hauteurRevue+73),scrollbarHeight:22, scrollbarMargin:0});

							if( $(".bloc").width()-20 <= tailleScroll) {
								$(".bloc").css({'margin-top': '30px'});
							}
							else{
								$(".bloc").css({'margin-top': '10px'});
							}

							clearInterval(interRubRevueRedim);
							rubRevueRedim = false;
						}
						else{
							cpt2RubRevueRedim = cptRubRevueRedim;
						}

					} , 700);
		}



	}

	function rubriqueRevuePresse(){
		var tailleScroll = document.documentElement.clientWidth - 315;

		$("#listeRevuesPresse").css('width', tailleScroll+'px');

		// Agrandit la largeur du bloc article en fonction du contenu
		var hauteurRevue = 0;
		var tailleArticle = 0;

		$(".imgBreve").each(function(){
			var largeur = $(this).width();
			$(this).parents(".cadreRevuePresse").css({'width': largeur+'px'});
		});

		$(".cadreRevuePresse").each(function(){
			if($(this).height() > hauteurRevue) {
				hauteurRevue = $(this).height();
			}
		});

		$(".imgBreve").each(function(){
			//var largeur = $(this).width();
			$(this).parents(".cadreRevuePresse").css({'height': hauteurRevue+'px'});
			//$(this).parents(".cadreRevuePresse").css({'width': largeur+'px'});
		});

		// Donne la taille globale du div qui contient les articles
		var tailleRevuesPresse = 0;
		var derniereRevue;
		var i = 0;

		$(".cadreRevuePresse").each(function(){
			i++;
			var taille = $(this).outerWidth();
			tailleRevuesPresse = tailleRevuesPresse + taille;
			derniereRevue = $(this).attr("name");
		});
		$("#revue_"+derniereRevue).css({'margin-right': '0px'});
		tailleRevuesPresse = tailleRevuesPresse + (i*3)-3 +(tailleScroll-$("#revue_"+derniereRevue).width());
		/*var correction = 0;
		if(taillePremierArticle-tailleScroll>0){
			correction = taillePremierArticle-tailleScroll+50;
		}*/

		$("#bande_grise").css({'height': (hauteurRevue+51)+'px'});

		$(".bloc").css({'width': tailleRevuesPresse+20+'px'});
//alert($(".bloc").width() + " / " + tailleScroll);
		$('#listeRevuesPresse').jScrollHorizontalPane({scrollbarHeight:22, hauteurContenu:(hauteurRevue+73), scrollbarMargin:0,minimumWidth:tailleScroll});

		if(tailleRevuesPresse <= (document.documentElement.clientWidth - 315)) {
			$(".bloc").css({'margin-top': '30px'});
		}


		setTimeout(function(){
				var url = window.location.href;
				var parsed_url = url.split('#');
				if (parsed_url[1] != undefined && parsed_url[1] != "") {
					var posActu = $("#"+parsed_url[1]).position();

					//alert('largeur : '+ $(".jScrollPaneContainer").width());
					//alert(typeof(posActu));
					if(typeof(posActu)=='object'){
						$('#listeRevuesPresse')[0].scrollTo(posActu.left);
					}
				} else {
					// Pour l'effet de démo du début

						/*$('#listeRevuesPresse')[0].scrollTo(50, true, function(e) {
							$('#listeRevuesPresse')[0].scrollTo(0);
						});*/
				}
			},1000);

		setTimeout(function(){
			if($("#texteBloc")[0]){
				var hauteur = $("#texteBloc").position().top + $("#texteBloc").height();

					var dimensions = {width: 0, height: 0};
				    if (document.documentElement) {
				        dimensions.width = document.documentElement.offsetWidth;
				        dimensions.height = document.documentElement.offsetHeight;
				    } else if (window.innerWidth && window.innerHeight) {
				        dimensions.width = window.innerWidth;
				        dimensions.height = window.innerHeight;
				    }
					//alert(dimensions.height);
					if( hauteur > dimensions.height ){
						$("#gauche").css('height', hauteur+'px');
					}
					else{
						$("#gauche").css('height', dimensions.height+'px');
					}
				}


			},1000);
	}

	function ancreRevue(idRevue) {
		var posRevue = $("#revue_"+idRevue).position();
		$('#listeRevuesPresse')[0].scrollTo(posRevue.left);
		//$('#lienRevue_'+idRevue).animate({backgroundColor : "#FFFFFF"}, 500).addClass('courant');
		//$('.lienRevue:not(#lienRevue_'+idRevue+')').animate({backgroundColor : "#666666"}, 500).removeClass('courant');
		return false;
	}

