// Cufon.replace

Cufon.replace('h1, h2, h3, h5, code',{fontFamily:'regular',letterSpacing:'-1px'});

Cufon.replace('h4',{fontFamily:'light'});

Cufon.replace('.header-menu a',{fontFamily:'regular', hover:'#B72126'});
Cufon.replace('.menu-links li a',{fontFamily:'regular',hover:'true'});

Cufon.replace('.content-posts blockquote, .post-date',{fontFamily:'regular'});

Cufon.replace('.menu-publication',{fontFamily:'light', hover:'#B72126'});
Cufon.replace('.footer-name, .footer-location',{fontFamily:'light'});
Cufon.replace('.footer-name strong, .footer-location strong',{fontFamily:'regular'});
Cufon.replace('.accolade-grid-data-title',{fontFamily:'light'});

Cufon.replace('.agenda-mois .nom',{fontFamily:'regular'});
Cufon.replace('.agenda-mois .lieu',{fontFamily:'light'});

// Slider
function Slider(elem) {
	this.$elem=$(elem);
	this.$slides=$('.slide', this.$elem);
	this.current=0;
	this.animating = false;
	this.nbSlides=this.$slides.length;
	var numbers = '<span class="active">1</span>';
	for(var i=1;i<this.nbSlides;i++) numbers += '<span>'+(i+1)+'</span>';
	this.$elem.append('<div class="numbers">'+numbers+'</div>');
	this.timer = null;
	this.resetTimer();
	this.initEvents();
}

Slider.prototype.next=function() {return (this.current+1<this.nbSlides) ? this.current+1 : 0;}
Slider.prototype.currentSlide=function() {return $(this.$slides[this.current]);}
Slider.prototype.nextSlide=function() {return $(this.$slides[this.next()]);}
Slider.prototype.initEvents=function() {
	var slider = this;
	this.$elem.find('.numbers span').each(function(i){
		$(this).click(function() {
			slider.animate(i);
		});
	});
}
Slider.prototype.resetTimer = function() {
	var slider = this;
	if(this.timer !== null) window.clearInterval(this.timer);
	this.timer = window.setInterval(function() {slider.animate();},7000);
}

Slider.prototype.animate=function(next) {
	var $current=this.currentSlide();
	var next = (typeof next !== 'undefined') ? next : this.next();
	var $next = $(this.$slides[next]);
	if(this.animating == false && next != this.current) {
		var slider = this;
		this.animating = true;
		this.$slides.css('z-index',10);
		$current.css('z-index',20);
		$next.css('z-index',30);
		$next.find('.image').css('width',0).find('img').css('right',-120);
		$next.find('.legend').css('left',-930);
		$next.show();
		$next.find('.image').animate({width:930},600,'easeOutQuart')
		.find('img').animate({right: 0},600);
		$next.find('.legend').delay(300).animate({left:0},300)
		$current.find('.image img').animate({right:120},600, function() {slider.animating = false});
		$current.find('.legend').animate({left:-930},300,'easeOutQuart');
		this.$elem.find('.active').removeClass('active');
		this.$elem.find('.numbers span').eq(next).addClass('active');
		this.current=next;
		this.resetTimer();
	}
}

// ---O--- //
$(function() {

	$('#box-texto').submit(function() {
		var $loading = $(this).find('.loading');
		$loading.css('opacity', 0).show().fadeTo(500, 0.8);

		$.post('/texto.php', {nom: $('#box-texto-nom').val(), numero: $('#box-texto-numero').val()},
			function(data) {
				if(data == '1') $loading.html('Inscription réussie !');
				else $loading.html('Erreur informations');
				$loading.delay(2000).fadeOut(500);
			}
		);
		return false;
	});

});

