$(document).ready(function(){

    //$("table div#documents").hide(); //hide all div elements with id "documents" hich are inside a table element.
    $('table div[id^="documents_"]').hide(); //hide all div elements with id "documents" hich are inside a table element.

    $("a")
        .click(function(){
            var element = this.id; //store a.id in variable

            if(document.getElementById("documents_"+element).style.display == "block"){
                $("div."+element).hide("slow"); //hide div with id
                $(this).toggleClass("retract");
            }
            else{
                $("div."+element).show("slow"); //show div with id
                //$("a img#"+element).addClass("retract");
                $(this).toggleClass("retract");
            }
            return false;

        }).end();


        /* Download document via jquery
         $('a').click(function(e) {
            e.preventDefault();  //stop the browser from following
            window.location.href = 'uploads/file.doc';
        });


         */

});