$(document).ready(function(){
    (function($) {
        // VERTICAL ALIGNMENT FUNCTION
        $.fn.vAlign = function() {
            return this.each(function(i) {
                var $ah = $(this).height();
                var $ph = $(this).parent().height();
                var $mh = ($ph - $ah) / 2;
                $(this).css('padding-top', $mh);
            });
        };

    })(jQuery);

    $('#content').css('height', $(window).height());
    $('.centered').vAlign();
	$('#previous').hide().end();

    $.easing.easeOutQuart = function(x, t, b, c, d) {
        return - c * ((t = t / d - 1) * t * t * t - 1) + b;
    };

    var $prev = $('#previous');//prev button
    var $next = $('#next');//next button
 	var $currentSlide = 0;
   
 	$('#slideshow').serialScroll({
        items: 'li',
        prev: '#previous',
        next: '#next',
        onBefore: function(e, elem, $pane, $items, pos) {
            $currentSlide = pos;
            if (pos == 0) {
            $prev.fadeOut(1200);}
            if ((pos != 0) && (pos != $items.length - 1)){
            $prev.add($next).fadeIn(1200);}
            if (pos == $items.length - 1) {
                $next.fadeOut(1200);
                $prev.fadeOut(1200);
            }

        },
        start: 0,
        duration: 1200,
        force: true,
        lazy: true,
        stop: true,
        easing: 'easeOutQuart',
        lock: false,
        cycle: false //don't pull back once you reach the end
    });
	
	$(window).bind('resize',
    function() {
        var resizeTimer = null;
        if (resizeTimer) clearTimeout(resizeTimer);
        resizeTimer = setTimeout(function() {
            $('#content').css('height', $(window).height());
            $('#slideshow').trigger('goto', [$currentSlide]);
            $('.centered').vAlign();
        },
        10);
    });
});
