var ParametresAffichage = {
	
	bodyClass_0 : 'res1024',
	bodyClass_1 : 'res1280',
	bodyClass_2 : 'res1600',
	/* Durée en millisecondes de l'animation de décalage du menu sur la gauche et d'agrandissement du carré rouge */
	dureeAnimation : 900,
	couleurCarre : "rgb(255,0,0)",
	/* Nombre de pixels de la largeur du menu sur la gauche */
	largeurMenuGauche_0 : 422,
	largeurMenuGauche_1 : 422,
	largeurMenuGauche_2 : 422,
	/* Nombre de pixels pour le décalage du menu sur la gauche */
	largeurDecalageMenuGauche_0 : 340,
	largeurDecalageMenuGauche_1 : 340,
	largeurDecalageMenuGauche_2 : 340,
	/* URL de l'image affichée à gauche des menus fermés */
	imageMenuDroitFerme : 'palette/vert/puce_fleche_vert.gif',
	/* URL de l'image affichée à gauche des menus ouverts */
	imageMenuDroitOuvert : 'images/puce_fleche_noir_dw.gif',
	/* URL de l'image affichée à gauche des menus qui ne s'ouvrent pas */
	imageMenuDroitTransparent : 'images/puce_fleche_trans.gif',
	/* Taille en pixels de la zone de dessin */
	tailleCanvas_0 : [966, 546],
	tailleCanvas_1 : [966, 546],
	tailleCanvas_2 : [1086, 546],
	/* Positionnement du carré dans le canvas */
	positionPetitCarre_0 : [587, 285],
	positionMoyenCarre_0 : [544, 352],
	positionGrandCarre_0 : [277, 352],
	positionPetitCarre_1 : [584, 284],
	positionMoyenCarre_1 : [544, 351],
	positionGrandCarre_1 : [277, 351],
	positionPetitCarre_2 : [584, 284],
	positionMoyenCarre_2 : [544, 351],
	positionGrandCarre_2 : [277, 351],
	/* Angle de positionnement du carré rouge */
	angleRotationCarre : (-15 * Math.PI/180),
	menuDroitDepartFleche : 5,
	menuDroitDecalageFleche : 4,
	/* Décalage pour centrage */
	ajustement_0 : 0,
	ajustement_1 : 260,
	ajustement_2 : 460,	
	/* Largeur zone actus */
	largeurZoneActus : 322,
	largeurSignature : 316,
	resolutionCourrante : 0,
	zoneImageLargeur : 0,
	zoneImageHauteur : 0,
	
	parametres : new Array(),
	
	init : function() {
		$('#Resolution').css('display','');
		/* Recherche de la résolution écran */
		var lScreenWidth = screen.width;
		if (lScreenWidth < 1280) {
			/* Affichage pour du 1024 */
			this.resolutionCourrante = 0;
		} else if (lScreenWidth < 1600) {
			/* Affichage pour du 1280 */
			this.resolutionCourrante = 1;
		} else {
			/* Affichage pour du 1600 */
			this.resolutionCourrante = 2;
		}
		var params = new Array();
		this.parametres[0] = params;
		params['bodyClass'] = this.bodyClass_0;
		params['bodyBackground'] = this.background1024;
		params['largeurMenuGaucheFerme'] = this.largeurMenuGauche_0;
		params['largeurMenuGaucheOuvert'] = this.largeurDecalageMenuGauche_0;
		params['ajustement'] = this.ajustement_0;
		params['tailleCanvas'] = this.tailleCanvas_0;
		params['positionPetitCarre'] = this.positionPetitCarre_0;
		params['positionMoyenCarre'] = this.positionMoyenCarre_0;
		params['positionGrandCarre'] = this.positionGrandCarre_0;
		params['largeurZoneActus'] = this.largeurZoneActus;
		params = new Array();
		this.parametres[1] = params;
		params['bodyClass'] = this.bodyClass_1;
		params['bodyBackground'] = this.background1280;
		params['largeurMenuGaucheFerme'] = this.largeurMenuGauche_1;
		params['largeurMenuGaucheOuvert'] = this.largeurDecalageMenuGauche_1;
		params['ajustement'] = this.ajustement_1;
		params['tailleCanvas'] = this.tailleCanvas_1;
		params['positionPetitCarre'] = this.positionPetitCarre_1;
		params['positionMoyenCarre'] = this.positionMoyenCarre_1;
		params['positionGrandCarre'] = this.positionGrandCarre_1;
		params['largeurZoneActus'] = this.largeurZoneActus;
		params = new Array();
		this.parametres[2] = params;
		params['bodyClass'] = this.bodyClass_2;
		params['bodyBackground'] = this.background1600;
		params['largeurMenuGaucheFerme'] = this.largeurMenuGauche_2;
		params['largeurMenuGaucheOuvert'] = this.largeurDecalageMenuGauche_2;
		params['ajustement'] = this.ajustement_2;
		params['tailleCanvas'] = this.tailleCanvas_2;
		params['positionPetitCarre'] = this.positionPetitCarre_2;
		params['positionMoyenCarre'] = this.positionMoyenCarre_2;
		params['positionGrandCarre'] = this.positionGrandCarre_2;
		params['largeurZoneActus'] = this.largeurZoneActus + 140;
		var lDivContainer = $('#Container');
		$('body').attr('class',this.parametres[this.resolutionCourrante]['bodyClass']);
		lDivContainer.attr('style','background:url('+this.parametres[this.resolutionCourrante]['bodyBackground']+') left top no-repeat!important;');
		$('#fil_actu > p').css('width',this.getLargeurZoneActus()+'px');
		$('#signature').css('width',this.largeurSignature+'px');
		$('#zone_lien').css({'width':this.zoneImageLargeur+'px','height':this.zoneImageHauteur+'px'});
		var lCanvas = $('#canvas');
		var lTailleCanvas = this.getTailleCanvas();
		$('#canvas').attr({'width':lTailleCanvas[0],'height':lTailleCanvas[1]});
		lCanvas.css({'left':this.getLeftPositionCanvas(),'display':''});
		var _this = this;
		$(window).resize(function() {
			lCanvas.css('left',_this.getLeftPositionCanvas());
		});
		
	},
	getLargeurMenuGaucheOuvert : function() {return this.parametres[this.resolutionCourrante]['largeurMenuGaucheOuvert'];},
	getLargeurMenuGaucheFerme : function() {return this.parametres[this.resolutionCourrante]['largeurMenuGaucheFerme'];},
	getLargeurZoneActus : function() {return this.parametres[this.resolutionCourrante]['largeurZoneActus'];},
	getAjustement : function() {return this.parametres[this.resolutionCourrante]['ajustement'];},
	getTailleCanvas : function() {return this.parametres[this.resolutionCourrante]['tailleCanvas'];},
	getPositionPetitCarre : function() {return this.parametres[this.resolutionCourrante]['positionPetitCarre'];},
	getPositionMoyenCarre : function() {return this.parametres[this.resolutionCourrante]['positionMoyenCarre'];},
	getPositionGrandCarre : function() {return this.parametres[this.resolutionCourrante]['positionGrandCarre'];},
	getTaillePetitCarre : function() {return 60;},
	getTailleMoyenCarre : function() {return 680;},
	getTailleGrandCarre : function() {return 900;},
	getLeftPositionCanvas : function() {
		var lLeft = (($(window).width()-(980+this.getAjustement()))/2);
		if (2 == this.resolutionCourrante) {
			lLeft = lLeft - 60;
		}
		if (lLeft < 0) {
			lLeft = 0;
		}
		return lLeft;
	}
}

