(function ($, Drupal, undefined) {

  $.fn.searchFocus = function(px) {
    var searchDefaultText = 'SEARCH';

    $(this)
      .bind('focus', function() {
        if ($(this).val() == searchDefaultText) {
          $(this).val('');
        }
      })
      .bind('blur', function() {
        if ($(this).val() == '') {
          $(this).val(searchDefaultText);
        }
      })
      .blur();

   return this;
  };

  $.fn.fullNav = function(px) {
      var totalWidth = $(this).parents('ul').width(),
          numberOfTabs = 0,
          totalWidthsOfText = 0,
          totalWidthOfTab = 0,
          numBorders = 1,
          padding,
          tabs = $(this);


	    tabs.each(function(i){
        totalWidthsOfText += $(this).width();
        if (totalWidthsOfText == 0) {
          totalWidthsOfText += $(this).children('div').width();
        }
        numberOfTabs++;
        if ($(this).css('border-right-width') == "1px") {
          numBorders++;
        }
        if ($(this).css('border-left-width') == "1px") {
          numBorders++;
        }
	    });

      padding = (totalWidth - totalWidthsOfText) - numBorders;
      padding = padding/numberOfTabs;
      padding = padding/2.1;

	    tabs.each(function(i){
		    $(this).css({'padding-left': padding, 'padding-right': padding}); 
	    });
      // Debug
      // console.log('width to fill: '+totalWidth);
      // console.log('number of borders: '+numBorders);
      // console.log('number of tabs: '+numberOfTabs);

     return this;
    };

  $(window).load(function() {
      $('.block-search .form-text').searchFocus();
      $('#quicktabs-custom_engagement_block > ul > li > a').fullNav();
      $('#quicktabs-feeder > ul > li').fullNav();  
      $('#quicktabs-pirg_custom_quicktabs > ul > li').fullNav();
      // Cleaning up the styles that have been embedded by other scripts.    
      $('#block-pirg-custom-pirg-home-features ul.filmstrip').attr('style', 'list-style-type: none; list-style: none; margin:0px; padding: 0px; position: absolute; z-index: 900; top: 0px; left: 0px; height: 20px; visibility: visible; width: 660px;');
      $('#block-pirg-custom-pirg-home-features ul.filmstrip .clearfix').remove();
      $('#block-pirg-custom-pirg-home-features li.frame').each(function(){
        $(this).find('div.caption').attr('style', 'display: block;');
        $(this).attr('style', 'display: block; width: auto; padding: 0 0; overflow: visible');
      });
      $('#block-pirg-custom-pirg-home-features li').fullNav();

      $('#block-custom-resources #pirg-resource-slider').easySlider();
  });

})(jQuery, Drupal);
;

