$(document).ready(function() {
  $("#tweet-out-link .toggle-tweet-out-box").click(function(e) {
    e.preventDefault();
    $('.tweet-out-box').toggle();
  });

  $("textarea#status").keypress(function() {
    if($(this).val().length > 140) {
      $(this).addClass('invalid');
    } else {
      $(this).removeClass('invalid');
    }
  });

  $("#post-on-twitter").click(function(e) {
    var regEx = new RegExp(strSubject.toLowerCase().replace(/ /g,''), "g")
    if(!regEx.test($("#status").val().toLowerCase().replace(/ /g,''))) {
      e.preventDefault();
      $("#status").addClass('invalid');
      alert("Your tweet must include the word '" + strSubject + "' in your tweet for it to count as a review!");
    } else {
      $("#status").removeClass('invalid');
      $("#status").val($("#status").val() + " (posted on " + strSiteShortURL + ")");
      $(".tweet-out-box form").submit();
    }
  });
  
  $(".labelled").focus(function(e) {
      this.value = "";
      $(this).removeClass('labelled');
      $(this).unbind('focus');
  });
  
  if ($.browser.msie) {
    $('.fade').removeClass('fade');
    $('dissappear').removeClass('dissappear');
  } else {
    $('.tweet').live('mouseover', function() {
      $('#' + $(this).attr('id') +' .fade').stop().animate({'opacity': 1}, 500);
      $('#' + $(this).attr('id') +' .dissappear').stop().animate({'opacity': 1}, 500);
    });
    
    $('.tweet').live('mouseout', function() {
      $('#' + $(this).attr('id') +' .fade').stop().animate({'opacity': 0.2}, 500);
      $('#' + $(this).attr('id') +' .dissappear').stop().animate({'opacity': 0}, 500);
    });
  }
  
  $('.nw').attr('target','_blank');
  $('img.nw').parent().attr('target','_blank');
});