var MenuPortail = {

	IDMenuNiveau1 : '#menuNiv1_',
	IDSousMenuNiveau1 : '#sousMenuNiv1_',
	IDDivDecalage : '#media_box',
	
	items : new Array(),
	
	estOuvert : false,
	menuGaucheActif : null,
	menuDroitActif : null,
	footerActif : null,
	
	listeMenusScroll : new Array(),

	init : function() {
		AnimationCarre.init();
	},

	fermer : function() {
		if (this.footerActif!=undefined) {
			this.masquerFooter(this.footerActif);
		}
		var _this = this;
		AnimationCarre.animer(AnimationCarre.PETIT, function() {
			// Fermeture du niveau 1 déjà ouvert
			if (_this.menuGaucheActif != null) {
				_this.menuGaucheActif.fermer();
			}
			$(_this.IDDivDecalage).css('width',ParametresAffichage.getLargeurMenuGaucheFerme()+'px');
			$('#media_box').show();
			$('#menu_gauche').show();
			$('#menu_droit').show();
			_this.estOuvert = false;
		});
	},

	deplierNiveau1 : function(pIDMenuNiveau1) {
		var _this = this;
		function afficherSousMenuNiveau1(pIDMenuNiveau1) {
			// Fermeture du niveau 1 déjà ouvert
			if (_this.menuGaucheActif != null) {
				_this.menuGaucheActif.fermer();
			}
			// Récupération du niveau 1 à ouvrir
			var lMenuNiveau1 = _this.items[pIDMenuNiveau1];
			if (lMenuNiveau1 == undefined) {
				lMenuNiveau1 = new MenuNiveau1(_this.IDMenuNiveau1+pIDMenuNiveau1, _this.IDSousMenuNiveau1+pIDMenuNiveau1);
				_this.items[pIDMenuNiveau1] = lMenuNiveau1;
			}
			// Ouverture du niveau 1
			lMenuNiveau1.ouvrir();
			_this.menuGaucheActif = lMenuNiveau1;
		}
	
		if (_this.estOuvert) {
			afficherSousMenuNiveau1(pIDMenuNiveau1);
		} else {
			AnimationCarre.animer(AnimationCarre.MOYEN);
			$(this.IDDivDecalage).animate({width:ParametresAffichage.getLargeurMenuGaucheOuvert()+'px'},{duration:ParametresAffichage.dureeAnimation, complete:function(){
				_this.estOuvert = true;
				afficherSousMenuNiveau1(pIDMenuNiveau1);
			}});
		}
	},

	deplierNiveau2 : function(pIDMenuNiveau1, pIndexMenuNiveau2, pTailleScroll) {
		// Récupération du niveau 1
		var lMenuNiveau1 = this.items[pIDMenuNiveau1];
		if (lMenuNiveau1 != undefined) {
			lMenuNiveau1.deplierSousMenu(pIndexMenuNiveau2, -1, pTailleScroll);
		}
	},

	deplierNiveau3 : function(pIDMenuNiveau1, pIndexMenuNiveau2, pIndexMenuNiveau3) {
		// Récupération du niveau 1
		var lMenuNiveau1 = this.items[pIDMenuNiveau1];
		if (lMenuNiveau1 != undefined) {
			lMenuNiveau1.deplierSousMenu(pIndexMenuNiveau2, pIndexMenuNiveau3);
		}
	},
	
	afficherFooter: function(pIdFooter) {
		var _this = this;
		$('#media_box').hide();
		$('#menu_gauche').hide();
		var lMenuDroit = $('#menu_droit');
		lMenuDroit.hide();
		AnimationCarre.animer(AnimationCarre.GRAND, function() {
			if (_this.footerActif!=undefined) {
				_this.masquerFooter(_this.footerActif);
			}
			var lFooter = $('#'+pIdFooter);
			if (lFooter!=undefined) {
				//lMenuDroit.after(lFooter.remove());
				lFooter.show();
				$('#'+pIdFooter+' > .mentions_contenu').jScrollPane({topCapHeight: 0});
				_this.footerActif = pIdFooter;
			}
		});
	},
	masquerFooter: function(pIdFooter) {
		var lFooter = $('#'+pIdFooter);
		if (lFooter!=undefined) {
			lFooter.hide();
			this.footerActif = null;
		}
	}
	
}

