$(function(){
/**
 * mark -> bassgrinder [a] gmail
 * 20090820 
 */
kr = {
    wrapper: 'div.featured_wrapper',
    timer: null,
    active: null,
    next: null,
    moveNext:function(){        
        this._stopTimer();
        this.slideShow();
        this.enableTimer();
    },
    movePrevious:function(){        
        this._stopTimer();
        this.slideShowReverse();
        this.enableTimer();
    },
    slideShow:function(){        
        var $active = $(this.wrapper+' P.active');
        if ( $active.length == 0 ) $active = $(this.wrapper+' P:last');        
        this.next = $active.next().length ? $active.next() : $(this.wrapper+' P:first');        
        this.active = $active;
        this._animate();
    },
    slideShowReverse:function(){
        var $active = $(this.wrapper+' P.active');
        if ( $active.length == 0 ) $active = $(this.wrapper+' P:last');
        this.next = $active.prev().attr('class')=='hidden' ? $active.prev() : $(this.wrapper+' P:last');        
        this.active = $active;
        this._animate();   
    },
    enableTimer:function(){
        kr.timer=setInterval( "kr.slideShow()", 12000 );    
    },    
    _animate:function(){
        var $active = this.active;
        var $next = this.next;                
        $active.animate({opacity: 0.0}, 600, function() {                            
            $next.css({opacity: 0.0})
                .removeClass('hidden')
                .addClass('active')
                .animate({opacity: 1.0}, 600, function() {                    
                    $active.removeClass('active');
                    $active.addClass('hidden');            
                });                                                                    
            });
    },
    _stopTimer:function(){
        clearInterval(kr.timer);
        if (this.active) this.active.stop(true, true);
        if (this.next) this.next.stop(true, true);            
    }   

};

kr.enableTimer();
$(kr.wrapper+" span#button-up").click(function(){kr.movePrevious()});
$(kr.wrapper+" span#button-down").click(function(){kr.moveNext()});

});
