Check/uncheck click handler only toggles first time
<p>I have this code.</p>

<pre><code>        var check = true;
        $('#selectall').click(function () {
            $("form input[type='checkbox']").attr ("checked", true);
            if (check){
                check = false;
                $('#checktodos').attr("src", "check_off.png");
            }
            else {
                $('#checktodos').attr("src", "check_on.png");
                $("form input[type='checkbox']").attr ("checked", false);
            }
        });
</code></pre>

<p>When I click on the button with ID = "selectall", all checkboxes are selected, and the image button changes. Then I click again on the same button, and all checkboes are unchecked and image changes again to the first one.</p>

<p>But I can't do it more times, I make a third click on the button, and the image button doesn't change and no checkboxes are selected. I want to do this unlimited times.</p>