function MenuNiveau1(pIDMenu, pIDSousMenu) {

	this.IDMenu = pIDMenu;
	this.IDSousMenu = pIDSousMenu;
	this.sousMenus = new Array();
	this.sousMenuActif = null;

	var domSousMenus = $(this.IDSousMenu+' > ul > li');
	var nbSousMenus = domSousMenus.size();
	for (var i=0;i<nbSousMenus;i++) {
		this.sousMenus[i] = new MenuNiveau2(i, domSousMenus[i]);
	}

	this.ouvrir = function() {
		this.sousMenuActif = null;
		$.each(this.sousMenus, function(pIndex, pElement) {
			pElement.decaler(ParametresAffichage.menuDroitDepartFleche, pIndex);
		});
		$(this.IDSousMenu).show();
		$(this.IDMenu).addClass('on');
	}
	
	this.fermer = function() {
		$.each(this.sousMenus, function(pIndex, pElement) {
			pElement.fermer();
		});
		$(this.IDSousMenu).hide();
		$(this.IDMenu).removeClass('on');
	}

	this.deplierSousMenu = function(pIndexNiveau2, pIndexNiveau3, pTailleScroll) {
		// Fermeture sous menu ouvert
		if (this.sousMenuActif != null) {
			if (pIndexNiveau3 > -1) {
				this.sousMenuActif.deplierSousMenu(pIndexNiveau3);
				return;
			} else {
				this.sousMenuActif.fermer();
				for (var i=(this.sousMenuActif.index+1); i < this.sousMenus.length; i++) {
					this.sousMenus[i].decaler(ParametresAffichage.menuDroitDepartFleche, i);
				}
			}
		}
		// Ouverture sous menu demandé
		
		if (undefined != this.sousMenus[pIndexNiveau2]) {
			if (pTailleScroll!=undefined && pTailleScroll>0) {
				this.sousMenus[pIndexNiveau2].activerScroll(pTailleScroll);
			}
			this.sousMenus[pIndexNiveau2].ouvrir();
			var nbSousMenus = this.sousMenus[pIndexNiveau2].getSizeSousMenu();
			for (var i=(pIndexNiveau2+1); i < this.sousMenus.length; i++) {
				this.sousMenus[i].decaler(ParametresAffichage.menuDroitDepartFleche, i + nbSousMenus);
			}
			this.sousMenuActif = this.sousMenus[pIndexNiveau2];
		}
	}

}

