$(document).ready(function() {
  //function doResize() {
  //  var width = $(window).width();
  //  var height = $(window).height();
  //  var wrapperWidth = $('#wrapper').outerWidth();
  //  var wrapperHeight = $('#wrapper').outerHeight();
  //  $('#wrapper').css({
  //    position: 'absolute', 
  //    left:     wrapperWidth < width ? (width / 2) - (wrapperWidth / 2) : 0,
  //    top:      wrapperHeight < height ? (height / 2) - (wrapperHeight / 2) : 20
  //  });
  //}
  //
  //doResize();
  //$(window).resize(doResize);
  
  $('#newsletter form').ajaxForm(function() {
    $('#newsletter').addClass('submitted');
  });
  
  $('#newsletter form a').click(function(event) {
    event.preventDefault();
    $(this).parents('form').submit();
  });
  
  $('a[rel=external]').click(function(e) {
    e.preventDefault();
    window.open($(this).attr('href'), '_blank')
  });
  
  $('input.default').focus(function(e) {
    $(this).val('').removeClass('default');
  });

  $('a#poster').click(function(e) {
    e.preventDefault();
    window.open($(this).attr('href'), 'poster', 'width=1000px,height=707px,toolbar=no,location=no,status=no');
  });
  
  $('a#videotrailer-thumb').click(function(e) {
    e.preventDefault();
    $('#videotrailer-overlay').show();
  })
  
  $('a#videotrailer-close').click(function(e) {
    e.preventDefault();
    $('#videotrailer-overlay').hide();
  })
  
  var pulseInterval;
  function animateTicketMessage() {
    $('#message strong')
      .css({width:$('#message strong').width()})
      .typewriter(function() {
        var newColor = '#fff';
        function pulseTickets() {
          $('#message').stop(true).animate({color: (newColor == '#fff' ? '#EDDD93' : '#fff')}, {duration: 350, easing: 'easeOutQuad'});
          $('#message strong').stop(true).animate({color: newColor}, {duration: 350, easing: 'easeOutQuad'});
          newColor = newColor == '#fff' ? '#EDDD93' : '#fff';
        }
        pulseTickets();
        pulseInterval = setInterval(pulseTickets, 700);
      });
  }
  animateTicketMessage();
  
  setInterval(function() {
    clearInterval(pulseInterval);
    animateTicketMessage();
  }, 7000)

  
  
  var interval;
  function animateTickets() {
    interval = setInterval(function() {
      var notActive = $('#ticket-info li').not('.active').fadeIn(400);
      var active = $('#ticket-info li.active').fadeOut(400);
      notActive.addClass('active');
      active.removeClass('active');
    }, 3000);
  }
  $('#ticket-info li a').hover(function() {
    clearInterval(interval);
  }, function() {
    animateTickets();
  });
  animateTickets();
});