/**
  Utilities
**/

// On DOM Ready
jQuery(document).ready(function(){
  substringText(jQuery('.post-nav a'),40);
  
  // Replace Search form label
  jQuery('.wp-caption-text').wrapInner('<span></span>');
  searchText('Search');

  //TwitterBar styling hooks
  jQuery('.aktt_tweets LI.aktt_more_updates').remove();
  jQuery('.aktt_tweets LI:odd').addClass('even');
  jQuery('.aktt_tweets LI:last').addClass('last');
  
});

function searchText(labelText) {
  if (!labelText) var labelText = jQuery('#searchForm #searchsubmit').val();
  jQuery('#searchsubmit').val('Go');
  if (jQuery('#searchBar #s').val() == '') {
    jQuery('#searchBar #s').val(labelText);
  };
  jQuery('#searchBar #s').focus(function(){
    if (jQuery('#searchBar #s').val() == labelText) {
      jQuery(this).val('');
      jQuery(this).blur(function(){
        if (jQuery(this).val()=='') {
          jQuery('#searchBar #s').val(labelText);
        };
      });
    };
  });
}

function substringText(obj,count) {
  obj.each(function(){
    var objSize  = jQuery(this).text().length;
    if (count <= objSize) {
      var dots = '...';
    } else {
      var dots = '';
    };
    var textAll = jQuery(this).text();
    var text = textAll.substring(0,count)+dots;
    jQuery(this).text(text).attr('title',textAll);
  });
};
