// drop menu
// from http://net.tutsplus.com/tutorials/design-tutorials/how-to-build-and-enhance-a-3-level-navigation-menu/
var site = function() {
	this.navLi = $('#nav li').children('ul').hide().end();
	this.init();
};

site.prototype = {
 	
 	init : function() {
 		this.setMenu();
 	},
 	
 	// Enables the slidedown menu, and adds support for IE6
 	
 	setMenu : function() {
 	
 	$.each(this.navLi, function() {
 		if ( $(this).children('ul')[0] ) {
 			$(this)
 				.append('<span />')
 				.children('span')
 					.addClass('hasChildren')
 		}
 	});
 	
 		this.navLi.hover(function() {
 			// mouseover
			$(this).find('> ul').stop(true, true).slideDown('fast');
 		}, function() {
 			// mouseout
 			$(this).find('> ul').stop(true, true).hide(); 		
		});
 		
 	}
 
}

new site();


// --------------------------------------------------------------------------------------
// slide up description for home page images
$(document).ready(function(){
	$('a#details-slide').hover(function(){
		$(".boxcaption").stop().animate({top:'425px'},{queue:false,duration:280}); // animate up to
	}, function() {
		$(".boxcaption").stop().animate({top:'575px'},{queue:false,duration:160}); // animate back down to should match the css for .caption .boxcaption
	});
});


// --------------------------------------------------------------------------------------
// Andy Langton's show/hide/mini-accordion - updated 23/11/2009
// Latest version @ http://andylangton.co.uk/jquery-show-hide
// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {
// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='Show';
var hideText='Hide';
// initialise the visibility check
var is_visible = false;
// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggle').prev().append(' (<a href="#" class="toggleLink">'+showText+'</a>)');
// hide all of the elements with a class of 'toggle'
$('.toggle').hide();
// capture clicks on the toggle links
$('a.toggleLink').click(function() {
// switch visibility
is_visible = !is_visible;
// change the link depending on whether the element is shown or hidden
$(this).html( (!is_visible) ? showText : hideText);
// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next('.toggle').slideToggle('slow');
// return false so any link destination is not followed
return false;

});
});


// --------------------------------------------------------------------------------------
// remove clickable link for events
// we can add other non-clickable links via the class 80
$(document).ready(function() {
	$('#nav .page-item-80 a:first').replaceWith('<a href="#">Events</a>');
	$('#sidebar .page-item-80 a:first').replaceWith('<a href="#">Events</a>');
});


// --------------------------------------------------------------------------------------
// home page slideshow
// slideshow for home page explanation is at http://www.lateralcode.com/simple-slideshow/
$('.ppt li:gt(0)').hide();
$('.ppt li:last').addClass('last');
$('.ppt li:first').addClass('first');
$('#play').hide();
 
var cur = $('.ppt li:first');
var interval;
 
$('#fwd').click( function() {
	goFwd();
	showPause();
} );
 
$('#back').click( function() {
	goBack();
	showPause();
} );
 
$('#stop').click( function() {
	stop();
	showPlay();
} );
 
$('#play').click( function() {
	start();
	showPause();
} );
 
function goFwd() {
	stop();
	forward();
	start();
}
 
function goBack() {
	stop();
	back();
	start();
}
 
function back() {
	cur.fadeOut( 1000 );
	if ( cur.attr('class') == 'first' )
		cur = $('.ppt li:last');
	else
		cur = cur.prev();
	cur.fadeIn( 1000 );
}
 
function forward() {
	cur.fadeOut( 1000 );
	if ( cur.attr('class') == 'last' )
		cur = $('.ppt li:first');
	else
		cur = cur.next();
	cur.fadeIn( 1000 );
}
 
function showPause() {
	$('#play').hide();
	$('#stop').show();
}
 
function showPlay() {
	$('#stop').hide();
	$('#play').show();
}
 
function start() {
	interval = setInterval( "forward()", 3000 );
}
 
function stop() {
	clearInterval( interval );
}

