jQuery(document).ready(function()
	{
	var minutesFlag = false;

	jQuery('#downloads-list li h3').each(function()
		{
		if (this.innerHTML.substr(0,7).match(/\bMinutes\b/))
			{
			minutesFlag = true;
			}
		});

	if (minutesFlag)
		{
		jQuery('#list-section').prepend(
			'<div id="downloads-list-filter">\
				<form action="#" method="post">\
					<fieldset>\
						<div class="checkbox">\
							<label for="filter_minutes">Show minutes</label>\
							<input type="checkbox" id="filter_minutes" name="filter_minutes" checked="checked" />\
						</div>\
						<div class="checkbox">\
							<label for="filter_others">Show other items</label>\
							<input type="checkbox" id="filter_others" name="filter_others" checked="checked" />\
						</div>\
					</fieldset>\
				</form>\
			</div>');

		jQuery('#filter_minutes').click(function()
			{
			if (this.checked)
				{
				document.cookie = 'filterMinutes=1';
				jQuery('#downloads-list li h3').each(function()
					{
					if (this.innerHTML.substr(0,7).match(/\bMinutes\b/)) this.parentNode.parentNode.style.display = 'list-item';
					});
				}
			else
				{
				document.cookie = 'filterMinutes=0';
				jQuery('#downloads-list li h3').each(function()
					{
					if (this.innerHTML.substr(0,7).match(/\bMinutes\b/)) this.parentNode.parentNode.style.display = 'none';
					});
				}
			});

		jQuery('#filter_others').click(function()
			{
			if (this.checked)
				{
				document.cookie = 'filterOthers=1';
				jQuery('#downloads-list li h3').each(function()
					{
					if (!this.innerHTML.substr(0,7).match(/\bMinutes\b/)) this.parentNode.parentNode.style.display = 'list-item';
					});
				}
			else
				{
				document.cookie = 'filterOthers=0';
				jQuery('#downloads-list li h3').each(function()
					{
					if (!this.innerHTML.substr(0,7).match(/\bMinutes\b/)) this.parentNode.parentNode.style.display = 'none';
					});
				}
			});
		}
	});

