﻿function selectmenu(menu,menuparent)
{		
	if(menu!=0)
	{
		if(menu=='2' && menuparent=='0')
		{
			$('#m_2').addClass('menuh_dernier');
			$('#m_2').removeClass('menu_dernier');
		}
		else
		{
			if(menuparent!=0)
			{			
				if($('#m_'+menuparent).attr('class')=='menu_centre ssmenuparent') $('.m_'+menuparent+'_ssmenucache').css('display','block');
			
				$('#m_'+menuparent).addClass('menu_centre');
				$('#m_'+menuparent).removeClass('menuh_centre');
				
				if(menuparent=='3')
				{
					$('#ssmv_'+menu).addClass('menuh_centre_gris');
					$('#ssmv_'+menu).removeClass('menu_centre_gris');
				}
				else
				{
					$('#ssm_'+menu).addClass('menuh_centre_gris');
					$('#ssm_'+menu).removeClass('menu_centre_gris');
				}
				
				if($('#lang').html()=='en') var lang='../'; else var lang='';
				$('.plus_'+menuparent).html('<img src="'+lang+'images/moins.png" alt="-" />');
			}
			else
			{
			
				if($('#m_'+menu).attr('class')=='menu_centre ssmenuparent') $('.m_'+menu+'_ssmenucache').css('display','block');
				
				$('#m_'+menu).addClass('menuh_centre');
				$('#m_'+menu).removeClass('menu_centre');
				
				if($('#lang').html()=='en') var lang='../'; else var lang='';
				$('.plus_'+menu).html('<img src="'+lang+'images/moins.png" alt="-" />');
			}
		}
	}
}

function ouverture_menu(ch)
{
	if($('#lang').html()=='en') var lang='../'; else var lang='';
	var idparent=$('#'+ch).attr("id");
	$('#menu_contenupage .'+idparent+'_ssmenucache').toggle('medium');
	id=idparent.split('m_');
	if($('.plus_'+id[1]+' img').attr('alt')=='+') $('.plus_'+id[1]).html('<img src="'+lang+'images/moins.png" alt="-" />'); else $('.plus_'+id[1]).html('<img src="'+lang+'images/plus.png" alt="+" />');
}

function ouverture_menu_accueil(ch)
{
	if($('#lang').html()=='en') var lang='../'; else var lang='';
	var idparent=$('#'+ch).attr("id");
	$('#menu_accueil .'+idparent+'_ssmenucache').toggle('medium');
	id=idparent.split('m_');
	if($('.plus_'+id[1]+' img').attr('alt')=='+') $('.plus_'+id[1]).html('<img src="'+lang+'images/moins_accueil.png" alt="-" />'); else $('.plus_'+id[1]).html('<img src="'+lang+'images/plus_accueil.png" alt="+" />');
}
	
	
// Fonction de verification de formulaire

var regMail = new RegExp("^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]­{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$", "i");
function isMailCorrect (m){return regMail.test(m);}
function InitFormulaireGestion () { /* initialisation, placage de l'etoile et de l'evenement submit */
	$("tr.obligatoire",$("form")).each(function () {$("label",this).each(function () {$(this).append('<'+'span class="obli">*<\/span>')})});
	$("form").submit(FormControl);
}
function FormControl(o){return ElementControl($(".obligatoire",this));} /* control du formulaire */
function ElementControl (a){/*control d'un groupe d'elements*/
	var retour=true;
	for(var i=0;i<a.length;i++){
		if (($("input",a[i]).length>0 && $("input",a[i])[0].value=="")||($("textarea",a[i]).length>0 && $("textarea",a[i])[0].value=="")){
			retour=false;
			$(a[i]).addClass('control');
		} else {
			if($(a[i]).hasClass('MailControl'))
			{
				if(isMailCorrect($("input",a[i])[0].value)) {$(a[i]).removeClass('control');$('.MailControlExp').addClass('dn');}
				else{retour=false;$(a[i]).addClass('control');$('.MailControlExp').removeClass('dn');}
			}
			else $(a[i]).removeClass('control');
		}
	}
	return retour;
}
	
$(document).ready(function() {

	$(document).noContext();
	
	$('.img_mini').click(function()
	{
		var gde=$('#viewer img').attr('id');
		var id=(this.id).replace('mini-','');
		var parent_id=gde.replace('gde-','');
		var parent_src=$('#viewer img').attr('src');
		var img=parent_src.replace(parent_id,id);
		
		$('#viewer .img').hide();
		$('#viewer a').attr('href',img.replace('gde/',''));
		$('#viewer .img').attr('src',img);
		$('#viewer .img').attr('id','gde-'+id);
		$('#thumbs img').css('opacity','1');
		$(this).css('opacity','0.6');
		$('#viewer .img').fadeIn('slow');
	});
	
	
	
	$(".zoom").click(function(){
		$(".zoom").colorbox({transition:"elastic", height:"95%"});
	});
	
	$('#menu_contenupage .ssmenuparent').click(function(){
		var url=$('#'+this.id+' a').attr('href');
		if(url=='javascript:;') { ouverture_menu(this.id); }
	});
	
	$('#menu_accueil .ssmenuparent').click(function(){
		var url=$('#'+this.id+' a').attr('href');
		if(url=='javascript:;') { ouverture_menu_accueil(this.id); }
	});
		
	
	InitFormulaireGestion();
	
	
	
	$('.gallery').bxGallery({
			maxwidth: '',              // if set, the main image will be no wider than specified value (in pixels)
	        maxheight: '',             // if set, the main image will be no taller than specified value (in pixels)
        	thumbwidth: 55,           // thumbnail width (in pixels)
	        thumbcrop: true,          // if true, thumbnails will be a perfect square and some of the image will be cropped
	        croppercent: .22,          // if thumbcrop: true, the thumbnail will be scaled to this percentage, then cropped to a square
	        thumbplacement: 'right',  // placement of thumbnails (top, bottom, left, right)
	        thumbcontainer: '',        // width of the thumbnail container div (in pixels)
	        opacity: .7,               // opacity level of thumbnails
	        load_text: '',             // if set, text will display while images are loading
	        load_image: 'images/img_loader.gif',
	                                   // image to display while images are loading
	        wrapperclass: 'outer'      // classname for outer wrapping div
	    });
		
});