//-- sjano-cpi.fr 10/2011
$(document).ready(function(){
$('#bloc_haut_infos').css('display','none');
//---
brwsr=0;

jQuery.each(jQuery.browser, function(i, val) {

    //brwsr_txt += " --[ " + i + " : <span>" + val + 'brwsr =' + brwsr + "</span> ]-- ";
    if( i == 'msie'){
	brwsr = val;
    }
    if(brwsr != 0 && i == 'version' ){

	if(Number(val) < 9){
	  version_nav = '' ;
	  //brwsr_txt est dans le doc
	  brwsr_txt = " Votre version de Explorer, version : "+val+", est trop ancienne, minimum version 9, et certains affichages peuvent être étranges.<br />";
	  brwsr_txt += "Ihre Version von Explorer is veraltet, version : "+val+", minimum version 9, und manche displays könnten merkwürdig wirken.<br />";
	  brwsr_txt += "Your version of Explorer, version : "+val+", is to old , minimum version 9, and some displays may appear stangely.<br />";
	  $('<div class="notice_padd"> Notice :  '+brwsr_txt+'</div>').prependTo( $('#boitier h2').next() );

	   //brwsr=0;
	   //$('<span class="bold"> brwsr_txt: '+brwsr_txt+' Navigateur IE trop vieux</span><br /><br />').prependTo( $('#boitier h2').next() );
	}
    }
 //

    });
//--
function va_en_haut(){
    $('html, body').animate({scrollTop:0}, 'slow');
    return false;
}
function va_en_bas(){

    var offset_ou_pos = $('#deco_bas').offset();
    var pos_x = offset_ou_pos.top;


    $('html, body').animate({scrollTop:pos_x}, 'slow');
    return false;
}

    function va_la_bas(ou_aller){

    var offset_ou_pos = ou_aller.offset();
    var pos_x = offset_ou_pos.top;

    $('html, body').animate({scrollTop:pos_x}, 'slow');
    return false;
}
function listeSelection(leMenuSel){
	varUri = document.location.search;
	//$('h2.bold').after('<div> varUri :: '+varUri+' </div>');
	chaine = "messageNum_sel_blog=";
	Lch = chaine.length;
	recherche = varUri.indexOf(chaine);

	if(recherche>0){
		L = varUri.length;
		numeroTrouve = varUri.substr(Lch+1,L);
		longu = $(leMenuSel).length;
		leMenuSel_var = 'select'+leMenuSel+' option';
		$(leMenuSel_var).each( function(indexS) {
		    if($(this).val() == numeroTrouve ){
			$(this).attr('selected','selected');
			//$('h2.bold').after('<div> value : '+$(this).val()+' </div>');
		    }
		});
	}
}
// execute au chargement
listeSelection('#messageNum_sel_blog');
//-------
//xxxV = $('#xxx').text();
var x_left = $('#JST').css('left');
var largeur = $('#JST').css('width');
var hauteur = $('#JST').css('height');
var x_left_check = 0;
$('#JST').hide(100);
$('li.li_txt').css('display','none');
//ul.box li{display:inline; margin: 5px; padding:5px;font-size: 16px;letter-spacing: 0.45em;}
//pour permettre la lisibilité si js est désactivé
//$('ul.box li').attr('style',"display:inline; margin: 5px; padding:5px;font-size: 16px;letter-spacing: 0.45em;");
var titre = '';
//
//li_info a.defLien


//----------------------------------------------------------------------------------------
etat = 'off';
var largeur = $('#JST').css('width');
var hauteur = $('#JST').css('height');
function remetOnOff(etatVar,btn_onOff){
    //etat = etatVar;

    titre_o = btn_onOff.attr('title');
    div_exist_o = '#'+titre_o;
    loc_infos_html = btn_onOff.parent('li').next().text() ;

    if($(div_exist_o).attr('id') ){
	$(div_exist_o).hide('fast');
	$('#JST').html( 'div_exist_o = '+div_exist_o );

	if(etat == 'off'){
	    //$(div_exist_o).hide('slow');
	    //$('#JST').html( 'div_exist_o = '+div_exist_o );
	}
    }else{
	b
	$('#JST').html(' titre_o = '+titre_o+ ' pas de div_exist_o = '+div_exist_o );
    }

    return etat;
}
boutons_table = new Array();
boutons_table_h = new Array();
zindex = 0;
function bouge_infos( bouton ,bloc_infos , type_bloc ){

	titre = bouton.attr('title');
	div_exist = '#'+titre;

	var balise_offset = bouton.parent('li').offset();
	var pos_x = balise_offset.left;
	var posY = balise_offset.top + bouton.height();
	opacite = 0.6;
	//$('#JST').css('width','auto');
	//$('#JST').css('height',hauteur);

	//contenu =  bouton.parent('li').next().text();
	contenu =  $('#bloc_haut_infos li.'+titre).text();//attr('title');

	if($(div_exist).attr('id') ){


	}else{

	    balise = '<div id="'+titre+'" style="left:'+pos_x+'px;width:auto;display:none;">'+contenu+'</div>';
	    $('#bloc_haut').append(balise);
	  //div_exist = '#'+titre;
	  boutons_table[div_exist]=$(div_exist).width()+10;
	  //boutons_table_h[div_exist]=$(div_exist).height()+10;
	}
	vitesse = 1000;
	 $(div_exist).show(vitesse);
	 zindex++;
	 $(div_exist).css('z-index',zindex);

	// if( bouton.parent('li').next().hasClass('li_big') ){
	//
	//	//bloc_infos.css('line-height','17px');
	//	if(!boutons_table_h[div_exist])boutons_table_h[div_exist]=$(div_exist).height()+90;
	//
	//	$(div_exist).animate({height:'100px', opacity:0.7, width:boutons_table[div_exist],height:boutons_table_h[div_exist]},vitesse);
	//
	//
	//    }else{
	//	//bloc_infos.css('line-height','40px');
	//	if(!boutons_table_h[div_exist])boutons_table_h[div_exist]=$(div_exist).height()+30;
	$(div_exist).animate({height:'auto', opacity:0.7, width:boutons_table[div_exist],height:boutons_table_h[div_exist]},vitesse);
	//
	//
	//    }

  $(div_exist).queue(function () {
    //$(this).addClass("newcolor");
    $(this).dequeue();
    $(this).clearQueue();
  });




}
function affiche_images(bouton_img,bloc_image){
    bloc_image.css('cursor','pointer');
    lien_vignette = bouton_img.attr('title');
	bloc_image.css('top','300px');
	bloc_image.css('left','990px');
	bloc_image.html( '<img src="images_communes/captures/'+lien_vignette+'.png" style="display:none;" /> ');
	bloc_image.show('fast');

	bloc_image.animate({height:'300px', width:'400px', opacity:0.7},{duration: 200 , complete : function() { $('#JST img').fadeIn( 800); } } );

	bloc_image.queue(function () {
    $(this).dequeue();
    $(this).clearQueue();
  });
}
// -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  ----- form verif
function verif_radio(){
    check_radio = 1;
    var n = $("input:radio:checked").length;
    var nB = $("input:radio").length;
    if(n == 0){
	//$('input:radio').css('margin','0px');
	$('input:radio').wrap('<span class="wrapRd" style="border-bottom:3px solid orange;text-align:center;height:16px;line-height:16px;">','</span>');
	$('.wrapRd').animate({opacity:0.6},{duration:1500, complete: function() { $('.wrapRd').animate({opacity:1},{duration:1500 });$('.wrapRd').css('border-bottom','none'); } });

    }else{

	check_radio = 0;
    }
    return check_radio;
}
// -----
function verifie_form(){

	boite_mssg_form_style = ' style="height:auto;border:solid 3px orange;position:relative;top:0px;padding:2px 10px;margin:2px 5px;border-radius:8px 8px;"';

	erreurs_verif = 0;
	boite_mssg_form = '<span';
	boite_mssg_form1 = '>';
	boite_mssg_form_fin = '</span>';

        $('form#formulaire input:text').each( function(index) {
	    //$(this).after(boite_mssg_form);
	    //if($(this).val()=='')verif_form = false;
	    $(this).css('border-bottom','solid 1px #CCC');
	    boite_mssg_form_id = ' id="boxzid_'+index+'" ';

	    var this_offset = $(this).offset();
	    var posY = this_offset.top;
	    var h = $(this).height();

	    boite_mssg_form_style = ' style="position:relative;top:-'+(h-20)+'px;height:auto;border:solid 3px orange;padding:2px 10px;margin:9px;border-radius:8px 8px;"';

//var mssg_txt_vide = 'Ce champ est indispensable.';var mssg_txt_nomail = 'Ceci n\'est pas un mail.'; var mssg_area_vide = 'Pas de message?';
	    boite_mssg_data = boite_mssg_form + boite_mssg_form_id + boite_mssg_form_style + boite_mssg_form1  + boite_mssg_form_fin;
	    nomBox = '#boxzid_';

	    if($(this).val() == ''){



		if($(nomBox+''+index).attr('id') ){

			$(nomBox+''+index).animate({opacity:1},{duration:2000 });
			$(nomBox+index).html(mssg_txt_vide);


		    }else{
			$(this).after(boite_mssg_data);
			$(nomBox+index).html(mssg_txt_vide);
		}



		erreurs_verif++;
	    }else{


		$($(this)).css('border-bottom','solid 1px #CCC');

		 if($($(this)).attr('name')=='email'){
			email_var = $($(this)).val();

			var motif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			var motCherche = email_var.match(motif);
			//alert('motCherche = '+motCherche);
			if(motCherche == null ){

			    if(!$(nomBox+''+index).attr('id') ){
				$(this).after(boite_mssg_data);
				//mssg_txt_nomail
				$(nomBox+''+index).html(mssg_txt_nomail);
			    }else{
				$(nomBox+''+index).html(mssg_txt_nomail);
			    }

			    $(nomBox+index).animate({opacity:1},{duration:1000 });

			    erreurs_verif++;

			}

		    }



	    }

	    $(nomBox+index).animate({opacity:0},{duration:3000,specialEasing:{ height: 'easeOutBounce' }});

	});



	$('form#formulaire textarea').each( function(indexA) {

	$(this).css('border-bottom','solid 1px #CCC');
	boite_mssg_form_id = ' id="boxzAr_id_'+indexA+'" ';

	var this_offset = $(this).offset();
	var posY = this_offset.top;
	var h = $(this).height();

	this_mssg_form_style = ' style="position:relative;top:-'+(h-20)+'px;height:auto;border:solid 3px orange;padding:2px 10px;margin:9px;border-radius:8px 8px;"';
	boite_mssg_data_b = boite_mssg_form + boite_mssg_form_id + this_mssg_form_style + boite_mssg_form1  + boite_mssg_form_fin;

	if($(this).val() == ''){

		nomBox = '#boxzAr_id_';

		if($(nomBox+''+indexA).attr('id') ){

			$(nomBox+''+indexA).animate({opacity:1},{duration:2000 });
			$(nomBox+indexA).html(mssg_area_vide);


		    }else{
			$(this).after(boite_mssg_data_b);
			$(nomBox+indexA).html(mssg_area_vide);
		}

		erreurs_verif++;

	    }

	$(nomBox+indexA).animate({opacity:0},{duration:3000,specialEasing:{ height: 'easeOutBounce' }});
	});

	erreurs_verif += verif_radio();
	if(erreurs_verif == 0){
	   //return false;
	   return true;
	}else{
	    return false;
	}



}
$("form#formulaire").submit(function() {
    return verifie_form();


    });

// -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  -----  ----- form verif
$('a.defLien').mouseenter(function( ) {
    //
    bouge_infos( $(this) ,$('#JST') , 1 );


    });

//

$('#JST').css('box-shadow','10px 10px 5px #999');
$('#JST').css('-webkit-box-shadow','10px 10px 5px #999');
$('a.out_link').mouseenter(function( ) {
	//bouge_infos( $(this) ,$('#JST'), 2 );
	affiche_images($(this) ,$('#JST') );
    });
$('#JST').mouseenter(function( ) {
	$(this).animate({height:'300px', opacity:0},{duration:900 , complete: function() { $(this).css('cursor','default'); } });
	//$(this).hide(900);
    });

$('#messageNum_sel_blog').change(function( ) {
	    $('#formulaire_blog').submit();
    });

$('a.out_link').mouseleave(function( ) {
	//bouge_infos( $(this) ,$('#JST'), 2 );
//	$('#JST').hide(40);
	$('#JST img').fadeOut(1000);
//    $('#JST').clearQueue();
    $('#JST').css('background','url(images_communes/btn_close.png)  center no-repeat');
    //$('#JST').css('background-color','white');
    });

$('a.defLien').mouseleave(function( ) {
    titre_off = $(this).attr('title');
    div_exist_off = '#'+titre_off;
    $(div_exist_off).hide(300);

    });

$('#retour_haut').click(function( ) {
   va_en_haut();
    });

$('#aller_la_bas').click(function( ) {
   va_la_bas($('#types_de_formations'));
    });

});

