$(document).ready(function() {

    $('.home img').mouseover(function() {
        $(this).fadeOut('fast', function() {
            $(this).fadeIn('fast');
        });
    });
    
    var total = 3;

    var pos = 1;

    var next = $('#slider-controls > .next');

    var previous = $('#slider-controls > .previous');

    var x;

    function roll() {
        x = setTimeout(function(){
            n();
            roll();
        }, 4000 );
    }

    roll();

    function n() {
        var current = $('#slider > .current');
        
        if(pos < total) pos++;
        else pos = 1;

        current.fadeOut('slow', function() {
            current.removeClass('current');
            var newCurrent = $('#slider > .slide-' + pos);
            newCurrent.addClass('current');
            newCurrent.fadeIn('slow');
        });
    };

    function p() {
        var current = $('#slider > .current');

        if(pos > 1) pos--;
        else pos = 3;

        current.fadeOut('slow', function() {
            current.removeClass('current');
            var newCurrent = $('#slider > .slide-' + pos);
            newCurrent.addClass('current');
            newCurrent.fadeIn('slow');
        });
    };

    next.click(function() {
        n();
        clearTimeout(x);
        roll();
    });
     
    previous.click(function() {
        p();
        clearTimeout(x);
        roll();
    });

    

});



