jQuery( function()
{
 $("div.menu_left ul#menu li").click( function ()
 {
  $("div.menu_left ul#menu li ul.sub-nav").css("display","none");
  $(this).find("ul.sub-nav").css("display","block");
  
  var newSizeHeight = $(this).outerHeight();
  console.log( $(this) );
  console.log( newSizeHeight );
  console.log(  $("div.menu_left").css( "height" ) );
  $("div.menu_left").css( "height", 310 + newSizeHeight );
  
 });

 $('a[name=submit]').click(function(){
  $(this).parents('form').submit();
 });
 
 // Map
 if( $( "#map-canvas" ).length > 0 )
 {
  latlng = new google.maps.LatLng( 47.261038, -1.541483 );
  map = new google.maps.Map( $("#map-canvas").get(0),
  {
   "zoom": 13,
   "center": latlng,
   "mapTypeId": google.maps.MapTypeId.ROADMAP,
   "mapTypeControl": false
  } );

  var marker = new google.maps.Marker(
  {
   "map": map,
   "position": latlng
  } );
 }
 
 replaceFrameContent();
 
});

function launchVideo( video_uri )
{
 // Launch video
 jwplayer("video_container")
  .setup({
          file: video_uri,
          autostart: false,
          bufferlength: 20,
          controlbar: 'bottom',
          width: 235,
          height: 162,
          wmode: "opaque",
          image: '/templates/cens/imgs/video-presentation.png',
          players: [
                    { type: "flash", src: "/mediaplayer/player.swf" }
                   ],
          plugins: {
                    sharing: { link: false, menu: false }
                   },
          skin: "/mediaplayer/skins/glow.zip"
         });
}

function replaceFrameContent()
{
 var frameContentList = $("div.frame_content").has("h1");
 
 $( frameContentList ).each( function( i, frameContent )
 {
  if( $( frameContent ).find( "h1:first" ).height() > parseInt( $( frameContent ).find( "h1:first" ).css("min-height") ) )
  {
   var height = parseInt($( frameContent ).css( "padding-top") ) + ( $( frameContent ).find( "h1:first" ).height() - parseInt( $( frameContent ).find( "h1:first" ).css("min-height") ) );
   $( frameContent ).css( "padding-top" , height + "px" );
  }
 });
  
}


function sendApprenticeShipTax()
{
 if( $('form').validForm() )
 {
  $.post( "/system/private/private.html",
          $.extend( $('form').find(":input").serializeJSON(), { "action_form": "sendApprenticeShipTax", "files": {} } ),
          function( data )
          {
           if( data.status == true )
           {
             ViGiSITE.core.prompt( "Votre demande a bien été pris en compte.",
                                   { "OK": { className: "little", default_button: true, callback: function(){ window.location.reload(); } } } );
           }
          } );
 }
 else
 {
   ViGiSITE.core.prompt( "Un ou plusieurs champs du formulaire ne sont pas remplis correctement et ont été mis en surbrillance.",
                         { "OK": { className: "little", default_button: true } } );
 }
}

function changeNews( id, date )
{
  $.post( "/system/private/private.html",
          { "action_form": "changeNews", "id_news": id, "date": date },
          function( data )
          {
           if( data.status == true )
           {
            console.log("yes");
           }
          });
}

function formAccessStudent()
{
  ViGiSITE.core.prompt( "<form id='login_student' class='login' method='post' action='/'>"
                       +" <p>Accès étudiant :</p>"
                       +" <input type='text' value='E-mail' alt='E-mail' name='email' class='defaultValue'>"
                       +" <input type='password' alt='Mot de passe' name='password' class='password'>"
                       +"</form>",
                        { "Annuler": { className: "little" }, 
                          "Connexion": { className: "little", 
                                         default_button: true, 
                                         callback: function(){  
                                          $.post( "/system/private/userspace.html", 
                                          $.extend( { action_form: "connect", access: "student" }, $("form#login_student").find(":input").serializeJSON() || {} ), 
                                          function( data )
                                          {
                                           if( data.status == true )
                                           {
                                            window.location = "/";
                                           }
                                           else
                                           {
                                            ViGiSITE.core.prompt( "Connexion refus&eacute;e. Votre login et/ou votre mot de passe sont incorrects. Veuillez saisir &agrave; nouveau vos identifiants." );
                                           }
                                          });
                                         } 
                                       } 
                        },
                        null,
                        "access" );
                        
 initDefaultValues( $("form#login_student") ); 
}

