$(document).ready(function() {
	// Get any available filter categories and enable the onclick.
	if ($("#categoryFilter .category")) {
		$("#categoryFilter .category").click(function() {
			// Get the clicked filter box.
			var id	= 'filterBox' + this.id.replace('filter', '');

			// Get the position.
			var pos	= $('#' + this.id).position();
			$('#' + id).css('top', pos.top + 30);
			$('#' + id).css('left', pos.left);

			// Iterate through any other filter boxes and hide.
			$('.filterBox').each(function(i, v) {
				if (v.id == id) {
					return;
				}
				if ($('#' + v.id).is(":shown")) {
					$('#' + v.id).slideUp();
				}
			});

			// Check its visibility. Show when hidden and vice-versa.
			if ($('#' + id).is(":hidden")) {
				$('#' + id).slideDown();
			} else {
				$('#' + id).slideUp();
			}
		});

		$(document).bind('click', function(e) {
			// Hide the filter boxes when a click is made outside the box.
			var $clicked	= $(e.target);
			if (!$clicked.is('.filterBox') && !$clicked.parents().is('.filterBox') && !$clicked.is('.category')) {
				$('.filterBox').each(function(i, v) {
					if ($('#' + v.id).is(":shown")) {
						$('#' + v.id).slideUp();
					}
				});
			}
		});

		// Add the pop up event to the checkmarks links.
		$('#catCheckmarks a').each(function() {
			$('#' + this.id).click(function() {
				window.open(this.href + '?popup=true','PopUp','width=600,height=350,resizable=no,scrollbars=yes,menubar=no,toolbar=no,left=150,top=175,screenX=150,screenY=175');
				return false;
			});
		});

		// Add the pop up event to the checkmarks links.
		$('#ppcLanding .checkmarksWrap a').each(function() {
			if (this.id != '') {
				$('#' + this.id).click(function() {
					window.open(this.href + '?popup=true','PopUp','width=600,height=350,resizable=no,scrollbars=yes,menubar=no,toolbar=no,left=150,top=175,screenX=150,screenY=175');
					return false;
				});
			}
		});
	}
});
