$(function() {
	$('#nav li a:last').css('border', 'none');
	
	// hero
	/*var scrollables = $(".scrollable").scrollable({
	  circular: true, 
	  next: '#next_arrow', 
	  prev: '#prev_arrow'
  });
	
	// fix for circular from here
	// http://flowplayer.org/tools/forum/35/40506
	scrollables.each(function() {
		var $itemsToClone = $(this).scrollable().getItems().slice(1);
		var $wrap = $(this).scrollable().getItemWrap();
		var clonedClass = $(this).scrollable().getConf().clonedClass;
		$itemsToClone.each(function() {
			$(this).clone(true).appendTo($wrap).addClass(clonedClass + ' hacked-' + clonedClass);
		});
	});*/
	
	$('.course_display').toggle(function () {
		$(this).parent().next().slideDown('medium');
		$(this).next().css('position', 'relative');		
		$(this).next().css('background-position', '-45px 13px');
		
		return false;
		
	}, function () {
		$(this).parent().next().slideUp('medium');
		
		$(this).next().css('background-position', '3px 13px');
		
	});	
	
	$('.course_arrow').toggle(function () {
		$(this).parent().next().slideDown('medium');
		$(this).css('position', 'relative');		
		$(this).css('background-position', '-45px 13px');
		
		return false;
		
	}, function () {
		$(this).parent().next().slideUp('medium');
		
		$(this).css('background-position', '3px 13px');
		
	});	
	
	/* ---- Course Search ---- */
	var courses = [];
	
	// populate courses array with values from HTML lists
	$.each($('.course_listings li'), function() {
		courses.push($(this).text());
	});
	
	// filter on submit
	$('#course_searchform').submit(function() {
		
		// reset
		$(".course_listings li").css('background', '#ffffff');
		$(".course_listings").hide();
		
		// search
		var term = $('#course_searchform #course_s').val();

		if (term === '') {
			return false;
		}
		
		var pattern = new RegExp('^'+term+'\w*', 'i');
		
		var matches = $.grep(courses, function(n, i) {
			return pattern.test(n);
		});
		
		$.each(matches, function() {
			var els = $(".course_listings li:contains('"+this+"')");
			
			els.css('background', '#c08abf');
			els.parent().parent().show();
		});
		
		return false;
		
	});
	/* ---- End Course Search ---- */
	
	$('#contact_popup').click(function() {
	  $('#overlay_container').fadeIn();
	  	  
	  return false;
	});
	
	$('#close_form').click(function() { 
  	 $('#overlay_container').fadeOut();
	     	 
	     return false;

	});
		
	// footer
	$('#footer .left ul li').not('#footer .left ul li:last').append('|');
});
