$(document).ready(function() {

	jQuery('#carousel').jcarousel({
		scroll: 1, auto: 2, animation: "slow", wrap: "both", initCallback: mycarousel_initCallback
	});

	$("#contenu .resume div").hide();
	$("#contenu a.voirplus").click(function(event){
		event.preventDefault();
		$(this).next().slideToggle();
		$(this).toggleClass('on');
	});

	$("#calendrier h5").each(function(i) {
		$(this).next().hide();
		$(this).next().addClass("infos_bulle");
		$(this).mouseover(function(event){
			$(this).next().show();
		});
		$(this).mouseout(function(event){
			$(this).next().hide();
		});
	});

	$("#contenu .actu li.col_g").each(function(i) {
		if( $(this).height() > $(this).next().height() ) $(this).next().height($(this).height());
		else $(this).height($(this).next().height());
	});
	
	$('span.spancrypt').after('<span>&#6'+'4;</span>');
    $('span.spancrypt').remove();
	if( $('.antispam').length ) {
		$('.antispam').each(function(i) {
			$(this).html('<a href="mailto:'+$(this).html().replace(/<\/?[^>]+>/gi, '')+'">'+$(this).html()+'</a>' );
		});
	}

	/*function detruireCible() {
	  $(this).remove();
	  isVide();
	}
	function isVide() {
	  if($('.listes_ref li:visible').length )  $('.listes_ref li.vide').hide();
	  else $('.listes_ref li.vide').slideDown('fast');
	}
	function ajouterCours(e) {
		if ( $('#cours').val() != '' )
			$('#cours').val( $('#cours').val()+','+e.val() ) ;
		else 
			$('#cours').val( e.val() ) ;
	}
	function enleverCours(id) {
		var chaine = $('#cours').val();
		var reg=new RegExp("[,]+", "g");
		var valeurs = chaine.split(reg);
		var concat = '';
		for(i=0;i < valeurs.length;i++) {
			if(valeurs[i] != id && valeurs[i]!= '' && valeurs[i]) concat += valeurs[i]+',';
		}
		concat = concat.substring(0,concat.length-1)
		$('#cours').val(concat);
	}
	function supprClick(event) {
		enleverCours($(this).attr('rel'));
		event.preventDefault();
		$(this).parent().slideUp('fast',detruireCible);
	}

	if( $('#formulaire_auteur').length ) {
		$('.listes_ref li').show();
		if( !$('.listes_ref li:last').hasClass('vide') ) $('.listes_ref li.vide').hide();
		$('.listes_ref a.supprimer').click(supprClick);
		$('select.cours_ref').change(function(event){
			if( $(this).val() != '' ) {
				ajouterCours($(this));
				texte = $(this).find(':selected').text();
				$('.listes_ref')
					.append('<li>'+texte+'<a href="" class="supprimer" rel="'+$(this).val()+'">Supprimer</a></li>')
					.find('li:last').css('fontWeight', 'bold').hide().slideDown('fast')
					.find('a').click(supprClick);
				isVide();
			}
		});
		$('#cours_ajout_submit').click(function(event){
			event.preventDefault();
			if( $('#cours_ajout_nom').val() != '' && $('#cours_ajout_nom').val() != 'Intitulé du cours' ) {

			}
		});
	}*/

	if( $('#formulaire_documents').length ) {
		$('.listes_ref a.supprimer').click(function(event){
			event.preventDefault();
			$('#auteur_document_confirm').val('suppression');
			$('#auteur_document_suppr').val($(this).attr('rel'));
			$('#formulaire_documents_form').submit();
		});
	}

	if( $('#pageperso_form').length ) {
		$('.listes_ref a.supprimer').click(function(event){
			event.preventDefault();
			var texteDyn = $(this).prev().html();
			if( confirm('Voulez-vous vraiment supprimer ' + texteDyn + ' ?') ) {
				$('#pageperso_action').val('supprimer');
				$('#pageperso_suppr').val($(this).attr('rel'));
				$('#pageperso_form').submit();
			}
		});
	}

	if( $('#semframe').length ) {
		alert($('#semframe').find('.orange').html());
		$('#seminaire').html($('#semframe').find('.orange').html());
	}

	//hauteur encart sur toute la hauteur de la nav gauche :
	if( $('#encart_g').length ) {
		$('#encart_g').height( $('#pied').offset().top - $('#encart_g').offset().top - 20  );
	}
	
});

function lancerlien(a,b){ return 'ma'+'ilto'+':'+a+'@'+b; }

function eregi( chaine, find ) {
	var norm = new RegExp( find );
	return norm.exec( chaine )!=null;
}

function affichage_onglets() {
	$("#contenu h2.masque").addClass("invisible");
	$("#onglets li a").each(function(i){
		$(this).addClass("js_spec");
		if($(this).hasClass("on")) $(this).addClass("js_on");
		if(!($(this).hasClass("on"))) $('#bloc_'+this.id).hide();
		$(this).click(function(event){
			event.preventDefault();
			$("#onglets li a").each(function(i){
				$('#bloc_'+this.id).hide();
				$(this).removeClass("js_on");
			});
			$('#bloc_'+this.id).show();
			$(this).addClass("js_on");
		});
	});
}

function masquage_onglets() {
	$("#contenu h2.masque").addClass("invisible");
	$("#onglet1").addClass("invisible");
	$("#onglet1").removeClass("on");
	$("#onglet1").parent().hide();
	$("#onglet2").addClass("on");
	$("#onglet2").addClass("js_on");
	$("#bloc_onglet1").addClass("invisible");
}


function mycarousel_initCallback(carousel) {
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};