jQuery(document).ready(function(){
/*
var btnbilletblog = document.getElementById('btnbilletblog');
if(btnbilletblog) {
	var footer = document.getElementById('footer');
	if(footer) {
		var divFooter = footer.getElementsByTagName('div');
		if(divFooter.length > 0) {
			divFooter[0].appendChild(btnbilletblog);
		}
	}
}
*/
	DD_roundies.addRule('.post', '6px', true);
	DD_roundies.addRule('#footer', '6px 6px 0 0', true);
	DD_roundies.addRule('.cadre_commentaires', '6px', true);
	DD_roundies.addRule('.commentaires-cont', '6px', true);
	DD_roundies.addRule('#sidebar .module', '6px', true);
	DD_roundies.addRule('.wp-caption-text', '0 6px 6px 0' , true);
	DD_roundies.addRule('.button', '3px', true);
	DD_roundies.addRule('.header-bas2 .recherche .submit', '3px', true);
	DD_roundies.addRule('.commentaires-cont #submit', '3px', true);
	DD_roundies.addRule('#sidebar .module', '6px', true);
	DD_roundies.addRule('#contenu #contentarea .author', '6px', true);
	DD_roundies.addRule('#contenu #contentarea .btnok', '3px', true);
	DD_roundies.addRule('#footer .module .btnbilletblog a', '3px', true);
	
	//$('.wp-caption-text').css("opacity","0.6");
	$('.logo').css("opacity","0.9");
	$('.header-bas li a').css("opacity","0.8").textShadow();
	

	$("#footer .module:nth-child(1)").addClass('first');


$("span.date:contains('January')").each(function(){
        $(this).text($(this).text().replace(/January/, "Janvier"));
});
$("span.date:contains('February')").each(function(){
        $(this).text($(this).text().replace(/February/, "Février"));
});
$("span.date:contains('March')").each(function(){
        $(this).text($(this).text().replace(/March/, "Mars"));
});
$("span.date:contains('April')").each(function(){
        $(this).text($(this).text().replace(/April/, "Avril"));
});
$("span.date:contains('June')").each(function(){
        $(this).text($(this).text().replace(/June/, "Juin"));
});
$("span.date:contains('July')").each(function(){
        $(this).text($(this).text().replace(/July/, "Juillet"));
});
$("span.date:contains('August')").each(function(){
        $(this).text($(this).text().replace(/August/, "Aout"));
});
$("span.date:contains('September')").each(function(){
        $(this).text($(this).text().replace(/September/, "Septembre"));
});
$("span.date:contains('October')").each(function(){
        $(this).text($(this).text().replace(/October/, "Octobre"));
});
$("span.date:contains('November')").each(function(){
        $(this).text($(this).text().replace(/November/, "Novembre"));
});
$("span.date:contains('December')").each(function(){
        $(this).text($(this).text().replace(/December/, "Décembre"));
});
$("a.more-link").each(function(){
	$(this).parents("p").css("marginBottom", "0px");
	//$(this).parents("p").css("paddingBottom", "15px");
});
$("#prev a").click(function(e) {
	this.href = this.href + "?st=" + (document.body.scrollTop || document.documentElement.scrollTop || 0);
});
$("#next a").click(function(e) {
	this.href = this.href + "?st=" + (document.body.scrollTop || document.documentElement.scrollTop || 0);
});
if($("#twitterBouton").length > 0 && $("ul.twitter").length > 0) {
	$("#twitterBouton").insertBefore($("ul.twitter"));
}

if(st != '') {
	document.documentElement.scrollTop = st;
}

var wpCal = document.getElementById('wp-calendar');
if(wpCal) {
	//<span style="display:block; text-align:right; padding-right: 10px"><a href="/liste-des-billets-du-blog">Tous les articles du blog<a></span>
	var spanTous = document.createElement('span'), aTous = document.createElement('a');
	spanTous.id = 'tousCal';
	aTous.href = '/liste-des-billets-du-blog';
	aTous.innerHTML = 'Tous les articles du blog';
	spanTous.appendChild(aTous);
	wpCal.parentNode.appendChild(spanTous);
	
	var nodeTitle = wpCal.getElementsByTagName('caption')[0];
	var linkMois = document.createElement('a');
	var titleSplit = nodeTitle.innerHTML.split(' ');
	
	linkMois.href = location.protocol + '//' + location.hostname + '/date/' + titleSplit[1] + '/';
	var m = getNumMonth(titleSplit[0]);
	if(m < 10) linkMois.href = linkMois.href + '0';
	linkMois.href = linkMois.href + m;
	
	linkMois.innerHTML = nodeTitle.innerHTML;
	nodeTitle.innerHTML = '';
	nodeTitle.appendChild(linkMois);
}
});

function getNumMonth(txt) {
	txt = txt.toLowerCase().replace(/[éè]/, 'e').replace('ô', 'o').replace('û', 'u').replace('.', '');
	
	var m = 1;
	switch(txt) {
		case 'janvier':
		case 'janv':
		case 'jan':
			 m = 1;
			 break;
		case 'fevrier':
		case 'fevr':
		case 'fev':
			 m = 2;
			 break;
		case 'mars':
		case 'mar':
			 m = 3;
			 break;
		case 'avril':
		case 'avr':
			 m = 4;
			 break;
		case 'mai':
			 m = 5;
			 break;
		case 'juin':
			 m = 6;
			 break;
		case 'juillet':
		case 'juil':
			 m = 7;
			 break;
		case 'aout':
			 m = 8;
			 break;
		case 'septembre':
		case 'sept':
			 m = 9;
			 break;
		case 'octobre':
		case 'oct':
			 m = 10;
			 break;
		case 'novembre':
		case 'nov':
			 m = 11;
			 break;
		case 'decembre':
		case 'dec':
			 m = 12;
			 break;
		default:
			 return false;
	}
	
	return m;
}

function parseDateFr(date){
    var atoms = date.match(/^\s*((?:0?[1-9]|[12]?\d)|3[01])[\s-\.\/](1[012]|0?[1-9]|(?:jan(?:vier|\.|v|v\.)?|f[eéè]v(?:rier|\.|r|r\.)?|mar(?:s)?|avr(?:il|\.)?|mai|juin|juil(?:let|\.)?|a[oô][uû]t|sept(?:embre|\.)?|oct(?:obre|\.)?|nov(?:embre|\.)?|d[eéè]c(?:embre|\.)?))[\s-\.\/]((?:20)?[01]\d)\s*$/i),
        j, m, a, result;
    
    if(!atoms || atoms.length !== 4) return false;
    
    j = parseInt(atoms[1], 10);
    a = parseInt(atoms[3], 10);
    if(a < 2000) a += 2000;
    
    m = parseInt(atoms[2], 10);
    if(!m){
		  m = getNumMonth(atoms[2]);
    }
    if(m === 2 && j > 29) return false;
    if(m === 2 && a%4 !== 0 && j > 28) return false;
    if(j === 31 && !(m === 1 | m === 3 | m === 5 | m === 7 | m === 8 | m === 10 | m === 12)) return false;
    
	 location.href = location.protocol + '//' + location.hostname + '/date/' + a + '/' + m + '/' + j + '?k=' + date;
	 
	 return true;
}
