/* ===============================================
Slide Show
=============================================== */

function slideSwitch() {
    var $active = $('.slideshow IMG.active');

    if ( $active.length == 0 ) $active = $('.slideshow IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('.slideshow IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
});

/* ===============================================
Image Replacement
=============================================== */
  
$(document).ready(function(){
    $(".displayHeader h2").append('<em></em>')
    $(".display a").click(function(){
        var largePath = $(this).attr("href");
        var largeAlt = $(this).attr("title");
        $(".largeImg").attr({src: largePath, alt: largeAlt });
        $(".displayHeader h2 em").html(largeAlt); return false;
        });
    });

/* ===============================================
Collapseable Panels
=============================================== */

$(document).ready(function(){
	
	//hide display after the first one
	$(".accordianList .display:gt(0)").hide();
	
	//hide message li after the 10th
	$(".accordianList li:gt(20)").hide();

	
	//toggle display
	$(".messageHeader").click(function(){
		$(this).next(".display").slideToggle(500)
		return false;
	});

	//collapse all messages
	$(".collapseAll").click(function(){
		$(".display").slideUp(500)
		return false;
	});

	//show all messages
	$(".show_all_message").click(function(){
		$(this).hide()
		$(".show_recent_only").show()
		$(".accordianList li:gt(4)").slideDown()
		return false;
	});

	//show recent messages only
	$(".show_recent_only").click(function(){
		$(this).hide()
		$(".show_all_message").show()
		$(".accordianList li:gt(20)").slideUp()
		return false;
	});

});

// LIGHTBOX

$(function(){
    $('#gallery a').lightBox();
});