﻿/*
 * jQuery Tools tabs;
 * http://flowplayer.org/tools/
 */
$(function() {
  var $tabs = $('ul.jquery-tools-tabs');
  var initialIndex = 0;
// is there a querystring?  
  var getIndex = 0;
  var tabCount = $tabs.find('li').length;
  if ( tabCount ) {
    var tabIndex = location.search.split('=', 2);
    if (tabIndex && tabIndex.length > 1) {
      var getIndex = tabIndex[1].substring(0,1) * 1;
      if (!isNaN(getIndex) && getIndex < tabCount) {
        initialIndex = getIndex;
      }
      else {
        getIndex = 0;
      }
    }
  }

/*
 * solve problem resulting from postback not saving state
 * and always going to the **FIRST** tab; see master page
 * for hidden form value
 */
  var $tabTracker = $(':input[id$=jQueryToolsTabTracker]');
  if (getIndex < 1) {
    initialIndex = $tabTracker.val()
      ? $tabTracker.val() * 1 : 0;
  }
  $tabs.tabs('div.jquery-tools-panes > div', {
    initialIndex: initialIndex,
    onBeforeClick: function (event, tabIndex) {
      $tabTracker.val(tabIndex);
    }
  });
});

