/* site_functions.js
 * put site specific javascript functions here
 * is already included in header.tpl
 */
// SLIDESHOW. Speed is controlled through JS, but dimensions are controlled through CSS.
function slideSwitch($nextSlide) {
        jQuery('.slideshow').each(function(i){
                clearInterval(switchSlide);
                        
                if ($(this).children().size() > 1) {
                        var $active = $(this).children('li.active');
                        var $next;
                        
                        if ($nextSlide == 'previous')
                                $next = ($active.prev().length) ? $active.prev() : $(this).children('li:last');
                        else if ($nextSlide && $nextSlide != 'next')
                                $next = $nextSlide;
                        else
                                $next = ($active.next().length) ? $active.next() : $(this).children('li:first');
                   
                        $active.addClass('last-active');
                        $active.animate({opacity: 0.0}, fadeTime, function() {
                                        $active.removeClass('active last-active');
                                });
                        $next.css({opacity: 0.0})
                                .addClass('active')
                                .animate({opacity: 1.0}, fadeTime);
                        switchSlide = setInterval("slideSwitch(0)", pauseTime);
                }
        });
}

// SLIDESHOW SETTINGS (times are in milliseconds)
var switchSlide;
var pauseTime = 5000;   // Default speeds
var fadeTime = 1000;
var currentSlide = 0;

jQuery(document).ready(function($){
        // Make slideshow active if js is enabled
        $('.gallery').addClass('slideshow');
        $('.slideshow').each(function(i){
                $(this).children('li').css({opacity: 0.0}).filter('li:first').animate({opacity: 1.0}, fadeTime).addClass('active');
        });
        $('.slideshow').after('<ul class="nav slideshow-nav"><li class="prev"><a href="#" title="View Previous"><img src="images/slideshow/arrow-lt.gif" alt="Previous" style="border: 0px;" /></a></li><li class="next"><a href="#" title="View Next"><img src="images/slideshow/arrow-rt.gif" alt="Next" style="border: 0px;" /></a></li></ul>');
        $('li.prev a').click(function(){
                slideSwitch('previous');
                clearInterval(switchSlide);
                return false;
        });
        $('li.next a').click(function(){
                slideSwitch();
                clearInterval(switchSlide);
                return false;
        });
    switchSlide = setInterval("slideSwitch(0)", pauseTime);
        
        // Add a class of "last" to paragraphs with sudoclass :last, to remove bottom margin
        $('p:last').addClass('last');
});

