/**
  Utilities
**/

// On DOM Ready
jQuery(document).ready(function(){
  jQuery('#content hr').wrap('<div class="hr">');
  
  substringText(jQuery('.post-nav a'),30);
  resizeWpCaption(jQuery('.wp-caption'));
  
  // Replace Search form label
  var labelText = jQuery('#searchForm #searchsubmit').val();
  jQuery('#searchsubmit').val('Go');
  if (jQuery('#searchForm #s').val() == '') {
    jQuery('#searchForm #s').val(labelText);
  };
  jQuery('#searchForm #s').focus(function(){
    if (jQuery('#searchForm #s').val() == labelText) {
      jQuery(this).val('');
      jQuery(this).blur(function(){
        if (jQuery(this).val()=='') {
          jQuery('#searchForm #s').val(labelText);
        };
      });
    };
  });
  
  jQuery('.wp-caption-text').wrapInner('<span></span>');
  jQuery('#navigation').dropdown({timeout:300});
  
  jQuery('.wp-tag-cloud a').each(function(){
    var str = jQuery(this).html();
    jQuery(this).html(str.split(' ').join('&nbsp;'));
  });
  
  
});

function resizeWpCaption(obj) {
  obj.each(function(){
    var contWidth = jQuery(this).find('IMG').width();
    var contHeight = jQuery(this).find('IMG').height();
    jQuery(this).width(contWidth).height(contHeight);
    jQuery(this).find('.wp-caption-text SPAN').width(contWidth);
  });
};

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);
  });
};
/*
function showPortalMaximised() {
  jQuery('#eyebrow').animate({ height:87 },400);
  jQuery('#eyebrow .wrapper').animate({ opacity: 0 },400,function() {
    loadFlash();
    jQuery('#eyebrow .wrapper').animate({opacity:1})
  });
};

function loadFlash() {
  var po = new SWFObject("http://www.gold.org/common/swf/portal.swf", "portalswf", "100%", "60", "6", "#ffffff");
  po.addVariable('portalZone', 'www.science.gold.org');
  po.addVariable('hostZone', '/');
  po.addParam('allowScriptAccess','always');
  po.addParam("wmode", "opaque");
  po.write("flashbrow");
};

*/
