/* hide all sub menus */
function resetHeadMenu()
{
    $('#headMenu>dl>dd').css("display", "none");
}

$.fn.extend({ reset: function() {
    return this.each(function() {
        $(this).is('form') && this.reset();
    }
) }});

$(document).ready(function() {
    /* show sub menus on hover */
    $('#headMenu>dl>dt>a').hover(
        function() {
            resetHeadMenu();
            $(this).parent().next().css("display", "block");
        },
        function() {}
    );
    /* hide sub menus when leaving */
	$('#headMenu>dl>dd,div,#headMenu>dl').hover(function() {}, function () {resetHeadMenu();});

    $('.slideMore').click(function(event) {
        event.preventDefault();
        $($(this).attr('href')).slideToggle("slow");
    });

    $('.newsElem').hover(function() {
        $(this).find('.admLinks').show();
    }, function() {
        if (!$(this).find('.admLinks').eq(0).parent().is('.admActive')) {
            $(this).find('.admLinks').hide();
        }
    });
    $('.admLinks>a.admShow').click(function(event) {
        event.preventDefault();
        if ($(this).parent().parent().hasClass('admActive')) {
            return;
        }
        $(this).parent().parent().addClass('admActive');
        $(this).parent().find('a').filter('.admIsActive').show();
        $(this).parent().find('a').not('.admIsActive').hide();
        $(this).parent().parent().find('.admFields').slideDown();
        $(this).parent().parent().find('.regularFields').slideUp();
    });
    $('.admLinks>a.admCancel').click(function(event) {
        event.preventDefault();
        if ($(this).parent().parent().hasClass('admActive')) {
            $(this).parent().parent().removeClass('admActive');
            $(this).parent().find('a').filter('.admIsActive').hide();
            $(this).parent().find('a').not('.admIsActive').show();
            $(this).parent().parent().find('.admFields').slideUp();
            $(this).parent().parent().find('.regularFields').slideDown();
        }
    });
    $('.admLinks>a.admReset').click(function(event) {
        event.preventDefault();
        if ($(this).parent().parent().hasClass('admActive')) {
            $(this).parent().parent().find('form').reset();
            $(this).parent().parent().animate({
                opacity: 0
            }, 150, 'linear', function(event) {
                $(this).animate({
                    opacity: 1
                }, 150, 'linear');
            });
        }
    });
    $('.admLinks>a.admSubmit').click(function(event) {
        event.preventDefault();
        if ($(this).parent().parent().hasClass('admActive')) {
            $(this).parent().parent().find('form').submit();
            $(".newsContent").hide("slow",function(){
                $('.newsContent').html('<h2>Sauvegarde en cours ...</h2>');
                $('.newsContent').slideDown('slow');
            });
        }
    });
    // give some time to analytics
    setTimeout('startGA();', 500);
});