function MenuNiveau2(pIndex, pDomElement) {

	this.index = pIndex;
	this.decalage = ParametresAffichage.menuDroitDepartFleche + ((pIndex + 1) * ParametresAffichage.menuDroitDecalageFleche);
	this.domElement = pDomElement;
	this.sousMenus = new Array();
	this.sousMenuActif = null;
	
	this.scroll = false;
	this.scrollBar = null;
	this.tailleScroll = 0;
	this.positionScroll = 0;
	this.conteneurScroll = $('> div.conteneurSousMenu',$(this.domElement));
	this.decalageScroll = 0;
	this.scrollListener = null;
	
	var domSousMenus = $('> div > ul > li',$(this.domElement));
	var nbSousMenus = domSousMenus.size();
	for (var i=0;i<nbSousMenus;i++) {
		this.sousMenus[i] = new MenuNiveau3(i, domSousMenus[i]);
	}
	
	this.decaler = function(pDecalage, pIndex) {
		var lChildrenLI = $(this.domElement).children();
		var lImageDecalage = $(lChildrenLI[0]);
		lImageDecalage.attr('width',  pDecalage + (ParametresAffichage.menuDroitDecalageFleche * pIndex));
	}
	
	this.ouvrir = function() {
		this.sousMenuActif = null;
		this.decalageScroll = 0;
		var _this = this;
		$.each(this.sousMenus, function(pIndex, pElement) {
			pElement.decaler(_this.decalage, pIndex);
		});
		$('> span > a',$(this.domElement)).addClass('on');
		$('> img',$(this.domElement))[1].src = ParametresAffichage.imageMenuDroitOuvert;
		$(this.conteneurScroll).show();
		this.afficherScroll();
	}
	
	this.fermer = function() {
		$.each(this.sousMenus, function(pIndex, pElement) {
			pElement.fermer();
		});
		$(this.conteneurScroll).hide();
		$('> span > a',$(this.domElement)).removeClass('on');
		var lImageFleche = $('> img',$(this.domElement))[1];
		if (lImageFleche != undefined &&  lImageFleche.src.indexOf(ParametresAffichage.imageMenuDroitTransparent) == -1) {
			lImageFleche.src = ParametresAffichage.imageMenuDroitFerme;
		}
	}
	
	this.deplierSousMenu = function(pIndexSousMenu) {
		var lIndex;
		if (this.sousMenuActif != null) {
			this.sousMenuActif.fermer();
			for (var i=(this.sousMenuActif.index+1); i < this.sousMenus.length; i++) {
				lIndex = i;
				if (this.scroll) {
					lIndex = lIndex - this.positionScroll;
				}
				this.sousMenus[i].decaler(this.decalage, lIndex);
			}
		}
		if (this.sousMenus[pIndexSousMenu]!=undefined) {
			var lHeightSousMenus = this.sousMenus[pIndexSousMenu].ouvrir();
			for (var i=(pIndexSousMenu+1); i < this.sousMenus.length; i++) {
				lIndex = i;
				if (this.scroll) {
					lIndex = lIndex - this.positionScroll;
				}
				this.sousMenus[i].decaler(this.decalage, lIndex);
			}
			this.sousMenuActif = this.sousMenus[pIndexSousMenu];
			if (this.scroll) {
				this.decalageScroll = Math.ceil(lHeightSousMenus / 16 );
				if ((this.positionScroll + this.tailleScroll) <= (pIndexSousMenu + this.decalageScroll)) {
					this.positionScroll = this.decalageScroll + 1;
				}
				this.positionnerScroll();				
			}
		}
	}

	this.getSizeSousMenu = function() {
		return this.scroll ? this.tailleScroll : this.sousMenus.length;
	}
	
	this.activerScroll = function(pTailleScroll) {
		var _this = this;
		if (! this.scroll) {
			this.scroll = true;
			$('> div > ul',$(this.domElement)).css({float:'left'});
			this.conteneurScroll.mousewheel(function (event, delta) {
				delta > 0 ? _this.scrollUp() : _this.scrollDown();
			});
			this.conteneurScroll.append('<div class="conteneurScrollBar"><div class="scrollBar"></div></div>');
			this.scrollBar = $('> div.conteneurScrollBar > div.scrollBar',this.conteneurScroll);
			this.scrollListener = new scrollListener();
			var mouseStartPosition;
			var scrollBarStartPosition;
			var _dragElement;
			var listenerMouseUp = function() {
				document.onselectstart = null;
				_dragElement.ondragstart = null;
				$('html').unbind('mouseup',listenerMouseUp);
				$('html').unbind('mousemove',listenerMouseMove);
			};
			var listenerMouseMove = function(event) {
				var lNewTop = scrollBarStartPosition.top + getPos(event, 'Y') - mouseStartPosition;
				var lConteneurScrollBar = $('> div.conteneurScrollBar',_this.conteneurScroll);
				var lOffSetConteneur = lConteneurScrollBar.offset();
				if (lOffSetConteneur.top <= lNewTop && (_this.scrollBar.height() + lNewTop) <= (lOffSetConteneur.top + lConteneurScrollBar.height())) {
					_this.scrollBar.offset({top:lNewTop,left:scrollBarStartPosition.left});
					var pos = Math.round(((_this.sousMenus.length-_this.tailleScroll+_this.decalageScroll)*_this.scrollBar.position().top)/(lConteneurScrollBar.height()-_this.scrollBar.height()));
					_this.scrollTo(pos);
				}
			};
			this.scrollBar.mousedown(function(event) {
				mouseStartPosition = getPos(event, 'Y');
				scrollBarStartPosition = _this.scrollBar.offset();
				document.body.focus();
		        document.onselectstart = function () { return false; };
		        _dragElement = event.target != null ? event.target : event.srcElement;
		        _dragElement.ondragstart = function() { return false; };
				$('html').bind('mouseup',listenerMouseUp);
				$('html').bind('mousemove',listenerMouseMove);
				return false;
			});
		}
		this.tailleScroll = pTailleScroll;
		this.positionScroll = 0;
	}
	
	this.afficherScroll = function() {
		if (this.scroll) {
			var tailleConteneurScroll = 0;
			for (var i=this.positionScroll; i < this.tailleScroll; i++) {
				tailleConteneurScroll = tailleConteneurScroll + $( this.sousMenus[i].domElement).innerHeight();
			}
			$(this.conteneurScroll).height(tailleConteneurScroll);
			this.positionnerScroll();
		}
	}
	this.scrollUp = function() {
		if (this.positionScroll>0) {
			this.positionScroll--;
			this.positionnerScroll();
		}
	}
	this.scrollDown = function() {
		if (this.positionScroll < (this.sousMenus.length - this.tailleScroll + this.decalageScroll)) {
			this.positionScroll++;
			this.positionnerScroll();
		}
	}
	this.scrollTo = function(pIndex) {
		if (this.positionScroll == pIndex) {
			return;
		}
		if (pIndex < 0) {
			this.positionScroll = 0;
		} else if (pIndex > (this.sousMenus.length - this.tailleScroll + this.decalageScroll)) {
			this.positionScroll = this.sousMenus.length - this.tailleScroll + this.decalageScroll;
		} else {
			this.positionScroll = pIndex;
		}
		this.positionnerScroll(true);
	}
	this.positionnerScroll = function(pNoDisplayScrollBar) {
		var lMargin = 0;
		for (var i=0; i < this.positionScroll; i++) {
			lMargin = lMargin + $(this.sousMenus[i].domElement).innerHeight();
		}
		var lMargin = - lMargin;
		$('> ul ',this.conteneurScroll).css('marginTop',lMargin + 'px');
		for (var i=0; (i < this.tailleScroll) && (this.positionScroll + i <this.sousMenus.length); i++) {
			this.sousMenus[this.positionScroll + i].decaler(this.decalage, i);
		}
		if (pNoDisplayScrollBar) {
			return;
		}
		var lTailleTotal = this.sousMenus.length + this.decalageScroll;
		var lHeightScrollBar = (this.tailleScroll / lTailleTotal) * 100;
		this.scrollBar.height(lHeightScrollBar+'%');
		this.scrollBar.css('top',((100 - lHeightScrollBar)/(lTailleTotal - this.tailleScroll)*this.positionScroll)+'%');
	}
}

