Check window's width function in resize()
<p>I want to check window's width in user visit url and if browser resize then do it again.<p> <br>
Q1. If I only call the function <code>setcolamt()</code> in <code>resize()</code> it won't do anything <code>colmat</code>'s value same as before, I don't know why? I have to pull all code again just like the <code>comment</code> then <code>colmat</code> will be change.</p>

<p>Q2. Why is <code>alert()</code> in <code>resize()</code> it will pop up 3 times? 
<br><p>
Any suggestion will be appreciated.<p></p>

<p><a href="http://jsfiddle.net/86TDM/2/" rel="nofollow">jsfiddle</a></p>

<pre><code>var colamt=0;
var winwid = $(window).width();
function setcolamt(){        
    if(winwid &gt; 800){
        colamt = 8;
    }
    else{
        colamt = 4;
    }
};
setcolamt();
alert(colamt);

$(window).resize(function(){
    //var colamt=0;
    //var winwid = $(window).width();
    //function setcolamt(){        
        //if(winwid &gt; 800){
        //    colamt = 8;
        //}
        //else{
        //    colamt = 4;
        //}
    //};
    setcolamt();
    alert(colamt);
});
</code></pre>

<p>​</p>
