/* Author: Lee Boyce*/
/* Home slideshows */
function onAfter(curr, next, opts) {
    var index = opts.currSlide;
    $('#prev')[index == 0 ? 'hide' : 'show']();
    $('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
}
$('#slideshow').cycle({ 
    fx:     'fade',
    speed: '800',
    prev:   '#prev-btn', 
    next:   '#next-btn',
    before: onBefore, 
    after:   onAfter, 
    timeout: 6200 
});
function onBefore(){
	$('.large-copy').fadeOut(200);
}
function onAfter() { 
	$('.large-copy').fadeIn(200);
    $('.large-copy').html(this.alt);
}
/* Album accordions */
$(document).ready(function() {
	$('div.accordionButton').click(function() {
		$('div.accordionContent').slideUp('normal');	
		$(this).next().slideDown('normal');
	});
	$("div.accordionContent").hide();
	$("div.active-cat").show();
});
// Image Gallery
// Lee Boyce
// www.leeboyce.co.uk
$(function(){
	$numberOfImages = $("ul.thumbnails").children().length;
	$clickedAnImage = 0;
	$slideCounter = 1;
	var currentShown;
	var viewerToShow;	
	var cs;  
	$("img.thumbnail").click(function(){
		$imgclicked = $(this);
		$clickedAnImage = 1;
		var imgToShow = $imgclicked.attr("src");
		var currentShown = $imgclicked.attr("id").split('-');
		var cs = currentShown[1];
		$slideCounter = currentShown[1];
		$("#viewport").css('background','url(' + imgToShow + ')');
		var newTitle = $("#thumbnail-"+$slideCounter).attr("title");
		var newCaption = $("#thumbnail-"+$slideCounter).attr("alt");
		$("h1.caption-title").text(newTitle);
		$("p.caption-para").text(newCaption);
	});	
	$("#gallery-prev").click(function(){
		if ($slideCounter > 1){
			$prev = parseInt($slideCounter)-parseInt(1);
			$slideCounter = $prev;
			var cs = $prev;
			var imgToShow = $("#thumbnail-"+ $slideCounter).attr("src");
			var newTitle = $("#thumbnail-"+$slideCounter).attr("title");
			var newCaption = $("#thumbnail-"+$slideCounter).attr("alt");
			$("#viewport").css('background','url(' + imgToShow + ')');
			$("h1.caption-title").text(newTitle);
			$("p.caption-para").text(newCaption);
		}
	});		
	$("#gallery-next").click(function(){
		if ($slideCounter < $numberOfImages){
			$next = parseInt($slideCounter)+parseInt(1);
			$slideCounter = $next;
			var cs = $next;
			var imgToShow = $("#thumbnail-"+ $slideCounter).attr("src");
			var newTitle = $("#thumbnail-"+$slideCounter).attr("title");
			var newCaption = $("#thumbnail-"+$slideCounter).attr("alt");
			$("#viewport").css('background','url(' + imgToShow + ')');
			$("h1.caption-title").text(newTitle);
			$("p.caption-para").text(newCaption);
		}				
	});
});
$(function(){
	$("#gallery-show-thumbs").click(function(){
		$(this).find("#show").toggle();
		$(this).find("#hide").toggle();
		$("#thumbnail-container").fadeToggle();
	});
});
// Initiation
$(document).ready(function() {
	$("#images-loading").fadeOut(400);
	$("#thumbnail-container").hide();
});