function MenuNiveau3(pIndex, pDomElement) {

	this.index = pIndex;
	this.domElement = pDomElement;
	this.sousMenus = new Array();

	var domSousMenus = $('> ul > li',$(this.domElement));
	var nbSousMenus = domSousMenus.size();
	for (var i=0;i<nbSousMenus;i++) {
		this.sousMenus[i] = domSousMenus[i];
	}

	this.decaler = function(pDecalage, pIndex) {
		var lChildrenLI = $(this.domElement).children();
		var lImageDecalage = $(lChildrenLI[0]);
		lImageDecalage.attr('width',  pDecalage + (ParametresAffichage.menuDroitDecalageFleche * pIndex));
	}

	this.ouvrir = function() {
		var lConteneurUL = $('> ul',$(this.domElement));
		lConteneurUL.show();
		$('> span > a',$(this.domElement)).addClass('on');
		$('> img',$(this.domElement))[1].src = ParametresAffichage.imageMenuDroitOuvert;
		return lConteneurUL.innerHeight();
	}
	
	this.fermer = function() {
		$('> ul',$(this.domElement)).hide();
		$('> span > a',$(this.domElement)).removeClass('on');
		var lImageFleche = $('> img',$(this.domElement))[1];
		if (lImageFleche != undefined &&  lImageFleche.src.indexOf(ParametresAffichage.imageMenuDroitTransparent) == -1) {
			lImageFleche.src = ParametresAffichage.imageMenuDroitFerme;
		}
	}
	
	this.getSizeSousMenu = function() {
		return this.sousMenus.length;
	}
	
}

