$(document).ready(function(){
	$('#background-image img:not(":first")').hide();
	var count=0;
	var countImages = $('#background-image img').size();

	if(countImages>1){
		setInterval(nextImage,6000); //The number here dictates the length of time between the animation
	}

	function nextImage() {
		$('#background-image img:eq('+count+')').fadeOut(1500); //Length of FadeOut transition
		if(count<countImages-1){
			count++;
		} else {
			count=0;
		}
		$('#background-image img:eq('+count+')').fadeIn(1500); //Length of FadeIn transition
	}
	
	

	$('.container').prepend("<p class='container-hide'>HIDE X</p>");

	$('.scrolling-news').vTicker({
		speed: 500,
		pause: 7000,
		showItems: 1,
		animation: 'fade',
		mousePause: false,
		height: '15px',
		direction: 'up'
	});

	$("p.container-hide").click(function(){		
		oldHeight = $(".container").height();

		var pos = $(".container").offset();		
		var newHeight = $("#background-image img:first").height() - pos.top - 30;				

		$("#sub-nav").animate({
			opacity: '0'
		}, 'slow');
		$(".container").animate({
			opacity: '0'
		}, 'slow', function(){
			$(".container-content, .container-footer, p.container-hide").hide();
			$("p.container-show").fadeIn();
			$(this).animate({
				height: newHeight
			}, 'slow');
		}); 
		
		
	});
	
	/*if($('body').attr('class') == 'home')
	{
		$('.container-show').hide();
		$('.container').css({'height' : '558', 'display' : 'none'});
		$('.container').fadeIn(2500);
	}*/

	$("p.container-show").click(function(){
		$("p.container-show").fadeOut();	
		$(".container").animate({
			height: oldHeight
		}, 'slow', function(){
			$("#sub-nav").animate({
				opacity: '1'
			}, 'slow');
			$(this).animate({
				opacity: '1'
			}, 'slow');
			$(".container-content, .container-footer, p.container-hide").show();
		});		
	});	

	$("#signup img#signup-title").click(function(){
		var pos = $("#signup-slide").attr('class');	
		if(pos == "closed"){	
			$("#signup-slide").animate({
				width: '230px'
			}, 'fast');
			$("#signup").animate({
				width: '300px'
			}, 'fast');
			$("#signup-slide.closed").removeClass();
			$("#signup-slide").addClass("open");	
		}
		if(pos == "open"){	
			$("#signup-slide").animate({
				width: '0'
			}, 'fast');
			$("#signup").animate({
				width: '100px'
			}, 'fast');
			$("#signup-slide.open").removeClass();
			$("#signup-slide").addClass("closed");	
		}
	});

	$("#enquiry img#enquiry-title").click(function(){
		window.location = "contact.php";
	});	

	$("#video-side img#video-side-title").click(function(){
		window.location = "video.php";
	});	


	$("#large-content h4").click(function(){
		var pos = $("#large-content").attr('class');		
		if(pos == "up"){
			$("#large-content").animate({
				height: '43px',
				top: "78px"
			}, 'slow');
			$("#large-content.up").removeClass();
			$("#large-content").addClass("down");					
		}
		if(pos == "down"){			
			$("#large-content").animate({
				height: '552px',
				top: "78px"
			}, 'slow');
			$("#large-content.down").removeClass();
			$("#large-content").addClass("up");			
		}
	});

});
