$(document).ready(function(){
//	alert($('body').attr('id'));
	/*if ($('input[@id=page_id]').attr('value')) {
		init($('input[@id=page_id]').attr('value'));	
	} else {
		init(document.getElementsByTagName('body')[0].id);
	}*/
	init($('body').attr('id'));
	
	$('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', '#000');
			$(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();
		})
	});
	
	/* limite la largeur des bloc de descriptif de docs à celle du document décrit */
	$('.spip_documents').each(function(){
		if ($(this).find('img').length == 1) {
			var width = $(this).find('img').width();
			$(this).find('dt').css('width', width);
			$(this).find('dd').css('width', width);
		}
	});
	
	/*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;
		}
	})*/
	
	
	/*  supprime les infos de largeur automatique dans les span spip_documents */
	$('span').each(function (idx){
		if ($(this).attr('class') != undefined && $(this).attr('class').match(/spip_documents/) != null) {
			$(this).css('width', 'auto');
			$(this).css('padding', '0px');
		}
	});
	//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'));
			}
		}
	}
}

function init(id_secteur){
	if (id_secteur='rubrique-12') {	// blog
		if ($('fieldset[@class=previsu]').length > 0){
			$('form fieldset:eq(1)').css('display', 'none');
			$('form fieldset:eq(2)').css('display', 'none');
			$('form fieldset:eq(3)').css('display', 'none');
			$('p[@class=spip_bouton]:eq(1)').css('display', 'none');
			$('form fieldset[@class=previsu] p[@class=spip_bouton] input').attr('style', 'color:#F00; border: 2px solid #F00;');
		}
	}
	
	if ($('.previsu').length == 0){
		$('.billet_repondre .formulaire-forum').hide();
	}
	
	$(".bouton-slide").click(function(){
		$(".formulaire-forum").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});
}

