/* Author: The Foundry Communications Ltd */

$(document).ready(function() {
	
	// ---------------------------------------------------------------- Homepage image cycle
	
	if ($("body.home").length) {
		
		$("ul#slides").before('<div id="nav"></div>').cycle({
			fx: 'fade',
			pause: 8,
			pager:  '#nav'
		});

		$("#nav a").wrapInner("<span></span>");
		
	}
	
	// ---------------------------------------------------------------- People filter
	
	if ($("body.people").length) {
		
		jQuery.expr[':'].Contains = function(a,i,m){
		      return (a.textContent || a.innerText || "").toUpperCase().indexOf(m[3].toUpperCase())>=0;
		};


		  function listFilter(header, list) { // header is any element, list is an unordered list

			$("select").change( function () {
				var filter = $(this).val();
				if(filter) {
					// this finds all links in a list that contain the input,
					// and hide the ones not containing the input while showing the ones that do
					$(list).find("a.team:not(:Contains(" + filter + "))").parent().fadeTo("slow", 0.20);
					$(list).find("a.team:Contains(" + filter + ")").parent().fadeTo("fast", 1.0);
				} else {
					$(list).find("li").fadeTo("fast", 1);
				}
				return false;
			});

			$("a.filterlink").click(function() {
				var filter = $(this).attr("title");
				if(filter != "View everyone") {
					// this finds all links in a list that contain the input,
					// and hide the ones not containing the input while showing the ones that do
					$(list).find("a.team:not(:Contains(" + filter + "))").parent().fadeTo("slow", 0.20);
					$(list).find("a.team:Contains(" + filter + ")").parent().fadeTo("fast", 1.0);
				} else {
					$(list).find("li").fadeTo("fast", 1.0);
				}
				return false;
			});

		  }

		  $(function () {
		    listFilter($("#header"), $("#list"));
		  });
		
	}
	
	// ----------------------------------------------------------------
	
});






















