var slideshow;
var slideshow_options = {
        id:"rotate_padder",
        random:false,
        speed:6000,
        fadeSpeed:1000
};
$(function() {
    slideshow = donation_rotate(slideshow_options);
    slideshow.startRotate();
    $('#right-arrow').click(function(){
        slideshow.stopRotate();
        slideshow.rotateNext();
    });
    $('#left-arrow').click(function(){
        slideshow.stopRotate();
        slideshow.rotatePrev();
    });
});

var donation_rotate = function(options){
    var rotateTimer;
    var that = {};
    var rotateSize;
    var rotateStart = 1;
    var rotateId = rotateStart;
    var speed = options['speed'] || 8000;
    var fadeSpeed = options['fadeSpeed'] || 2000;
    var container_id =  "#" + (options['id'] || "rotate-container");

    var constructor = function(){
        rotateSize = $(".rotate").length;
   };
    that.startRotate = function(){
        $(".rotate").hide();
        $("#rotate-"+rotateStart).show();
        rotateTimer = setInterval(function(){
            that.rotateNext();
             },speed);
    };
    that.stopRotate = function(){
        clearInterval(rotateTimer);
    }
    that.rotateNext = function(){
        if (rotateId < rotateSize) {
            rotateId++;
        } else {
            rotateId=1;
        }
        $("#rotate-"+rotateId).fadeIn(fadeSpeed).siblings().fadeOut(fadeSpeed);
     };
     that.rotatePrev = function(){
        if (rotateId > 1) {
            rotateId--;
        } else {
            rotateId=rotateSize;
        }
        $("#rotate-"+rotateId).fadeIn(fadeSpeed).siblings().fadeOut(fadeSpeed);
     };
   
    constructor();
    return that;
};
