/*function ajuste_taille(){
	var max_width = 730;
	if (document.body.clientWidth > max_width) {
		document.getElementById('conteneur').style.width = max_width + 'px';
	} else {
		document.getElementById('conteneur').style.width = (document.body.clientWidth -30) + 'px';
	}
	document.getElementById('conteneur').style.display = 'block';
}*/
var DEBUG = false;


$(document).ready(function(){
	/*if ($('input[@id=page_id]').attr('value')) {
		init($('input[@id=page_id]').attr('value'));	
	} else {
		init(document.getElementsByTagName('body')[0].id);
	}*/
	
	
	/* corrections apparence */
	if ($.browser.msie) {
		$('#bandeau-actus').css('margin-bottom', '-30px');
	}
	
	/* sup le menu gauche si pas d'items */
	if ($('#menu-rubrique ul').length == 0){
		$('#menu-rubrique').hide();
	}

	/* redimensionne le menu gauche en fonction du contenu */
	var id_menu_gauche = ($('#menu-rubrique').length > 0 ? 'menu-rubrique' : ($('#bandeau-actus').length > 0 ? 'bandeau-actus' : ''));
	if (id_menu_gauche != '' && $('#' + id_menu_gauche).length > 0) {
		h_contenu_page = $('#contenu-page').height();
		if ($('#' + id_menu_gauche).height() - $('#contenu-page').height() != 15) {
			$('#' + id_menu_gauche).css('height', ($('#contenu-page').height() + 15) + 'px');
		}
	}
	
	
	
	
	
	if (DEBUG) {
		var selected_element = '';
		var elements = new Array('div', 'span', 'ul', 'li');
		$('body:eq(0)').prepend('<div id="css-bar"></div>');
		for (i = 0; i < elements.length; i++) {
			$('body #css-bar').append('<a href="javascript:void(0)">' + elements[i] + '</a> ');
		}
		
		$('body #css-bar a').each(function (idx) {
			$(this).bind('click', function (){
				if (selected_element != '') {
					$(selected_element).each(function (idx){
						var pos = $(this).css('position');
						$(this).css('border', 'none');
						$(this).find('span.el-props').remove();
					});
				}
				
				selected_element = $(this).html();
				$(selected_element).each(function (idx){
					$(this).css('border', '1px solid #F00');
					var pos = $(this).css('position');
					if (pos == 'static' || pos == 'relative') {
						var str_id = '';
						if ($(this).attr('id') != undefined) { str_id += 'id:' + $(this).attr('id'); }
						if ($(this).attr('class') != undefined) { str_id += ' class:' + $(this).attr('class'); }
						if (str_id != '') {
							$(this).prepend('<span class="el-props" style="position:absolute;top:0px;left:0px;z-index:1;background-color:#FFF;font-size:8px">' + str_id + '</span>');
						}
					}
				});
			});
		});
		
		
		
	}
	
	$('a').bind('focus', function(){
		this.blur();
	});
	
	/*$('#navigation-principale ul li a').bind('mouseover', function (){
		if ($(this.parentNode).attr('class') == 'en-cours') {
			return;
		}
		
		$('#navigation-principale ul li').each(function (){
			if ($(this).find('a').length == 2) {
				$(this).find('a:eq(1)').hide();
			}
		});
		
		if ($(this.parentNode).find('a').length == 1) {
			lien_hover = $(this).clone();
			$(lien_hover).hide();
			$(lien_hover).css('background-color', '#25578A');
			$(lien_hover).css('color', '#FFF');
			$(lien_hover).css('position', 'absolute');
			$(lien_hover).css('top', '0px');
			$(lien_hover).css('left', '0px');
			$(this.parentNode).append(lien_hover);
		}
		
		$(this.parentNode).find ('a:eq(1)').fadeIn(1000);
		$(this.parentNode).find ('a:eq(1)').bind('mouseout', function (){
			$(this).fadeOut();
		})
	});*/
	
	
	arr_defs = document.getElementsByTagName('dfn');
	arr_acrs = document.getElementsByTagName('acronym');
	insere_infobulles(arr_defs);
	insere_infobulles(arr_acrs);
	
	$('#menu-rubrique li a').bind('click', function (){
		if ($(this.parentNode).find('ul').length > 0) {
			/* masque toutes les sous rubriques */
			
			$('#menu-rubrique li ul').hide();
			$(this.parentNode).find('ul').fadeIn(1000);
			return false;
		}
	})
	
	/* fade in sur les images */
	/*if ($('#contenu-article').length) {
		$('#contenu-article img').hide();
		$('#contenu-article img').fadeIn(3000);
	}*/
});


function insere_infobulles(html_elements){
	nb = typeof(html_elements) == 'object' ? html_elements.length : 0;
	for (i = 0; i < nb; i++) {
		if (html_elements[i].getAttribute('title')) {
			
			html_elements[i].insertBefore(document.createElement('span'), html_elements[i].firstChild);
			html_elements[i].firstChild.setAttribute('className', 'cartouche-def');
			html_elements[i].firstChild.setAttribute('class', 'cartouche-def');

			html_elements[i].firstChild.appendChild(document.createElement('span'));
			html_elements[i].firstChild.appendChild(document.createElement('span'));
			
			html_elements[i].firstChild.getElementsByTagName('span')[0].setAttribute('className', 'cartouche-def-haut');
			html_elements[i].firstChild.getElementsByTagName('span')[0].setAttribute('class', 'cartouche-def-haut');
			html_elements[i].firstChild.getElementsByTagName('span')[1].setAttribute('className', 'cartouche-def-int');
			html_elements[i].firstChild.getElementsByTagName('span')[1].setAttribute('class', 'cartouche-def-int');
			html_elements[i].firstChild.getElementsByTagName('span')[1].appendChild(document.createTextNode(html_elements[i].getAttribute('title')));
			html_elements[i].setAttribute('title', '');
			
			html_elements[i].onmouseover = function () {
				this.firstChild.style.display = 'block';
				//alert(this.nodeName + this.getAttribute('title') + this.firstChild.nodeName);
			}
			
			html_elements[i].onmouseout = function () {
				this.firstChild.style.display = 'none';
				//alert(this.getAttribute('title'));
			}
		}
	}
}

