$(function(){
    $("#fleet dd").not("#fleet dd dd").hide();
    $('#fleet dt').click(function() {
        $(this).next().toggle(200);
        return false;
    });
    $("#licensing dd").hide();
    $('#licensing dt').click(function() {
        $(this).next().toggle(200);
        return false;
    });
	$(".slideshow figure:not(:first-child)").hide();
    
});

$(window).load( function() {
    // initialize    
    var tallestimg = null;
    $('.slideshow figure img').each(function(index) {
        if ($(this).height() >= tallestimg ) {
            tallestimg = $(this).height();
        }
    });
    var tallestcaption = null;
    $('.slideshow figure figcaption').each(function(index) {
        if ($(this).height() >= tallestcaption ) {
            tallestcaption = $(this).outerHeight(true);
        }
    });    

    var myheight = tallestimg +tallestcaption;
	var current = 1;
	var next = current+1;
	var total = $(".slideshow").children().length;

    $(".slideshow").css({'position':'relative', 'height': myheight});
	$(".slideshow figure").css({'position':'absolute','top':'0'});
    
	var timer = setInterval( function() { slide( 'default',current); }, 5000 );
	var running = 1;
	
	function stopTimer(){
		clearInterval(timer);	
	};
	
	// next
	function slide(index){
		//next
		$(".slideshow figure:nth-child(" + current + ")").fadeOut('slow');
		if( current == total ){	current=0;	} 
		next = current+1;	
		$(".slideshow figure:nth-child(" + next + ")").fadeIn('slow');
		current++;
	}
});

