jQuery tabs with cookie support restore wrong tab position after page refresh
<p>I have tricky problem which I can't completely understand. It's jQuery tabs with cookie support. I've following code:</p>

<pre><code>$(document).ready(function() {
var $tabs = $("#tabs").tabs();

$tabs.tabs('select', $.cookie("tabNumber"));

$('#tabs ul li a').click(function() {
    $.cookie("tabNumber", $tabs.tabs('option', 'selected'));
});

$('#btnSelect').click(function() {
    //alert($.cookie("tabNumber"));
    //$tabs.tabs('select', 2);
    $tabs.tabs('select', $.cookie("tabNumber"));
});
});
</code></pre>

<p>So, I've 3 tabs (with positions 0,1,2) inside div named "tabs". When user selects one tab, then tab position stores in cookie. After that if user refresh page, active tab position must be restored.</p>

<p>But each time I refresh page I get active tab in previous position (if I select 2nd tab, then after refresh I got active tab in position 1, etc.).
I add some test in code (button btnSelect with onclick handler which duplicates load position functionality). 
So, if I uncomment and use </p>

<pre><code>$tabs.tabs('select', 2);
</code></pre>

<p>Then after I click btnSelect I've got right position. Ok, that's right. Then I comment that line and uncomment next one:</p>

<pre><code>alert($.cookie("tabNumber"));
</code></pre>

<p>So, I select tab, click button, get dialog message "2", and after that tab in position 1 became active.
Why?? In both cases I call 'select' method with parameter 2...</p>

<p>I know I can use aliases for tabs, but I want to understate why my code doesn't work properly.</p>
