var gloss_el = null;
var gloss_dt = null;
var gloss_dd = null;

if (window.jQuery) jQuery(document).ready(function() {
    jQuery('body').append('<div id="glossOverDiv" style="position:absolute; display:none; visibility: hidden;"><div class="glossOverDiv_int"><div class="padder" id="gl_dd"><span class="gl_dd" >dolor sit amet, consectetuer adipisci elit. Nec vacuitate molestias interiret.. conficiuntque, iudicare suspicor sed sint tamen diceret.</span></div><!--/padder--></div><!--/glossOverDiv_int--><div class="bottom"></div></div><!--/glossOverDiv-->');
	jQuery('a.info_bulle').hover( function(e) {
		sauvtitle=this.title;
		gloss_dd.innerHTML = sauvtitle; // definition
		this.title="";
		reg = jQuery(this).css('font-size').match(/^\d\d?(?:\.\d+)?px/);
		if(reg) gloss_el.style.fontSize = reg[0];
		jQuery(gloss_el)
			.css('top',(e.pageY.toString()-($(gloss_el).height()+5))+"px")
			.css('left', (e.pageX.toString()-65)+"px")
			.css('font-family', jQuery(this).css('font-family'));
		
		gloss_el.style.display    = 'block';
		gloss_el.style.visibility = 'visible';
		
	}, function(e) {
			gloss_el.style.display    = 'none';
			gloss_el.style.visibility = 'hidden';
			this.title=sauvtitle;
		}
	);
	gloss_el = document.getElementById('glossOverDiv');
	gloss_dd = document.getElementById('gl_dd');
	
});

$.fn.image = function(src, alt, f){
  return this.each(function(){
    $("<img />").appendTo(this).each(function(){
            this.src = src;
            this.alt = alt;
            this.onload = f;
    });
  });
}

