$(document).ready(function(){

	$(".sampleTag").bind('click', function(e){
		var text = $(this).text();
		if ($("#EventTags").text() != '')
		{
			text = $("#EventTags").text() + ', ' + text;
		}
		$("#EventTags").text(text);
		return false;
	});

	$(".tagFilter").bind('click', function(e){

		var visibility = this.checked;
		var tag = this.value;

		// Now show or hide the appropriate elements
		$(".cell-data > a[rel*="+this.value+"]").each(function(i){
			// If we just checked the box, then these should be visible
			if(visibility)
			{
				$(this).show();
			}
			else
			{
				// Look at each of the ENABLED tags, if any of them match this
				// event, then we can't hide it. Otherwise, hide the little toad.
				var tags = $(this).attr('rel');
				var hide = true;

				// Find all the tags that are checked, and iterate through them
				$(".tagFilter:checked").each(function(i){

					// Now see if this Enabled tag is a match to the tags
					// for this link. If so, then we should still keep it visible
					// and thus exit the loop.
					var searchValue = this.value;
					if(tags.indexOf(searchValue) != -1)
					{
						// Found a match, do nothing!
						hide = false;
					}
				});

				if(hide)
				{
					$(this).hide();
				}
			}

		});
	});
});
