
	$(function() {
		
		// Builds the filtering URL and takes you to it
		function loadResults(page) {
			
			page = !page ? 1 : page;
			
			var month = $('select#event-month').val();
			var type = $('select#event-types').val();
			var facility = $('select#event-locations').val();
						
			window.location.href = '/events/listing/'+page+'/'+facility+'/'+type+'/'+month+'/';
		}
		
	
		// The "Go" button
		$('#event-filter').click(function(e) {
			e.preventDefault();			
			loadResults();
		});
		
		
		// Grab the pagination buttons that are "disabled" via CSS and remove functionality
		$('a.pagination,.disabled').click(function(e) {
			e.preventDefault();
		});
		
		
		// Grab the pagination buttons that aren't disabled and make them do something
		$('a.pagination:not(.disabled)').click(function(e) {
			e.preventDefault();
			
			var num = parseInt($('span#start-page').html());
			
			if ( $(this).hasClass('previous-page') ) {
				loadResults(--num);
			} else {
				loadResults(++num);
			}
		});
		
		
		// Add functionality for the breadcrumb style filter bar
		$('.month-clicker').click(function(e) {
			e.preventDefault();
			
			$('select#event-locations').val(0);	// Reset selection to the very first item in list
			$('select#event-types').val(0);	// Reset selection to the very first item in list
			
			$('select#event-month').val($(this).attr('rel'));
			loadResults();
		});
		
		$('.type-clicker').click(function(e) {
			e.preventDefault();
			
			$('select#event-month').val(0);	// Reset selection to the very first item in list
			$('select#event-locations').val(0);	// Reset selection to the very first item in list
			
			$('select#event-types').val($(this).attr('rel'));
			loadResults();			
		});
		
		$('.facility-clicker').click(function(e) {
			e.preventDefault();
			
			$('select#event-month').val(0);	// Reset selection to the very first item in list
			$('select#event-types').val(0);	// Reset selection to the very first item in list
			
			$('select#event-locations').val($(this).attr('rel'));
			loadResults();
		});
		
		$('div.socialNetworking a.delicious').deliciousLink();
		$('div.socialNetworking a.digg').diggLink();
			
	});
