/* TABS */

$(document).ready(function() {

  if(document.title.match(/Frequently/)) { //faq toTop links
      $('#pWrap a[href*=#top]').parent().css('text-align','right');
  }

  if ( $('#tabbedContent').attr('class') != 'cms-edit') {
    
      /* Homepagetabs --------------------------------------- */
      var preSelectedTab = $('#JSselectedTab').text()-1;                  /* tab1=0... */

      if (preSelectedTab == '-1') { preSelectedTab = 0; }                 /* if not set use the first tab */
      
      /* Remove tabs from DOM*/
      var tab2 = $('#tab2noscript');
      var tab3 = $('#tab3noscript');
      
      /* add a class to work with */
      $('.tabbedContentHeaders:first').addClass('jsTabs');
      
      /* steal the li's and insert them into jsTabs */
      $('.jsTabs').append(tab2.find('li'));
      $('.jsTabs').append(tab3.find('li'));
      // no more ~ $('.jsTabs').append('<li id="tabPlus"><img src="images/tabPlus.png" alt="plus"></li>');
      tab2.remove();
      tab3.remove();
    
      /* pull the tabContent up */
      var subtract;
      var bodyID = $('body').attr('id'); /* Homepage or Issue tabs? */
      if (bodyID == 'home') {
          subtract = '-322px'; 
      } else {
          subtract = '-192px';
      }
    
      $('#contentTab2').css('margin-top',subtract); 
      $('#contentTab3').css('margin-top',subtract);
      
      $('.jsTabs li').each(function(index){
        
        /* assign click handler */
        $(this).find('h3').click(function(){
          
          /* reset all zIndexes */
          /* and hide the tab - fix for flash content in ie ignoring z-index*/
          $('.contentTab').each(function(){ $(this).css('zIndex','0').find('div').hide(); })
          $('.jsTabs li').each(function(){ $(this).css('zIndex','0'); })
          
          /* up the zIndexes and show the tab */
          $('.contentTab').eq(index).css('zIndex','100').find('div').show();;
            $(this).parent().css('zIndex','100');
    
        })    
       })
        
       $('.jsTabs li').children('h3').eq(preSelectedTab).trigger('click');
  
  }
  var nw=0;
  $('#categoryNav li').each(function() {nw += $(this).width();});
  nw = $('#categoryNav').width()-nw;
  if(nw > 0) {
    $('#categoryNav li:last a').width($('#categoryNav li:last a').width() + nw - 1);
  }
});

$(document).ready(function() {
  $(".smartInput").focus(function() {
    if( this.value == this.defaultValue ) {
      this.value = "";
    }
  }).blur(function() {
    if( !this.value.length ) {
      this.value = this.defaultValue;
    }
  });      
});

/* NAV ie6 nav hover fix
$(document).ready(function() {
  $("#categoryNav").children().each(function() {
          $('.subnav', this).hide();
          $(this).hover(
            function() { $('.subnav', this).css('display', 'none'); $('.subnav', this).show(); },
            function() { $('.subnav', this).hide(); }
          );
  });
});
*/