/* jquery.news-slider.js */
jQuery.fn.slideNews = function(settings) {
	settings = jQuery.extend({
		headline: "Top Stories",
		newsWidth: 250,
		newsHeight: 55,
		newsSpeed: "normal",
		nbItem: 4,
		scrollType: "horizontal"
	}, settings);
	return this.each(function(i){
		jQuery(".messaging",this).css("display","none");

		jQuery(".block_diaporama_link",this).css("overflow","hidden");
		jQuery(".block_diaporama_link_int",this).css("overflow","hidden");
		jQuery(".block_diaporama_link_int",this).css("position","relative");
		jQuery(".container",this).css("left","0px");
		jQuery(".container",this).css("top","0px");
		jQuery(".container",this).css("position","relative");

		itemLength = jQuery(".item",this).length;

		if (settings.scrollType=='horizontal')
		{
			newsContainerSize = itemLength * settings.newsWidth;
			jQuery(".container",this).css("width",newsContainerSize + "px");
			jQuery(".block_diaporama_link",this).css("width",settings.newsWidth * settings.nbItem + "px");
		}
		else
		{
			newsContainerSize = itemLength * settings.newsHeight;
			jQuery(".container",this).css("height",newsContainerSize + "px");
			jQuery(".block_diaporama_link",this).css("height",settings.newsHeight * settings.nbItem + "px");
		}

		animating = false;
		jQuery(".next",this).click(function() {
			thisParent = jQuery(this).parent().parent();
			if (animating == false) {
				animating = true;
				if (settings.scrollType=='horizontal') {
					animate = parseInt(jQuery(".container",thisParent).css("left")) - (settings.newsWidth * settings.nbItem);
					if (animate + parseInt(jQuery(".container",thisParent).css("width")) > 0) {
						jQuery(".container",thisParent).animate({left: animate}, settings.newsSpeed, function() {
							jQuery(this).css("left",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				} else {
					animate = parseInt(jQuery(".container",thisParent).css("top")) - (settings.newsHeight * settings.nbItem);
					if (animate + parseInt(jQuery(".container",thisParent).css("height")) > 0) {
						jQuery(".container",thisParent).animate({top: animate}, settings.newsSpeed, function() {
							jQuery(this).css("top",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				}

			}

			return false;
		});
		jQuery(".prev",this).click(function() {
			thisParent = jQuery(this).parent().parent();
			if (animating == false) {
				animating = true;
				if (settings.scrollType=='horizontal') {
					animate = parseInt(jQuery(".container",thisParent).css("left")) + (settings.newsWidth * settings.nbItem);
					if ((animate + parseInt(jQuery(".container",thisParent).css("width"))) <= parseInt(jQuery(".container",thisParent).css("width"))) {
						jQuery(".container",thisParent).animate({left: animate}, settings.newsSpeed, function() {
							jQuery(this).css("left",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				} else {
					animate = parseInt(jQuery(".container",thisParent).css("top")) + (settings.newsHeight * settings.nbItem);
					if ((animate + parseInt(jQuery(".container",thisParent).css("height"))) <= parseInt(jQuery(".container",thisParent).css("height"))) {
						jQuery(".container",thisParent).animate({top: animate}, settings.newsSpeed, function() {
							jQuery(this).css("top",animate);
							animating = false;
						});
					} else {
						animating = false;
					}
				}
			}

			return false;
		});
	});
};




$(document).ready(function()
{
	 $('.gallery a').lightBox();

	
/*	diapo_link='spip.php?article167';
	//diapo_link='squelettes/modeles/diaporama.html';
	$.get(diapo_link,
        	function (c) {
          		$(".home .block_diaporama")
          		//.html(c.replace(/</mg,'&lt;'))
          		.html(c)
        		}
      	);*/
      	//$(".home .block_diaporama").load(diapo_link);
      	
      	//$(".home .block_diaporama").appendTo(diapo_link);
	
	// liens d'evitement
	$("div.skip_link").addClass('accessibilite_off');
	$("div.skip_link a").focus(function(){
		$(this).parents("div.skip_link").removeClass('accessibilite_off');
	});
	$("div.skip_link a").blur(function(){
		$(this).parents("div.skip_link").addClass('accessibilite_off');
	});

	var options = {
		//newsWidth: 150,
		newsWidth: 366,
		newsHeight: 244,
		newsSpeed: "normal",
		nbItem: 1
	}
	$(".page_article .block_diaporama_link").slideNews(options);
	
	var options2 = {
		//newsWidth: 150,
		newsWidth: 586,
		newsHeight: 325,
		newsSpeed: "normal",
		nbItem: 1
	}
	$(".home .block_diaporama_link").slideNews(options2);
	
	
	/*popin
	$("a.open_popin").popin({
		loaderImg : 'mime/gif/ajax-loader.gif',
		opacity: .6
	});*/
	

	/*liens externes*/
	$("a.spip_out").image(
		"/mime/gif/ico_external_link.gif",
		"Lien externe, ouverture dans une nouvelle fenètre",
		function(){
		    
		}
	);
	
	
	
	$("a.spip_out").click(function(){
		window.open(this.href,'newwin','menubar=yes,resizable=yes,fullscreen=yes,scrollbars=yes,toolbar=yes,titlebar=yes,location=yes');
		return false;
	});
	var new_url = location.href;
	if(new_url == 'http://www.banditsnogent.com/Le-calendrier#R3'){
		$("div.block_championnat.R2").addClass('hide');
		document.title='Championnat R3 - ' + document.title;
		$("div.nav_champ a").removeClass('on');
		$("div.nav_champ a.hide_h2").addClass('on');
	}
	if(new_url == 'http://www.banditsnogent.com/Le-calendrier#R2'){
		$("div.block_championnat.R3").addClass('hide');
		document.title='Championnat R2 - ' + document.title;
		$("div.nav_champ a").removeClass('on');
		$("div.nav_champ a.hide_h3").addClass('on');
	}
	$("div.nav_champ a").click(function(){
		if($(this).attr('class')=='hide_h3'){
			$("div.block_championnat").removeClass('hide');
			$("div.block_championnat.R3").addClass('hide');
			location.assign(new_url + '#R2');
			document.title='Championnat R2 - ' + document.title;
			$("div.nav_champ a").removeClass('on');
			$("div.nav_champ a.hide_h3").addClass('on');
		}
		else if($(this).attr('class')=='hide_h2'){
			$("div.block_championnat").removeClass('hide');
			$("div.block_championnat.R2").addClass('hide');
			location.assign(new_url + '#R3');
			document.title='Championnat R3 - ' + document.title;
			$("div.nav_champ a").removeClass('on');
			$("div.nav_champ a.hide_h2").addClass('on');
		}
		else{
			$("div.block_championnat").removeClass('hide');
			location.assign(new_url + '#');
			$("div.nav_champ a").removeClass('on');
			$("div.nav_champ a.affiche_tout").addClass('on');
			
			
			
		}
		return false;
	});
	// Menu principal
	//activation souris
	$("div.nav_main>ul>li").hover(function() {
		// On ferme les autres
		$('div.nav_main>ul>li').removeClass('on');
		$(this).addClass('on');
	}, function() {
		$(this).removeClass('on');
		
	});
	//activation clavier
	$("div.nav_main>ul>li>a").focus(function() {
		$('div.nav_main>ul>li').removeClass('on');
		$(this).parent().addClass('on');
	});

	
	$('a[href^="mailto"], span.wmail').not('.exclu').each(function (i) {
		//Remplacment du texte dans l'élément
		var temp = $(this).html();
		temp = temp.replace('[chez]','@');
		temp = temp.replace('[point]','.');
		$(this).html(temp);
		//Si il y a un attribut "href", on remplace le texte dans l'attribut
		if($(this).attr('href')){
			var temphref = $(this).attr('href');
			temphref = temphref.replace('[chez]','@');
			temphref = temphref.replace('[point]','.');
			$(this).attr('href',temphref);
		}
	});
	


});


