$(function() {
	
	/* jQuery MEDIA PLUGIN */
	$.fn.media.defaults.mp3Player = 'http://trinitylifechurch.org.uk/wp-content/themes/tlc-theme/js/mediaplayer.swf';
	$('.media').media({ width: 500, height: 20, autoplay: true, flashvars: { autostart: true }});
	
	/* MESSAGES */
	$('.play-message').removeAttr("href");
	$('.message-player').hide();
	
	$('.play-message').click(function() {
		if($(this).nextAll('.message-player').css('display') == 'none')
		{
			$('.message-player').slideUp(500);
			$(this).nextAll('.message-player').slideDown(500);
		}
	});
	
	if(window.location.hash) {
		
		$('.message-player').slideUp(500);
		$(window.location.hash + ' .message-player').slideDown(500);
	}
	
	/* SLIDESHOW */
	$(".thumb").click(function (){
		$(".thumb").removeClass("selected");
		$(this).addClass("selected");
	});
	
	
	/* FEATURE */
	$("#feature-small a").removeAttr("href");
	
	var currentFeature = 0;
	$("#feature-small a:eq(0)").addClass("current");
	var featureTimer = setTimeout(function() { changeFeature(1); }, 4000);
	
	
	$("#feature-large a").css({'position' : 'absolute', 'display' : 'none'});
	$("#feature1").css({'display' : 'block'});
	
	function changeFeature(featureNo)
	{
		if(featureNo != currentFeature)
		{
		if(featureNo > 5){ featureNo = 0; }
		
			$("#feature-small" + (currentFeature + 1)).removeClass("current");
			$("#feature-small" + (featureNo + 1)).addClass("current");
			$("#feature" + (currentFeature + 1)).fadeOut();
			$("#feature" + (featureNo + 1)).fadeIn();
			currentFeature = featureNo;
		}
		featureTimer = setTimeout(function() { changeFeature(currentFeature+1); }, 4000);
	}
	
	
	$("#feature-small a").click(function() {
		clearTimeout(featureTimer);
		var featureNo = $("#feature-small a").index(this);
		changeFeature(featureNo);
	});
	
	
	/* NAV */
	$("#nav ul > li").hover(function() {
		$(this).find('> ul').stop(true, true).slideDown(250);
	}, function() {
		$(this).find('> ul').stop(true, true).fadeOut(200);
	});
	
	$("#nav ul > li").focus(function() {
		$(this).find('> ul').stop(true, true).slideDown(250);
	}, function() {
		$(this).find('> ul').stop(true, true).fadeOut(200);
	});
	


	
});