function formAccessTeacher()
{
  ViGiSITE.core.prompt( "<form id='login_teacher' class='login' method='post' action='/'>"
                       +" <p>Accès enseignant :</p>"
                       +" <input type='text' value='E-mail' alt='E-mail' name='email' class='defaultValue'>"
                       +" <input type='password' alt='Mot de passe' name='password' class='password'>"
                       +"</form>",
                        { "Annuler": { className: "little" }, 
                          "Connexion": { className: "little", 
                                         default_button: true, 
                                         callback: function(){  
                                          $.post( "/system/private/userspace.html", 
                                          $.extend( { action_form: "connect", access: "teacher" }, $("form#login_teacher").find(":input").serializeJSON() || {} ), 
                                          function( data )
                                          {
                                           if( data.status == true )
                                           {
                                            window.location = "/";
                                           }
                                           else
                                           {
                                            ViGiSITE.core.prompt( "Connexion refus&eacute;e. Votre login et/ou votre mot de passe sont incorrects. Veuillez saisir &agrave; nouveau vos identifiants." );
                                           }
                                          });
                                         } 
                                       } 
                        },
                        null,
                        "access"
                        );
                        
 initDefaultValues( $("form#login_teacher") ); 
}


function formAccessParent()
{
  ViGiSITE.core.prompt( "<form id='login_parent' class='login' method='post' action='/'>"
                       +" <p>Accès parent :</p>"
                       +" <input type='text' value='E-mail' alt='E-mail' name='email' class='defaultValue'>"
                       +" <input type='password' alt='Mot de passe' name='password' class='password'>"
                       +"</form>",
                        { "Annuler": { className: "little" }, 
                          "Connexion": { className: "little", 
                                         default_button: true, 
                                         callback: function(){  
                                          $.post( "/system/private/userspace.html", 
                                          $.extend( { action_form: "connect", access: "parent" }, $("form#login_parent").find(":input").serializeJSON() || {} ), 
                                          function( data )
                                          {
                                           if( data.status == true )
                                           {
                                            window.location = "/";
                                           }
                                           else
                                           {
                                            ViGiSITE.core.prompt( "Connexion refus&eacute;e. Votre login et/ou votre mot de passe sont incorrects. Veuillez saisir &agrave; nouveau vos identifiants." );
                                           }
                                          });
                                         } 
                                       } 
                        },
                        null,
                        "access"
                        );
                        
 initDefaultValues( $("form#login_parent") ); 
}


function accessVideo()
{
  ViGiSITE.core.prompt( "<div id='video_popup'></div>" );
}


function sendFormContact( _this )
{
 if( $(_this).validForm() )
 {
  $.post( "/system/private/private.html",
         $.extend( { action_form: "sendFormContact" }, ( $(_this).find(":input").serializeJSON() || {} ) ), 
         function( data )
         {
          if( data.status == true )
          {
           ViGiSITE.core.prompt( "Votre message a été envoyé avec succès");
          }
          else
          {
           ViGiSITE.core.prompt( "Une erreur est survenue lors de l'envoi du formulaire");
          }
         } );
 }
 else
 {
  ViGiSITE.core.prompt( "Un ou plusieurs champs du formulaire ne sont pas remplis correctement et ont été mis en surbrillance.",
                         { "OK": { className: "little", default_button: true } } );
 }
}


