var _gaq = [['_setAccount', 'UA-11358954-1'], ['_trackPageview']];
(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = (document.location.protocol == 'https:' ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

$(document).ready(function() {
  $.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?screen_name=abramsresearch&count=20&callback=?', function(json) {
    var output = '';
    $.each(json, function(i, tweet) {
      output += '<div class="entry"><span>' + tweet.text + '</span></div>';
    });
    $('#tweet_stream').html(output);
    
    $('#social-megawrapper span').each(function() {
      var height = $(this).parent().height();
      var elheight = $(this).height();
      $(this).css({'top': (height - elheight) / 2.2});
    });

    $('#social-megawrapper').scrollable({
      vertical: true,
      next: '.next',
      prev: '.previous',
      items: '.social-entries',
      speed: 200
    });
  });

  $('#follow-us').hover(
    function() {
      $('#follow-us-dropdown').css({height: 45});
      $('#follow-us-dropdown').stop().slideDown(300);
    },
    function() {
      $('#follow-us-dropdown').stop().slideUp(300);
    }
  );

  $('#follow-us-dropdown img').hover(
    function() {
      $(this).fadeTo(70, 0.6);
    },
    function() {
      $(this).fadeTo(70, 1);
    }
  );

  $('#whitepapers-sidebar').hover(
    function() {
      $('#whitepapers-dropdown').slideDown();
    },
    function() {
      $('#whitepapers-dropdown').slideUp();
    }
  );

  $('#slider-megawrapper').scrollable({
    next: '.slider-right-arrow',
    prev: '.slider-left-arrow',
    items: '.slider-entries',
    speed: 500
  });
  
  $('.autoclear').each(function() {
    $(this).attr('initvalue', $(this).val());
  });
  $('.autoclear').focus(function() {
    if ($(this).val() == $(this).attr('initvalue')) $(this).val('');
  });
  $('.autoclear').blur(function() {
    if ($(this).val() == '') $(this).val($(this).attr('initvalue'));
  });
});