function scrollListener() {

}

var AnimationCarre = {

	PETIT : 0,
	MOYEN : 1,
	GRAND : 2,
	
	tailleEnCours : 0,
	
	init : function() {
		var lDivsCanvas = $('canvas > div');
		if (lDivsCanvas && lDivsCanvas.size()>0) {
			var lTailleCanvas = ParametresAffichage.getTailleCanvas();
			lDivsCanvas.each(function (pIndex) {
				lDivsCanvas.css({width:lTailleCanvas[0],height:lTailleCanvas[1]});
			});
		}
		this.tailleEnCours = this.PETIT;
		var lPositionCarre = ParametresAffichage.getPositionPetitCarre();
		this.dessinerCarre(ParametresAffichage.getTaillePetitCarre(), lPositionCarre[0],lPositionCarre[1] ,ParametresAffichage.angleRotationCarre);
	},
	
	dessinerCarre : function (pTaille, pPositionX, pPositionY, pRotation) {
		var canvas = document.getElementById('canvas');
		var ctx = canvas.getContext("2d");
		ctx.save();
		var lTailleCanvas = ParametresAffichage.getTailleCanvas();
		ctx.clearRect(0,0,lTailleCanvas[0],lTailleCanvas[1]);
		ctx.rotate(pRotation);
		ctx.lineWidth = 1;  
		ctx.strokeStyle = ParametresAffichage.couleurCarre;
		ctx.strokeRect(pPositionX,pPositionY,pTaille,pTaille);
		ctx.restore();
	},
	
	animer : function(pTaille, pCallBack) {
		/* Si la taille demandée n'existe pas ou qu'elle est la même que la taille actuelle alors pas d'animation */
		if ((this.PETIT!=pTaille && this.MOYEN!=pTaille && this.GRAND!=pTaille) || (this.tailleEnCours == pTaille)) {
			if (pCallBack) {
				pCallBack();
			}
			return;
		}
		var _this = this;
		var tailleCarreDebut = 0;
		var positionDebut = [0,0];
		if (this.PETIT==this.tailleEnCours) {
			tailleCarreDebut = ParametresAffichage.getTaillePetitCarre();
			positionDebut = ParametresAffichage.getPositionPetitCarre();
		} else if (this.MOYEN==this.tailleEnCours) {
			tailleCarreDebut = ParametresAffichage.getTailleMoyenCarre();
			positionDebut = ParametresAffichage.getPositionMoyenCarre();
		} else if (this.GRAND==this.tailleEnCours) {
			tailleCarreDebut = ParametresAffichage.getTailleGrandCarre();
			positionDebut = ParametresAffichage.getPositionGrandCarre();
		}
		var tailleCarreFin = 0;
		var positionFin = [0,0];
		if (this.PETIT==pTaille) {
			tailleCarreFin = ParametresAffichage.getTaillePetitCarre();
			positionFin = ParametresAffichage.getPositionPetitCarre();
		} else if (this.MOYEN==pTaille) {
			tailleCarreFin = ParametresAffichage.getTailleMoyenCarre();
			positionFin = ParametresAffichage.getPositionMoyenCarre();
		} else if (this.GRAND==pTaille) {
			tailleCarreFin = ParametresAffichage.getTailleGrandCarre();
			positionFin = ParametresAffichage.getPositionGrandCarre();
		}
		loop(function(pPosition, pLast) {
			if (pPosition>1) {
				pPosition = 1;
			}
			if (pLast) {
				_this.tailleEnCours = pTaille;
				_this.dessinerCarre(tailleCarreFin, positionFin[0] ,positionFin[1] ,ParametresAffichage.angleRotationCarre);
				if (pCallBack) {
					pCallBack();
				}
			} else {
				var lTaille = ((tailleCarreFin - tailleCarreDebut)*pPosition) + tailleCarreDebut;
				var lPositionX = ((positionFin[0] - positionDebut[0])*pPosition) + positionDebut[0];
				var lPositionY = ((positionFin[1] - positionDebut[1])*pPosition) +positionDebut[1];
				_this.dessinerCarre(lTaille, lPositionX, lPositionY,ParametresAffichage.angleRotationCarre);
			}
		},ParametresAffichage.dureeAnimation);
	},
	
	actualiser : function() {
		var lPositionCarre;
		if (this.PETIT==this.tailleEnCours) {
			lPositionCarre = ParametresAffichage.getPositionPetitCarre();
			this.dessinerCarre(ParametresAffichage.getTaillePetitCarre(), lPositionCarre[0],lPositionCarre[1] ,ParametresAffichage.angleRotationCarre);
		} else if (this.MOYEN==this.tailleEnCours) {
			lPositionCarre = ParametresAffichage.getPositionMoyenCarre();
			this.dessinerCarre(ParametresAffichage.getTailleMoyenCarre(), lPositionCarre[0],lPositionCarre[1] ,ParametresAffichage.angleRotationCarre);
		} else if (this.GRAND==this.tailleEnCours) {
			lPositionCarre = ParametresAffichage.getPositionGrandCarre();
			this.dessinerCarre(ParametresAffichage.getTailleGrandCarre(), lPositionCarre[0],lPositionCarre[1] ,ParametresAffichage.angleRotationCarre);
		}
	}
	
}

