//FICHIER JS POUR LA SKIN F1COM
$(document).ready(function() {
  
  /*BOUTON +1 Google*/
  window.___gcfg = {lang: 'fr'};
  (function() {
      var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
      po.src = 'https://apis.google.com/js/plusone.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
    })();  
	
	/*MENU*/ 
  //$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
	var doClideDown=true;
	var doSlideUP=false;
	$("ul.topnav li").hover(function() {   
		if(doClideDown){
			$(this).find("ul.subnav").slideDown('fast',function(){
				doClideDown=false;
				doClideDown=true;
				doSlideUP=true;
			}).show();
		}
		
	  $(this).parent().hover(
	  	function() {},
	    function(){  
	    	if(doSlideUP){
		  		$(this).find("ul.subnav").slideUp('fast',function(){
		  			doClideDown=true;
						doSlideUP=false;
						doSlideUP=true;
		    	});
	    	}
	    }
	  );  
	}).hover(
		function() {  
	  	$(this).addClass("subhover");  
	  },
	  function(){
	  	$(this).removeClass("subhover");
	  	if(doSlideUP){
	  		$(this).find("ul.subnav").slideUp('fast',function(){
	  			doClideDown=true;
					doSlideUP=false;
					doSlideUP=true;
	    	});
    	} 
	  }
	);  
	
  //Affichage de la boite de login
  if($('#afficheLogin').length>0){
    if($("#afficheLogin").html()==""){
      var formHtml="<form id='login' name='login' method='post' action='index.php?affiche_login=1&template=login'>" +
                     "<input type='hidden' value='login' name='module'>" +
                     "<input type='hidden' value='login' name='action'>" +
                     "<fieldset>" +
                        "<p>" +
                          "<label>Identifiant :</label>" +
                          "<input type='text' maxlength='30' size='10' value='' name='login' id='login'>" +
                        "</p>"+
                        "<p>" +
                          "<label>Mot de passe :</label>" +
                          "<input type='password' maxlength='30' size='10' value='' name='pass' id='pass'>" +
                        "</p>" + 
                     "</fieldset>";
                   "</form>";
      $("#afficheLogin").html(formHtml);
      $( "#afficheLogin" ).dialog({
        title: "Authentification requise",
        modal: true,
        open: function(e,ui) {
          //Active le post du formulaire sur ENTER
        	$(this).keyup(function(e) {
              if (e.keyCode == 13) {
                 $('.ui-dialog-buttonpane button:last').trigger('click');
              }
          });
        },
        buttons: {
          "OK": function() {
          	var urlLogin=$("#login").attr("action");
          	var login = $("input#login").val();  
            var pass = $("input#pass").val();  
            var dataString="module=login&action=login&login=" + login + "&pass="+ pass + "&ajaxLogin=1";
            $("#afficheLogin").html("<div style='margin-top:20px;'><center><img src='./images/ajax-loader.gif' /></center></div>");
            $.ajax({  
              type: "POST",  
              url: urlLogin,  
              data: dataString,  
              success: function(result) {  
                  if(result!="FAILED"){
                    window.location=result;
                  }else{
                  	$("#afficheLogin").html("<p class='error'>Erreur d'authentification. Veuillez ré-essayer</p>" + formHtml );
                  }
              }  
            });  
            
          }
        },
        close: function() {
          
        }
      });
    }
  }
  
  //Dialog Box Googlemap
  if($('#imgGoogleMap').length>0){
  	$('#imgGoogleMap').click( function() {
  		$( "#map_canvas" ).dialog({
				modal: true,
				height:400,
				width:400,
				title:"Plan d'accès à nos locaux",
				buttons: {
					FERMER: function() {
						$( this ).dialog( "close" );
					}
				}
			});
  	} );
  }
  
  //SlideShow formation sur page d'accueil
  if($('#slideForm').length>0){
  	$('#slideForm').slides({
    	generateNextPrev: false,
      effect: 'slide',
      play: 5000
    }); 
  }
  
  //Vertical Tabs
  $("#vTabs").jVertTabs();
  
  //Accordeon
  if($('#listeCoursAccordion').length>0){
	  var icons = {
				header: "ui-icon-circle-arrow-e",
				headerSelected: "ui-icon-circle-arrow-s"
			};
	  $("#listeCoursAccordion").accordion({
			autoHeight: false,
			navigation: true,
			icons:icons,
			collapsible: true
		});
	  if ($('#listeCoursAccordion h2').length>1){
	  	$("#listeCoursAccordion" ).accordion("activate", -1);
	  }
  }
  
  //Google map dans la div ID=map_canvas
	if($('#map_canvas').length>0){
    var latlng = new google.maps.LatLng(43.5481,5.366306);
    var myOptions = {
      zoom: 16,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

    marker = new google.maps.Marker({
    	 map:map,
       draggable:false,
       animation: google.maps.Animation.DROP,
       position: latlng
  	});
    marker.setAnimation(google.maps.Animation.BOUNCE);
	}
	
	//Validation de formulaire
	
	$("#formContact").validate();

});
