jQuery(document).ready(function($){  
  $('a[class*=timeago], span[class*=timeago]').livequery(function() {
    $(this).timeago();
  });
  
  $.each($('input.prompt'), function() {
     $(this).val($(this).attr('title')).addClass('prompted')
      .focus(function() {
        if($(this).val() == $(this).attr('title')) $(this).val('').toggleClass('prompted');
      })
      .blur(function() {
        if($(this).val() == '') $(this).val($(this).attr('title')).toggleClass('prompted');
      })
      
  });
  
  $('img.close-button').click(function() {
    $(this).parent().toggle();
    });
    
  // $('ul.tweets li.status').click(function(){
  //   url = $(this).children('span.meta').children('a.timeago').attr("href");
  //   window.location = url;
  // });
  
  $("#tweetstream").tweet({
    url: "http://search.twitter.com/search?q=tweetsaver",
    username: "tweetsaver",
    join_text: "",
    show_user: true,
    avatar_size: 32,
    count: 5,
    loading: "loading tweets..."
  });
  
  $('.flash.success, .flash.error, .flash.notice').animate({top: "-50px"}, 1000);
  $('.flash.success, .flash.error, .flash.notice').oneTime(10000, function(){
    $(this).animate({ top: "-170px"},1000);
  });
  
  $('a.close').click(function(){
    clearTimeout();
    $(this).parent().animate({ top: "-170px"},1000);
  });
  
  $('a.actionlink').click(function(){
    $(this).siblings($('.actionform')).toggle("slow");
  });
  
  $('form.new_user .trigger').focus(function(){
    var div = $(this).attr('id');
    var pop = '.'+div
    $(pop).css({ 'display' : 'block', 'opacity' : '0'});
    $(pop).animate({
      left: "-325px",
      opacity: 0.90,
      display: "block"
    }, 500);
  });// .blur(function(){
  //       var div = $(this).attr('id');
  //       var pop = '.'+div
  //       $(pop).animate({
  //         left: "-295px",
  //         opacity: 0,
  //         display: "none"
  //       },500);
  //     });
  
  
  
  // $('a.system-tags-toggle').click(function() {
  //   $('li a.hashtag').toggle();
  //   $(this).toggleClass('show');
  //   if ($(this).hasClass('show')) {
  //     $(this).text('show hashtags');
  //   }
  //   else
  //   {
  //     $(this).text('hide hashtags');
  //   }
  //   return false;
  // });
  
  ///////////////////////////////////
  // Google Analytics Event Tracking
  ///////////////////////////////////
  
  $('ul#nav li a').livequery('click',function(event){
    pageTracker._trackEvent('Nav Link', 'Click', $(this).attr('id'));
  });
  
  $('a#index-get-started-button').livequery('click',function(event){
    pageTracker._trackEvent('Button', 'Click', $(this).attr('id'));
  });
  
  $('a#learn-more-link').livequery('click',function(event){
    pageTracker._trackEvent('Button', 'Click', $(this).attr('id'));
  });
  
  $('a#about-pricing-button').livequery('click',function(event){
    pageTracker._trackEvent('Button', 'Click', $(this).attr('id'));
  });
  
  $('a#pricing-get-started').livequery('click',function(event){
    pageTracker._trackEvent('Button', 'Click', $(this).attr('id'));
  });
  
  $('.planlist .plan h3 a').livequery('click',function(event){
    pageTracker._trackEvent('Plan Subscribe', 'Click', $(this).attr('id'));
  });
  
  $('.planlist .plan p a').livequery('click',function(event){
    pageTracker._trackEvent('Plan Subscribe', 'Click', $(this).attr('id'));
  });
  
  $('a#twitter-acct-conn-link').livequery('click',function(event){
    pageTracker._trackEvent('External Link', 'Click', $(this).attr('id'));
  });
  
  ///////////////////////////////////
  // qTIPs
  ///////////////////////////////////
  
  $('.cancel-account').qtip({
      position: {
        corner: { target: 'topMiddle', tooltip: 'bottomMiddle'}
      },
      style: {
        name: 'red',
        tip: { // Now an object instead of a string
                 corner: 'bottomMiddle', // We declare our corner within the object using the corner sub-option
                 size: {
                    x: 20, // Be careful that the x and y values refer to coordinates on screen, not height or width.
                    y : 8 // Depending on which corner your tooltip is at, x and y could mean either height or width!
                 }
        }
      },
      show: {
        effect: { type: 'fade', length: '300'}
      },
      hide: {
        effect: { type: 'fade', length: '300'}
      },
      content: 'The account cancellation process is not quite automated yet. If you would like to cancel your account, please email bradley@tweetsaver.com for instructions. Thank you!'
  });
  
});