var ListeActualites = {

	conteneur : null,
	actualites : new Array(),
	position : 0,
	isPlaying : false,
	filActu : null,

	init : function(pIdBlocActu, pClassBlocActu, pIdBoutonStartStop, pVitesse) {
			var _this = this;
			$('p.actualite').each(function(pIndex) {
				var element = $(this);
				_this.actualites[pIndex] = element.html();
				if (pIndex>0) {
					element.hide();
				}
			});
			_this.filActu = $('#'+pIdBlocActu).marquee(pClassBlocActu, pVitesse).mouseover(function () {
				if (_this.isPlaying) {
		  			$(this).trigger('pause');
		  		}
			}).mouseout(function () {
				if (_this.isPlaying) {
		  			$(this).trigger('unpause');
		  		}
			}).bind('stop', function(){
				_this.position++;
				if (_this.position >= _this.actualites.length) {
					_this.position = 0;
				}
				_this.conteneur.html(_this.actualites[_this.position]);
			});
			_this.conteneur = $($('> div',_this.filActu[0]));
			_this.isPlaying = true;
			var btnStartStop = $('#'+pIdBoutonStartStop);
			if (btnStartStop != undefined) {
				btnStartStop.click(function(){
					if (_this.isPlaying) {
						_this.isPlaying = false;
						_this.filActu.trigger('pause');
						btnStartStop.attr('src',ParametresAffichage.imageBouttonLecture);
					} else {
						_this.isPlaying = true;
						_this.filActu.trigger('unpause');
						btnStartStop.attr('src',ParametresAffichage.imageBouttonPause);
					}
				});
			}
	}
}

/*
	Appel d'une fonction "pFunction" en boucle pendant une durée "pDuree" (en millisecondes)
*/
function loop(pFunction, pDuree) {
	var lStartTimeStamp = new Date().getTime();
	var lEndTimeStamp = lStartTimeStamp + pDuree;
	var myInterval = window.setInterval(function () {
		var now = new Date().getTime();
		pFunction((now-lStartTimeStamp)/pDuree, false);
	},1);
	window.setTimeout(function(){
		clearInterval(myInterval);
		pFunction(1, true);
	},pDuree);
}

function getPos(event, c) {
	var p = c == 'X' ? 'Left' : 'Top';
	return event['page' + c] || (event['client' + c] + (document.documentElement['scroll' + p] || document.body['scroll' + p])) || 0;
};
