Cufon.replace('h1');
Cufon.replace('h2');
//Cufon.replace('h7');
Cufon.replace('.h6big');
//Cufon.replace('.black14');
Cufon.replace('#title');
Cufon.replace('.cs-overlay');

$(document).ready(function() {

  $('#leftbox, #rightbox').height($('#homebox').height());
  // var lh = $('#leftbox').outerHeight();
  // var rh = $('#rightbox').outerHeight();
  // var tallest = lh > rh ? lh : rh;
  // tallest -= 40;
  // $('#leftbox').css('height', tallest + 'px');
  // $('#rightbox').css('height', tallest + 'px');



  
  $(".obf").each(function(){  
    var self = $(this);
    var email = this.tagName.toLowerCase() == 'a' ? self.attr('href') : self.html();
    email = email.replace(/[a-zA-Z]/g, function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});
    if(this.tagName.toLowerCase() == 'a'){
      if(self.html() == self.attr('href')){
        self.html(email);
      }
      self.attr('href','mailto:'+email);
    }else{
      self.html(email)
    }
  });
  
  
  
  
  $('#categories span').each(function(){
    var $this = $(this);
    //$this.css({position:'absolute', top:'50%', left:'6px',  marginTop:-parseInt($this.height() / 2)})
    $this.css({position:'absolute', top:'50%', left:0, marginTop:-parseInt($this.height() / 2)})
  })
  
  $('.case-study').each(function(){
    var $span = $(this).find('span');
    $span.css({position:'absolute', left:0, top:'50%', marginTop: -parseInt($span.height() / 2)})
  }).hover(function(e){
    $(this).find('img').animate({opacity:0})
  }, function(e){
    $(this).find('img').animate({opacity:1})
  })

  //$('blockquote').prepend(" <span class='bqstart'>&#8220;</span> ");
  //$('blockquote').append(" <span class='bqend'>&#8221;</span> ");
  $('blockquote').prepend(" <span class='bqstart'>&nbsp;</span> ");
  $('blockquote').append(" <span class='bqend'>&nbsp;</span> ");
  
  
  $('#news-search-form').submit(function(e){
    var q = $('#search-terms-news')
    if(q.val() == '' || q.hasClass('empty')){
      q.focus()
      return false
    }
  })

  $('input[type="text"][title]').focus(function(e){
    $(this).filter('.empty').val('').removeClass('empty');
  }).blur(function(e){
    $(this).filter(function(){return this.value == ''}).val($(this).attr('title')).addClass('empty');
  }).blur();
  
  
  $('#subscription-form').validate();
  
  
  if($('#social-links').length){
    var social_tip = $('<div id="social-tip"></div>').appendTo($('#social-links'))
    $('.social-link').hover(function(e){
      console.log($(this).html());
      social_tip.html($(this).text()).show();
    },function(e){
      social_tip.hide()
    });
    
  }
  
});


function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

