//Crossfade Slideshows

jQuery(document).ready(function() {
	jQuery('.next, .prev').click(function() {
		var direction = jQuery(this).attr('class');
		clearInterval(slideshow);
		slideSwitch(direction);
	});
	if(jQuery('.gallery').children().length>1)
	var slideshow = setInterval(function(){slideSwitch('next')}, 4000 );
	
	jQuery('.loginlinks li').click(function() {
		var slideclass = jQuery(this).attr('class');
		jQuery(this).css('color', '#000').siblings().css('color', '#3f7ab0');
		jQuery('.loginbox .slide').fadeOut();
		jQuery('.loginbox .' + slideclass ).fadeIn();
	});
	
	jQuery('.calendar div').hover(
		function() {
			var eventids = jQuery(this).attr('id');
			if(typeof(eventids)!= 'undefined' && eventids.length > 0){
				var events = eventids.split('-');
				jQuery('.events').hide();
				for (var x = 0; x <= events.length; x++) {
					jQuery('#event'+events[x]).show();
				}	
			} else{
				jQuery('.events').show();
			}
							
		}
	);
	
});

function slideSwitch(direction){
		var gallery = jQuery('.gallery');
		var first = gallery.children().first();
		var last = gallery.children().last();
		if (direction == 'next') last.fadeOut('slow', function(){last.insertBefore(first).show();});
		else first.hide().insertAfter(last).fadeIn('slow');
}

//facebook like button
(function(d, s, id) {
	var js, fjs = d.getElementsByTagName(s)[0];
  	if (d.getElementById(id)) {return;}
  	js = d.createElement(s); js.id = id;
  	js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
  	fjs.parentNode.insertBefore(js, fjs);
	}
	(document, 'script', 'facebook-jssdk')
);
