var slideshow;
var slideshow_options = {
        img : "http://aldf.rdsecure.org/img/rotate-",
        id:"slideshow",
        random:false,
        speed:5500,
        fadeSpeed:1000
};
$(function() {
    slideshow = rotate(slideshow_options);
    slideshow.startRotate();
    $('#right-arrow').click(function(){
        slideshow.stopRotate();
        slideshow.rotateNext();
    });
    $('#left-arrow').click(function(){
        slideshow.stopRotate();
        slideshow.rotatePrev();
    });
});

var rotate = function(options){
    var rotateTimer;
    var public_methods = {};
    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 img = options['img'];

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

    constructor();
    return public_methods;
};
