$(document).ready(function(){

    jQuery.preloadImages = function() {
        for(var i = 0; i<arguments.length; i++) {
            jQuery("<img>").attr("src", arguments[i]);
        }
    }

    $("input, textarea").focus( function() {
        if(this.value == this.defaultValue) {
            this.select();
        }
    });

    $('#toggle_transcription').click( function() {
        if ($("#transcription").is(":hidden")) {
            $("#transcription").slideDown("slow");
        } else {
            $("#transcription").slideUp('slow');
        }
    });

    $('#results_learning_header').click( function() {
        if ($("#results_learning").is(":hidden")) {
            $("#results_learning").slideDown("slow");
        } else {
            $("#results_learning").slideUp('slow');
        }
    });

    $('#results_learning_header_close').click( function() {
        if ($("#results_learning").is(":hidden")) {
            $("#results_learning").slideDown("slow");
        } else {
            $("#results_learning").slideUp('slow');
        }
    });

    $('#results_learning_header_open').click( function() {
        if ($("#results_learning").is(":hidden")) {
            $("#results_learning").slideDown("slow");
            $('#results_learning_header_open').html('-');
        } else {
            $("#results_learning").slideUp('slow');
            $('#results_learning_header_open').html('+');
        }
    });

    $('#team_show').click( function() {
        if ($("#the_team").is(":hidden")) {
            $("#the_team").slideDown("slow");
        } else {
            $("#the_team").slideUp('slow');
        }
    });


    $("#french").hover(
        function on() {
            $(this).css({'background-image' : 'url(' + loc + 'public/images/main/menu_francais_over.jpg)', 'cursor' : 'pointer'});

        },
        function out() {
            $(this).css({'background-image' : 'url(' + loc + 'public/images/main/menu_francais.jpg)'});
        }
    );

    $("#english").hover(
        function on() {
            $(this).css({'background-image' : 'url(' + loc + 'public/images/main/menu_english_over.jpg)', 'cursor' : 'pointer'});
        },
        function out() {
            $(this).css({'background-image' : 'url(' + loc + 'public/images/main/menu_english.jpg)'});
        }
    );

    $(".sponsor").hover (
        function on() {
           url = loc + 'public/images/main/' + $(this).attr('id') + '_over.jpg';
           $(this).attr('src', url);
        },
        function out() {
            url =  loc + 'public/images/main/' + $(this).attr('id') + '.jpg';
            $(this).attr('src', url);
        }
    );

    $(".sponsor_content").hover (
        function on() {
           url = loc + 'public/images/content/' + $(this).attr('id') + '_over.gif';
           $(this).attr('src', url);
        },
        function out() {
            url =  loc + 'public/images/content/' + $(this).attr('id') + '.gif';
            $(this).attr('src', url);
        }
    );


    $(".menu_item").hover (
        function on() {
           url =  loc + 'public/images/content/' + $(this).attr('id') + '_over.jpg';
           $(this).attr('src', url);
        },
        function out() {
            url =  loc + 'public/images/content/' + $(this).attr('id') + '.jpg';
            $(this).attr('src', url);
        }
    );

        $(".student_item").hover (
        function on() {
           url =  loc + 'public/images/content/' + $(this).attr('id') + '_over.jpg';
           $(this).attr('src', url);
        },
        function out() {
            url =  loc + 'public/images/content/' + $(this).attr('id') + '.jpg';
            $(this).attr('src', url);
        }
    );

    $("#video_resolution span").click (function () {
        $('#video_resolution span').toggle();
    });
});

function create_video(path, div, SWFObject) {
    SWFObject.addParam('allowfullscreen','true');
    SWFObject.addParam('allowscriptaccess','always');
    SWFObject.addParam('wmode','opaque');

    if (path.indexOf('_Gros.flv') != -1) {
        image_name = path.replace('_Gros.flv', '.jpg');
    } else {
        image_name = path.replace('_Petit.flv', '.jpg');
        path = 'video_low/' + path;
    }

    SWFObject.addParam('flashvars','file=' + loc + 'ressources_reference/' + path + '&image=' + loc + 'public/images/vid_caps/' + image_name);
    SWFObject.write(div);
}

