title: Set start day of the week to be Friday in JQuery UI date picker
body: <p>I saw another question that sets the first day to Monday by setting the first day to be 1.</p>
  
  <p>While I want to set the first day to be Friday.</p>
  
  <p>I tried to set the first date to 5, but not working as expected.</p>
  
  <p>When I click on 1/2/8/9/15/16/22/23 it gives wrong start date, while if clicked other than them, it will display the right start date.</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  &lt;head&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js"&gt;&lt;/script&gt;
      &lt;link rel="stylesheet" type="text/css" media="screen" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css"&gt;
  &lt;script type="text/javascript"&gt;
  $(function() {
      var startDate;
      var endDate;
  
      var selectCurrentWeek = function() {
          window.setTimeout(function () {
              $('.week-picker').find('.ui-datepicker-current-day a').addClass('ui-state-active')
          }, 1);
      }
  
      $('.week-picker').datepicker( {
          firstDay: 5,
          showOtherMonths: true,
          selectOtherMonths: true,
          onSelect: function(dateText, inst) { 
              var date = $(this).datepicker('getDate');
              startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() - 2);
              endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 4);
              var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;
              $('#startDate').text($.datepicker.formatDate( dateFormat, startDate, inst.settings ));
              $('#endDate').text($.datepicker.formatDate( dateFormat, endDate, inst.settings ));
  
              selectCurrentWeek();
          },
          beforeShowDay: function(date) {
              var cssClass = '';
              if(date &gt;= startDate &amp;&amp; date &lt;= endDate)
                  cssClass = 'ui-datepicker-current-day';
              return [true, cssClass];
          },
          onChangeMonthYear: function(year, month, inst) {
              selectCurrentWeek();
          }
      });
  
      $('.week-picker .ui-datepicker-calendar tr').live('mousemove', function() { $(this).find('td a').addClass('ui-state-hover'); });
      $('.week-picker .ui-datepicker-calendar tr').live('mouseleave', function() { $(this).find('td a').removeClass('ui-state-hover'); });
  });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="week-picker"&gt;&lt;/div&gt;
      &lt;br /&gt;&lt;br /&gt;
      &lt;label&gt;Week :&lt;/label&gt; &lt;span id="startDate"&gt;&lt;/span&gt; - &lt;span id="endDate"&gt;&lt;/span&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><a href="http://jsfiddle.net/sgfc5bz1/1/" rel="nofollow noreferrer">http://jsfiddle.net/sgfc5bz1/1/</a></p>
  
  <p>Any suggestions?</p>