/*
Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('#title');
Cufon.replace('.cs-overlay');
*/

$(document).ready(function() {
  
  $(".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 a').each(function(){
    var $this = $(this);
    $this.css({position:'absolute', top:'50%', left:'6px',  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();
  
  


  $('#quick-links-trigger').toggle(function(e){
    e.preventDefault()
    $('#quicklinks').show()

    $($.browser.webkit ? 'body' : 'html').animate({ scrollTop: $(document).height()   }, 1500);
    //$('body').animate({ scrollTop: $(document).height()   }, 1500);
    $(this).children('span').html('-');
  }, function(e){
    $('#quicklinks').slideUp(500)
    $(this).children('span').html('+');
  });

});

