<% content_for :footer do %>
	<script type="text/javascript">
		<% unless Event.last.blank? %>
		
			var last_event = "<%= Event.last_event_timestamp %>";
			$('div#wrapper').attr({last_event: last_event});
		
      setInterval (function () {
        $.get('/events/last', function(data) {

					var old_id = $('div#wrapper').attr('last_event');
					var page = parseInt($('.pager li.active a').html());

					if (old_id != data.time) {
						$.get('events/since', {timestamp: old_id}, function (data) {
							if (data.events && data.events.length != 0) {
								if (page <= '1') { 
									
									if ($('div.new_events').length == 0) {
										
										$('#events').prepend('<div class="note new_events"><strong class="new_event_count">'+data.events.length+'</strong> New Events Are Available Click here To View Them.</div>');
										
									} else {
										
										var new_count = parseInt($('#events div.new_events strong.new_event_count').html()) + data.events.length;
										$('#events div.new_events').html('<strong class="new_event_count">'+new_count+'</strong> New Events Are Available Click here To View Them.');
										
									};

									$('#events ul.table div.content').prepend(Snorby.templates.event_table(data));
								};
								Snorby.notification({title: 'New Events', text: data.events.length + ' Events Added.'});
							};
            });

						$('div#wrapper').attr('last_event', data.time)
					};
				});
			}, 50000);
		<% end %>
	</script>
	
<% end %>

<% content_for :footer do %>
	<%= render :partial => 'layouts/notify' %>
<% end %>

<%= title "Listing Events <i>(#{@events.pager.total} unclassified events)</i>".html_safe, 'Listing Events' do -%>
	<%= menu_item "Hotkeys", hotkey_events_path, 'events/keyboard.png', :class => 'snorbybox' %>
	<%= render :partial => 'events/menu' %>
<%- end -%>

<%= render :partial => 'events/events' %>

<%= render :partial => 'events/hotkeys' %>
