var moisNom=new Array('janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre');
var texteCorps='';
var texteDiv='';
var texteType='corps';
$(function(){
	//CALENDRIER
	$('#menuHautCalendrier').click(function(){
		news=$('#newsletter');
		cal=$('#calendrier');
		news.fadeOut(500,function(){cal.toggle(500);});
		calendrier();
		return false;
	});
	$('#calendrier .droite').click(function(){
		calendrierMois++;
		if(calendrierMois>12) calendrierMois=1;
		calendrier();
		return false;
	});
	$('#calendrier .gauche').click(function(){
		calendrierMois--;
		if(calendrierMois<1) calendrierMois=12;
		calendrier();
		return false;
	});
	//NEWSLETTER
	$('#menuHautNewsletter').click(function(){
		cal=$('#calendrier');
		news=$('#newsletter');
		cal.fadeOut(500,function(){news.toggle(500,function(){$('#newsletter #amel').val('Votre adresse électronique');$('#newsletter #reponse').attr('innerHTML','');});});
		return false;
	});
	$('#newsletter #amel').each(function(){
		newsletterAmel=$(this).val();
		$(this).blur(function(){
			if($(this).val()=='') $(this).val(newsletterAmel);
		});
		$(this).focus(function(){
			if($(this).val()==newsletterAmel) $(this).val('');
		});
	});
	$('#newsletter a').click(function(){
		amel=$('#newsletter #amel').val().toLowerCase();
		reponse=$('#newsletter #reponse');
		valid=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i;
		if(amel=='' || !valid.test(amel)) reponse.empty().append('Adresse électronique invalide.');
		else{
			reponse.empty().append('Inscription en cours...');
			$.post('php/newsletter.php',{adresse:amel},function(data){
				if(data.toLowerCase().substr(0,5)=='array') data=data.substr(5,data.length-5);
				reponse.empty().append(data);
			});
		}
		return false;
	});
})
function calendrier()
{
	$('#calendrier .mois').empty().append(moisNom[calendrierMois-1]);
	contenu=$('#calendrier .contenu');
	contenu.fadeOut(300,function(){
		contenu.empty().append('Chargement en cours...');
		$.post('php/calendrier.php',{mois:calendrierMois},function(data){
			//data.replace('\'','a')
			if(data.toLowerCase().substr(0,5)=='array') data=data.substr(5,data.length-5);
			contenu.empty().append(data);
			//http://craigsworks.com/projects/qtip/docs/tutorials/
			$('#calendrier .contenu a').each(function(index){
				$(this).qtip({content:$(this).title,position:{corner:{target:'bottomMiddle',tooltip:'topMiddle'}},style:{background:$(this).attr('class'),border:'none',color:'#fff',name:'dark'},show:'mouseover',hide:'mouseout'});
			});
		});
	}).fadeIn(300);
}
function getPageSize()
{
	var xScroll,yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		if(document.documentElement.clientWidth) windowWidth = document.documentElement.clientWidth; 
		else windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth) pageWidth = xScroll;		
	else pageWidth = windowWidth;
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}
function menu2AfficherCacher(contenu,delai,remplacerTexte)
{
	if(texteType=='corps') texteCorps=$('#texteHaut').html();
	$('#menu2>div>div').fadeOut(delai);
	if($('#'+contenu+'Titre').hasClass('selectionne')){
		if($('#texteHaut').html!=texteCorps) texteType='corps';
		//else $('#menu2>div>div').fadeOut(delai);
		$('#menu2 .titre').removeClass('selectionne');
	}
	else{
		//$('#menu2>div>div').fadeOut(delai);
		$('#menu2 .titre').removeClass('selectionne');
		if(remplacerTexte==1) texteType=contenu;
		else{
			if($('#texteHaut').html!=texteCorps) texteType='corps';
			$('#'+contenu).toggle(delai);
		}
		$('#'+contenu+'Titre').addClass('selectionne');
	}
	var texte=(texteType=='corps'?texteCorps:$('#'+contenu).html());
	$('#texteHaut').html(texte);
}
function testUA(expr)
{
    var isWin=new RegExp('^.*'+expr+'.*$','i');
    return isWin.test(navigator.userAgent);
}
function texteFin(texte,separateur)
{
	var debut=texte.indexOf(separateur,0);
	if(debut<0) return texte;
	else return texte.substring(debut+separateur.length,texte.length);
	//else return texte.substring(debut+separateur.length,texte.length-1);
}
