jQuery.fn.exists = function(){return jQuery(this).length>0;}

$(function() {

  // CLEARABLE INPUT VALUES FUNCTIONALITY
  // ====================================================================================
  $(".clearable").focus(function() {
    var el = $(this);
    if (el.val() == el.attr('title')) {
      el.val('');
    }
  });

  $(".clearable").blur(function() {
    var el = $(this);
    if (el.val() === '') {
      el.val(el.attr('title'));
    }
  });


  // MOVE INPUT TYPE HIDDEN VISUALLY OFF THE PAGE
  // ====================================================================================
  $('input[type="hidden"]').css({ 'position' : 'absolute', 'top' : '0', 'left' : '-9999em' });

  if ($('div.tweet').exists()) {
    var twitter_handle = 'lia_sophia';
    var join_template = 'tweet via <a href="http://twitter.com/' + twitter_handle + '">@' + twitter_handle + '</a>';
    $("div.tweet").tweet({
      join_text: "auto",
      username: twitter_handle,
      avatar_size: 48,
      count: 1,
      template: "{avatar}{text}{time}",
      auto_join_text_default: join_template,
      loading_text: "loading tweets..."
    });
  }
});

