var submenu = ''
var obj = null;
var obj2 = null;

jQuery.fn.extend({
   findPos : function() {
       obj = jQuery(this).get(0);
       var curleft = obj.offsetLeft || 0;
       var curtop = obj.offsetTop || 0;
       while (obj = obj.offsetParent) {
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
       }
       return {x:curleft,y:curtop};
   }
});


function checkHover() {
	if (obj) {
		obj.find('ol').fadeOut('fast');
                //obj.find('ol').hide();
	}
}
function checkHover2() {
	if (obj2) {
		obj2.find('dl').fadeOut('fast');
                //obj.find('ol').hide();
	}
}

function RemoveAggran () {
    $("#DisplayLarge").remove();
}

function decalBlocDdedocie() {
    var PositionDdedoc = $('#DDeDoc_Bloc').findPos();
    $('#AnimFlashDDeDoc').css('top' , PositionDdedoc.y  );
    $('#AnimFlashDDeDoc').css('left' , PositionDdedoc.x + 20  );

}

$(document).ready(function() {
    // Defilement d'image pour la page d'accueil
        if ( $("#slider1").size() == 1 ) {
            $('#slider1').s3Slider({timeOut: 4000});
        }

    // Menu
	$('#hc_menu ul > li').hover(
        function() {
            if (obj) {
                obj.find('ol').fadeOut('fast');
                obj = null;
            }
            $(this).find('ol').fadeIn('fast');
	},
        function(){
           obj = $(this);
            setTimeout(
                    "checkHover()",
                    400);
	});
	$('#hc_menu ul > li > ol > li').hover(
        function() {
            if (obj2) {
                obj2.find('dl').fadeOut('fast');
                obj2 = null;
            }
            $(this).find('dl').fadeIn('fast');
	},
        function(){
           obj2 = $(this);
            setTimeout(
                    "checkHover2()",
                    400);
	});

    // Agrandissement d'image
        if ( $(".DisplayPicture").size() == 1 ) {
            $('.DisplayPicture > img').hover(
                function () {
                    var positionPicture = $('.DisplayPicture > img').findPos();
                    $('.DisplayPicture > img').click(
                    function () {
                        $(".DisplayPicture").prepend( '<div id="LargePicture"><img src="http://www.culture-formation.ch/_img/puce0002.png" alt="Fermer" title="Fermer" id="CloseLargePicture" /><img src="' + $('.DisplayPicture > img').attr ( 'src' ).replace( 'mini' , 'large' ) + '" alt="" /></div>' );
                        $("#LargePicture").css ( 'width' , $('.DisplayPicture > img').attr('width') * 2.5 );
                        $("#LargePicture").css ( 'height' , $('.DisplayPicture > img').attr('height') * 2.5 );
                        $("#LargePicture").css ( 'z-index' , '950' );
                        $("#LargePicture").css ( 'margin-left' , '-' + ( ( $('.DisplayPicture > img').attr('width') * 2.5 ) / 2 ) + 'px' );
                        $('#CloseLargePicture').click(
                        function () {
                            $("#LargePicture").fadeOut("normal",function(){
                                $('#LargePicture').remove();
                            });
                        });
                    }
                    );
                },
                function () {
                    setTimeout("RemoveAggran()",400);
                }
            );
        }

        if ( $("#connu").size() == 1 ) {
            $( "#connu" ).change( function() {
                $( '#ContentAreaPrecisez' ).empty ();
                var contentLoader = '<label for="precisez">Précisez : </label>';
                contentLoader += '<img src="http://www.culture-formation.ch/_img/loader0000.gif" alt="chargement ..." />';
                $( '#ContentAreaPrecisez' ).prepend ( contentLoader );
                $.getJSON("./_lib/GetAreaPrecisez.php",{ param: $('#connu').attr('value') },
                  function(json){
                      var CountJson = json.length;
                      var content = '<label for="precisez">Précisez : </label>';
                      content += '<select name="precisez" id="precisez" tabindex="15" >';
                      content += '<option value="" >-- Veuillez préciser --</option>';
                      for ( i=0 ; i<CountJson ; i++ ) {
                          content += '<option value="' + json[i].Code + '" >' + json[i].Libelle + '</option>';
                      }
                      content += '</select>';
                      $( '#ContentAreaPrecisez' ).empty ();
                      $( '#ContentAreaPrecisez' ).prepend ( content );
                  }
                );
            });
        }
// Calque lors de la validation des formulaires
        if ( $("#Submit_FormForDDeDoc").size() == 1 ) {
            $('#Submit_FormForDDeDoc').click(
                function () {
                    if ( $( '#calqueValid' ).size() == 1 )
                        $( '#calqueValid' ).remove();
                    $( '#page_ddedoc' ).prepend ( '<div id="calqueValid" ><img src="http://www.culture-formation.ch/_img/loader0000.gif" alt="chargement ..." /></div>' );
                    return true;
                }
            );
            $("#Submit_FormForDDeDoc").hover(function(){
                $(this).attr( 'src' , 'http://www.culture-formation.ch/_img/ddedoc_valid.png' );
            },function(){
                $(this).attr( 'src' , 'http://www.culture-formation.ch/_img/ddedoc_valid_hover.png' );
            });
        }
        if ( $("#Submit_FormForRecrut").size() == 1 ) {
            $('#Submit_FormForRecrut').click(
                function () {
                    if ( $( '#calqueValid' ).size() == 1 )
                        $( '#calqueValid' ).remove();
                    $( '#page_ddedoc' ).prepend ( '<div id="calqueValid" ><img src="http://www.culture-formation.ch/_img/loader0000.gif" alt="chargement ..." /></div>' );
                    return true;
                }
            );
            $("#Submit_FormForRecrut").hover(function(){
                $(this).attr( 'src' , 'http://www.culture-formation.ch/_img/dderecrut_valid.png' );
            },function(){
                $(this).attr( 'src' , 'http://www.culture-formation.ch/_img/dderecrut_valid_hover.png' );
            });
        }

        if ( $("#viewMovie1").size() == 1 ) {
            $('#viewMovie1').click(
                function () {
                    var contentMovie = '<div id="PopInMovie" >';
                    contentMovie += '<div><img src="http://www.culture-formation.ch/_img/puce0002.png" alt="Fermer" title="Fermer" id="CloseMovie" /></div>';
                    contentMovie += '<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="328" height="200">';
                    contentMovie += '<param name="movie" value="http://www.culture-formation.ch/_medias/player.swf" /> ';
                    contentMovie += '<param name="allowfullscreen" value="true" /> ';
                    contentMovie += '<param name="allowscriptaccess" value="always" /> ';
                    contentMovie += '<param name="flashvars" value="file=video0000.flv&image=http://www.culture-formation.ch/_img/preview0000.png" /> ';
                    contentMovie += '<embed ';
                    contentMovie += 'type="application/x-shockwave-flash"';
                    contentMovie += 'id="player2"';
                    contentMovie += 'name="player2"';
                    contentMovie += 'src="http://www.culture-formation.ch/_medias/player.swf" ';
                    contentMovie += 'width="328" ';
                    contentMovie += 'height="200"';
                    contentMovie += 'allowscriptaccess="always" ';
                    contentMovie += 'allowfullscreen="true"';
                    contentMovie += 'flashvars="file=video0000.flv&image=http://www.culture-formation.ch/_img/preview0000.png" ';
                    contentMovie += '/> ';
                    contentMovie += '</object> ';
                    contentMovie += '</div>';
                    $( '#content_global' ).prepend ( contentMovie );
                    var positionMovie = $('#viewMovie1').findPos();
                    $( '#PopInMovie' ).css ( 'top' , positionMovie.y - 30 );
                    $( '#PopInMovie' ).css ( 'left' , positionMovie.x -  30 );
                    $('#CloseMovie').click(
                    function () {
                        $('#PopInMovie > object').remove();
                        $("#PopInMovie").fadeOut("normal",function(){
                            $('#PopInMovie').remove();
                        });
                    });
                }
            );
        }

        if ( $("#viewMovie2").size() == 1 ) {
            $('#viewMovie2').click(
                function () {
                    var contentMovie = '<div id="PopInMovie" >';
                    contentMovie += '<div><img src="http://www.culture-formation.ch/_img/puce0002.png" alt="Fermer" title="Fermer" id="CloseMovie" /></div>';
                    contentMovie += '<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="328" height="200">';
                    contentMovie += '<param name="movie" value="http://www.culture-formation.ch/_medias/player.swf" /> ';
                    contentMovie += '<param name="allowfullscreen" value="true" /> ';
                    contentMovie += '<param name="allowscriptaccess" value="always" /> ';
                    contentMovie += '<param name="flashvars" value="file=video0001.flv&image=http://www.culture-formation.ch/_img/preview0001.png" /> ';
                    contentMovie += '<embed ';
                    contentMovie += 'type="application/x-shockwave-flash"';
                    contentMovie += 'id="player2"';
                    contentMovie += 'name="player2"';
                    contentMovie += 'src="http://www.culture-formation.ch/_medias/player.swf" ';
                    contentMovie += 'width="328" ';
                    contentMovie += 'height="200"';
                    contentMovie += 'allowscriptaccess="always" ';
                    contentMovie += 'allowfullscreen="true"';
                    contentMovie += 'flashvars="file=video0001.flv&image=http://www.culture-formation.ch/_img/preview0001.png" ';
                    contentMovie += '/> ';
                    contentMovie += '</object> ';
                    contentMovie += '</div>';
                    $( '#content_global' ).prepend ( contentMovie );
                    var positionMovie = $('#viewMovie2').findPos();
                    $( '#PopInMovie' ).css ( 'top' , positionMovie.y - 30 );
                    $( '#PopInMovie' ).css ( 'left' , positionMovie.x -  30 );
                    $('#CloseMovie').click(
                    function () {
                        $('#PopInMovie > object').remove();
                        $("#PopInMovie").fadeOut("normal",function(){
                            $('#PopInMovie').remove();
                        });
                    });
                }
            );
        }

        if ( $("#viewMovie3").size() == 1 ) {
            $('#viewMovie3').click(
                function () {
                    var contentMovie = '<div id="PopInMovie" >';
                    contentMovie += '<div><img src="http://www.culture-formation.ch/_img/puce0002.png" alt="Fermer" title="Fermer" id="CloseMovie" /></div>';
                    contentMovie += '<object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="328" height="200">';
                    contentMovie += '<param name="movie" value="http://www.culture-formation.ch/_medias/player.swf" /> ';
                    contentMovie += '<param name="allowfullscreen" value="true" /> ';
                    contentMovie += '<param name="allowscriptaccess" value="always" /> ';
                    contentMovie += '<param name="flashvars" value="file=video0002.flv&image=http://www.culture-formation.ch/_img/preview0002.png" /> ';
                    contentMovie += '<embed ';
                    contentMovie += 'type="application/x-shockwave-flash"';
                    contentMovie += 'id="player2"';
                    contentMovie += 'name="player2"';
                    contentMovie += 'src="http://www.culture-formation.ch/_medias/player.swf" ';
                    contentMovie += 'width="328" ';
                    contentMovie += 'height="200"';
                    contentMovie += 'allowscriptaccess="always" ';
                    contentMovie += 'allowfullscreen="true"';
                    contentMovie += 'flashvars="file=video0002.flv&image=http://www.culture-formation.ch/_img/preview0002.png" ';
                    contentMovie += '/> ';
                    contentMovie += '</object> ';
                    contentMovie += '</div>';
                    $( '#content_global' ).prepend ( contentMovie );
                    var positionMovie = $('#viewMovie3').findPos();
                    $( '#PopInMovie' ).css ( 'top' , positionMovie.y - 30 );
                    $( '#PopInMovie' ).css ( 'left' , positionMovie.x -  30 );
                    $('#CloseMovie').click(
                    function () {
                        $('#PopInMovie > object').remove();
                        $("#PopInMovie").fadeOut("normal",function(){
                            $('#PopInMovie').remove();
                        });
                    });
                }
            );
        }
});

function ValidMessageForNotifier ( strMessage ) {
    $( '#notifier' ).empty ();
    $( '#notifier' ).prepend ( strMessage );
    $( '#notifier' ).slideToggle ( 'normal' );
    setTimeout("RemoveNotifier()",5000);
}
function RemoveNotifier() {
    $( '#notifier' ).slideToggle ( 'normal' );
}
