// JavaScript Document

$(document).ready(function(){
	
		// supression du séparateur en trop dans le menu de pied de page
	$('#footer li:last-child a').css({'border':'none'});
	
	// menu déroulant des langues
	$('#header-langue li ul').hide();
	$('#header-langue li').hover(function(){$(this).find('ul').show();},function(){$(this).find('ul').hide();});
	
	// Skin des boutons 
	$('.button').each(skinButton)
	$('.table-18').each(function(){skinTable(this,18);})
	$('.table-10').each(function(){skinTable(this,10);})
	$('.table-7').each(function(){skinTable(this,7);})
	$('.table-6').each(function(){skinTable(this,6);})
	
	// repositionnement des checkbox et bouton radio (décalage de 2 pixel)
	$('input[type=checkbox],input[type=radio]').css({'position':'relative', 'top':'2px'});
	
	/* Supression automatique du contenu des champs de formulaire au 1er clic */
	$('input.cleanup, textarea.cleanup').bind('click focus', function(){
		if($(this).attr('clean')==undefined)
		{
			$(this).val('');
			$(this).attr('clean',true);
			
			if($(this).hasClass('password'))
				$(this)[0].type='password';
		}
	});
	
	//Pour tous les liens commençant par "mailto" ou les span ayant une class "wmail"
	$('a[href^="mailto"], span.wmail').each(function (i) {
		//Remplacment du texte dans l'élément
		var temp = $(this).html();
		temp = temp.replace(" [at] ","@");
		temp = temp.replace(" [dot] ",".");
		$(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(" [at] ","@");
			temphref = temphref.replace(" [dot] ",".");
			$(this).attr("href",temphref);
		}
	})
	
});

function getFormValue(name)
{
	var el = null;
	
	el = $('input[name='+name+']')
	if(el.length>0)
	{
		if(el.attr('type')=='radio')
		{
			for(var i=0; i<el.length; i++)
				if(el.eq(i).attr('checked'))
					return el.eq(i).val();
		}
		else
			return el.val();
	}
		
	el = $('select[name='+name+']')
	if(el.length>0)
		return el[0].options[el[0].selectedIndex].value;
}


function skinButton()
{
	if($(this).hasClass('special'))
		$(this).wrap('<span class="buttonSkinned special"></span>');
	else
		$(this).wrap('<span class="buttonSkinned"></span>');
	$(this).hover(
		function(){ $(this).parent().addClass('over') },
		function(){ $(this).parent().removeClass('over') }
	)
}

function skinTable(el,size)
{
	$(el).removeClass('table-'+size);
	var className = $(el).attr('className');
	var rel = $(el).attr('rel');

	$(el).attr('className','');
	$(el).addClass('table-'+size);
	
	$(el).wrap('<div class="clear span-'+size+' '+className+'" rel="'+rel+'"></div>');

	$(el).before('<div style="background:url(_img/table-'+size+'.png) 0 top no-repeat; height:15px;overflow:hidden;">&nbsp;</div>')
	$(el).after('<div style="background:url(_img/table-'+size+'.png) 0 bottom no-repeat; height:15px;overflow:hidden;">&nbsp;</div>')

	$('td:last-child',el).css({'border-right':'none'});
	$('th:last-child',el).css({'border-right':'none'});
}

function clickZone(cible,ban)
{
	$(cible).each(function(){
		$(this).hover(
			function(){$(this).addClass('over')},
			function(){$(this).removeClass('over')
		});
		if($('a',this).length>0)
			$(this).css('cursor','pointer');
			
		$(this).bind('click',function(e){
			if(typeof(ban)=='undefined' || $(e.target).parents(ban).length==0)
				document.location.href=$('a',this).eq(0).attr('href');
		});
	})
}
