var redux = {
	init: function() {
		// make checkboxes active
		$('#sorting-bar input:checkbox').click(redux.filterPhotos);
		
		// run on load in case boxes are checked from a reload or clicking back
		redux.filterPhotos();
	},
	
	filterPhotos: function() {
		// get the currently checked boxes
		var locations = $('#sort1 input:checkbox:checked');
		var specialties = $('#sort2 input:checkbox:checked');

		// get the names of each of the selected location filters
		var location_filters = [];
		locations.each(function(index, value) {
			location_filters.push(value.id.replace('-check', ''));
		});

		// get the names of each of the selected specialty filters
		var specialty_filters = [];
		specialties.each(function(index, value) {
			specialty_filters.push(value.id.replace('-check', ''));
		});

		// setup some variables to use for showing/hiding of photos
		var display = false;
		var photo = null;

		// check each photo to see if it should be displayed based on the filters
		$('.photos li').each(function() {
			display = true;
			photo = $(this);

			// check each location filter to see if the class exists
			if (location_filters.length > 0) {
				display = redux.hasFilter(photo, location_filters);

				// check if the location and specialty match
				if (display && specialty_filters.length > 0) {
					display = redux.hasFilter(photo, specialty_filters);
				}		

			// only specialty filters were selected so check if the class exists
			} else if (specialty_filters.length > 0) {
				display = redux.hasFilter(photo, specialty_filters);
			}

			// show or hide the individual photo
			photo.toggle(display);
		});
	},
	
	// helper function to determine if photo has a filter 
	hasFilter: function(photo, filters) {
		var result = false;
		
		$.each(filters, function(i, filter) {
			if (photo.hasClass(filter)) {
				result = true;
				return false;
			}
		});

		return result;
	}
};

$(document).ready(redux.init);