var announcementBox, bindFilterEvents, checkWindowSize, dCheckWindowSize, sidebarPromo, updateMovieListing;

updateMovieListing = function() {
  if (!$('#movie-listing').is(':visible')) window.location.href = "#!/";
  return tgv.movies.list.update();
};

bindFilterEvents = function() {
  $('#filter-date li').click(function(e) {
    $(this).addClass('active').siblings().removeClass('active');
    updateMovieListing();
    return e.preventDefault();
  });
  return $('#filter_cinema').change(function(e) {
    return updateMovieListing();
  });
};

checkWindowSize = function() {
  var self, width;
  self = this;
  width = $(window).width();
  $('body').removeClass('desktop tablet mobile');
  if (width > 1024) {
    return $('body').addClass('desktop');
  } else if (width <= 1024 && width > 480) {
    return $('body').addClass('tablet');
  } else if (width <= 480) {
    return $('body').addClass('mobile');
  }
};

dCheckWindowSize = _.debounce(checkWindowSize, 300);

sidebarPromo = function() {
  if ($('.promo').length > 0) {
    $('.promo li a').nyroModal({
      filledContent: function() {
        $('.nyroModalBg').css({
          'zIndex': '1400'
        });
        return $('.nyroModalImg').css({
          'zIndex': '1500'
        });
      }
    });
    return $('.promo-pane-toggle').live('click', function() {
      if ($(this).hasClass('active')) {
        $(this).parent().animate({
          'right': '-200px'
        }, 300);
        return $(this).removeClass('active');
      } else {
        $('.promo .active').removeClass('active');
        $(this).parent().animate({
          'right': '0'
        }, 300).siblings('.promo').animate({
          'right': '-200px'
        }, 300);
        return $(this).addClass('active');
      }
    });
  }
};

announcementBox = function() {
  if ($('#announcement-box .content').html() !== '') {
    $('#announcement-box').removeClass('hidden');
  }
  if ($('#announcement-box').length > 0) {
    $('#announcement-box .close').click(function(e) {
      $(this).parent().animate({
        bottom: -500
      }, 400, function() {
        return $(this).addClass('hidden');
      });
      return e.preventDefault();
    });
    return $('.mobile #announcement-box .close').click(function(e) {
      return $(this).parent().addClass('hidden');
    });
  }
};

$(function() {
  if ($('#sorter').length > 0) {
    $(window).resize(dCheckWindowSize);
    checkWindowSize();
    bindFilterEvents();
    sidebarPromo();
    announcementBox();
    tgv.user.info = new tgv.user.UserInfo();
    tgv.movies.list = new tgv.movies.MoviesCollection();
    tgv.cinemas.list = new tgv.cinemas.Cinemas();
    tgv.session = new tgv.Controller();
    Backbone.history.start();
    return tgv.movies.list.update();
  }
});

