$(document).ready(function() {

	/**********
	Deal with the CROWNWeb Conferences links
	**********/
	
	$('div.photo span.imgHover').hide();
	
	$('div.photo a').bind({
		mouseenter: function(){
			if ($.support.opacity){ 
				$(this).children('span.imgHover:not(:animated)').stop(true, true).fadeIn('fast');
			}
			else {
				$(this).children('span.imgHover').show();
			}
		},
		mouseleave: function(){
			if ($.support.opacity){ 
				$(this).children('span.imgHover').stop(true, true).fadeOut('fast');
			}
			else {
				$(this).children('span.imgHover').hide();
			}
		}
	});
	
	/**********
	Slideshow controls
	**********/
	
	var slideText = $('#slideText');
	var slides = $('#slides');
	var slideWidth = $('#slideContainer').width();
	
	// Get number slides
	var numTextSlides = $(slideText).children('li').length - 1;
	var numPicSlides = $(slides).children('li').length - 1;
	if (numTextSlides == numPicSlides) {
		var numSlides = numPicSlides;
	}
	else {
		var numSlides = 0;
	}
	
	$('#control span.total').html(numSlides + 1);
	
	// Variable for current slide
	var currentSlide = 0;
	
	$('.next a').click(function() {
		if (($(this).attr('class')) != 'deactivated') {
			// Change the text
			var nextSlide = currentSlide + 1;
			$(slideText).children('li').eq(currentSlide).fadeOut('fast', function() {
				$('#slideText li').eq(nextSlide).fadeIn('slow');
			});
			
			var newMargin = (nextSlide) * slideWidth * -1;
			
			$('#slides').animate({
				left: newMargin
			}, 1000);
			
			// Set current and next images
			currentSlide = nextSlide;
			if (currentSlide >= numSlides) {
				$(this).addClass('deactivated');
			}
			$('.prev a').removeClass('deactivated');
			
			$('#control span.current').html(currentSlide + 1);
			
		}
	});
	
	$('.prev a').click(function() {
		if (($(this).attr('class')) != 'deactivated') {
			// Change the text
			var prevSlide = currentSlide - 1;
			$(slideText).children('li').eq(currentSlide).fadeOut('fast', function() {
				$('#slideText li').eq(prevSlide).fadeIn('slow');
			});
			
			var newMargin = (prevSlide) * slideWidth * -1;
			
			$('#slides').animate({
				left: [newMargin, 'swing']
			}, 1000);
			
			// Set current and previous images
			currentSlide = prevSlide;
			if (currentSlide <= 0) {
				$(this).addClass('deactivated');
			}
			$('.next a').removeClass('deactivated');
			
			$('#control span.current').html(currentSlide + 1);
			
		}
	});
	
	/**********
	Latest news nav
	**********/
	var newsContent = $('#newsContent');
	
	$('a.news').live('click', function() {
		var url = $(this).attr('href');
		$(newsContent).load(url);
		return false;		
	});

});