// Gestion des tailles des images de la une
function setTailleImagesUne() {

	// Image de l'article principal
	if(document.getElementById("photo_principal")) {
		var img = document.getElementById("photo_principal");
		// Application rapport de réduction
		if(img.width > 260 || img.height > 260) {
			ratio = calculeRatio(260,img.width,img.height);
			rw = img.width * ratio;
			rh = img.height * ratio;
			img.width = rw;
			img.height = rh;
		}
	}
	
	// Images des autres articles
	var docImages = document.images;
	for(var i=0; i<docImages.length; i++) {
		if(document.getElementById("photo_"+i)) {
			var img = document.getElementById("photo_"+i)
			// Application rapport de réduction
			if(img.width > 145 || img.height > 145) {
				ratio = calculeRatio(145,img.width,img.height);
				rw = img.width * ratio;
				rh = img.height * ratio;
				img.width = rw;
				img.height = rh;
			}
		}
	}
}
// Gestion des tailles des images de la newsletter
function setTailleImagesNewsletter() {

	// Image de l'article principal
	if(document.getElementById("photo_principal")) {
		var img = document.getElementById("photo_principal");
		// Application rapport de réduction
		if(img.width > 100 || img.height > 100) {
			ratio = calculeRatio(100,img.width,img.height);
			rw = img.width * ratio;
			rh = img.height * ratio;
			img.width = rw;
			img.height = rh;
		}
	}
	
	// Images des autres articles
	var docImages = document.images;
	for(var i=0; i<docImages.length; i++) {
		if(document.getElementById("photo_"+i)) {
			var img = document.getElementById("photo_"+i)
			// Application rapport de réduction
			if(img.width > 100 || img.height > 100) {
				ratio = calculeRatio(100,img.width,img.height);
				rw = img.width * ratio;
				rh = img.height * ratio;
				img.width = rw;
				img.height = rh;
			}
		}
	}
}
// Calcule un rapport de réduction
function calculeRatio(tmax,w,h) {
	test_h = tmax / h;
	test_w = tmax / w;
	if(test_h>test_w) ratio = test_w;
	else ratio = test_h;
	return ratio;
}

// Gestion bordure médias du jour
var bordure_affichee = false;
function affiche_bordure(media,from) {
	if(bordure_affichee == false) {
		var bordure = document.getElementById(media);
		
		if(media == 'photo_jour') {
			bordure.style.top = '199px';
		}
		else if(media == 'video_jour') {
			if(navigator.userAgent.indexOf("MSIE 6") != -1)
				bordure.style.top = '368px';
			else
				bordure.style.top = '365px';
		}
		else if(media == 'diapo_jour') {
			if(navigator.userAgent.indexOf("MSIE 6") != -1)
				bordure.style.top = '531px';
			else
				bordure.style.top = '525px';
		}
		
		if(media == 'video_jour' || media == 'diapo_jour') {
			if(navigator.userAgent.indexOf("MSIE 6") != -1) {
				bordure.style.width = '160px';
				bordure.style.height = '120px';
			}
			else {
				bordure.style.width = '144px';
				bordure.style.height = '104px';
			}
			if(document.body.clientWidth > 987)
				bordure.style.left = ((document.body.clientWidth - 987) / 2 + 4)+'px';
			else
				bordure.style.left = '4px';
			
		}
		else if(media == 'photo_jour') {
			if(navigator.userAgent.indexOf("MSIE 6") != -1) {
				bordure.style.width = '127px';
				bordure.style.height = '126px';
			}
			else {
				bordure.style.width = '111px';
				bordure.style.height = '110px';
			}
			if(document.body.clientWidth > 987)
				bordure.style.left = ((document.body.clientWidth - 987) / 2 + 36)+'px';
			else
				bordure.style.left = '36px';
		}
		
		bordure.style.display = 'block';
		bordure_affichee = true;
	}
}
function masque_bordure(media) {
	var bordure = document.getElementById(media);
	bordure.style.display = 'none';
	bordure_affichee = false;
}

// Gestion des menus dynamiques du bandeau
function montre(id) {
	var d = document.getElementById(id);
	if (document.getElementById('depuis')) {document.getElementById('depuis').style.display='none';}
	if (document.getElementById('annonce')) {document.getElementById('annonce').style.display='none';}
	
	/*if(document.body.clientWidth > 987) {
		//if(navigator.userAgent.indexOf("MSIE 6") != -1)
			document.getElementById("annonce").style.left = ((document.body.clientWidth - 987) / 2)+'px';
		//else
			//document.getElementById("annonce").style.left = ((document.body.clientWidth - 987) / 2 - 6)+'px';
	}
	else 
		document.getElementById("annonce").style.left = '0px';*/
	
	if (d) {d.style.display='block';}
}

// Gestion des calques "édito"
function affiche_edito(div_edito) {
	var edito = document.getElementById(div_edito);
	if(edito) 
		edito.style.display='block';
		
	edito.style.marginLeft = '0px';		
	edito.style.marginTop = '0px';
	
	var group;
	var coordinates = ToolMan.coordinates();
	var drag = ToolMan.drag();
	
	var boxDrag = edito;
	drag.createSimpleGroup(boxDrag);
	
	if(document.body.clientWidth > 987)
		edito.style.marginLeft = ((document.body.clientWidth - 987) / 2 + 155)+'px';
	else 
		edito.style.marginLeft = '155px';
		
	edito.style.marginTop = '158px';
}
function ferme_edito(edito) {
	var edito = document.getElementById(edito);
	if(edito) 
		edito.style.display='none';
}

// Gestion des calques "breves"
function affiche_breve(div_breve,from) {
	var breve = document.getElementById(div_breve);
	if(breve) 
		breve.style.display='block';
	
	breve.style.marginLeft = '0px';		
	breve.style.marginTop = '0px';
	
	var group;
	var coordinates = ToolMan.coordinates();
	var drag = ToolMan.drag();
	
	var boxDrag = breve;
	group = drag.createSimpleGroup(boxDrag);
	
	if(document.body.clientWidth > 987) {
		if(from == 'rub')
			breve.style.marginLeft = ((document.body.clientWidth - 987) / 2 + 630)+'px';
		else
			breve.style.marginLeft = ((document.body.clientWidth - 987) / 2 + 540)+'px';
	}
	else {
		if(from == 'rub')
			breve.style.marginLeft = '630px';
		else
			breve.style.marginLeft = '540px';
	}
	
	if(from == 'rub')
		breve.style.marginTop = '158px';
	else
		breve.style.marginTop = '358px';
}
function ferme_breve(id_breve) {
	var breve = document.getElementById(id_breve);
	if(breve) 
		breve.style.display='none';
}

// Gestion agrandissement/réduction texte
function setTailleTexte(lien,texte,num) {
	if(lien == 'lien_agrandir') {
		document.getElementById(texte).style.fontSize='14px';
		document.getElementById('lien_agrandir_'+num).style.display='none';
		document.getElementById('lien_reduire_'+num).style.display='block';
	}
	else {
		document.getElementById(texte).style.fontSize='12px';
		document.getElementById('lien_reduire_'+num).style.display='none';
		document.getElementById('lien_agrandir_'+num).style.display='block';
	}
}

// Gestion agrandissement/réduction image
function setTailleImage(lien,image) {
	if(lien == 'lien_agrandir') {
		document.getElementById('photo_jour_reduite').style.display='none';
		document.getElementById('photo_jour_normale').style.display='block';
		document.getElementById('lien_agrandir').style.display='none';
		document.getElementById('lien_reduire').style.display='block';
	}
	else {
		document.getElementById('photo_jour_normale').style.display='none';
		document.getElementById('photo_jour_reduite').style.display='block';
		document.getElementById('lien_reduire').style.display='none';
		document.getElementById('lien_agrandir').style.display='block';
	}
}

// Gestion marge encart pub (pour IE6)
function ajusteMargePub(id) {
	if(navigator.userAgent.indexOf("MSIE 6") != -1) {
		document.getElementById(id).style.marginLeft = '12px';
	}
}
// Gestion du deploiement des articles "autres photos/videos/diapos"
function gere_deploiement(id,url) {
	list_articles = document.getElementById('rub_'+id);
	ul = document.getElementById('ul_'+id);
	if(list_articles.style.display=='none' || list_articles.style.display=='') {
		list_articles.style.display='block';
		ul.style.backgroundImage='url('+url+'/squelettes/img/deplierbas.gif)';
	}
	else {
		list_articles.style.display='none';
		ul.style.backgroundImage='url('+url+'/squelettes/img/deplierhaut.gif)';
	}
}
