$(function() {
    var _initLeft = false;
    var _initRight = false;
    var _current = 0;
    var _after = function(curr,next,opts) {
            _current = opts.currSlide;
    };
    if ($('#rotationBox').length) {
        $('#rotationBox').cycle({fx: 'scrollLeft',after:_after,startingSlide:_current});
        $('.right-arrow').each(function(){
            $(this).bind('click',function() {
                if (!_initRight) {
                    //$('#rotationBox').cycle('destroy');
                    $('#rotationBox').cycle({fx:'scrollLeft',after:_after,startingSlide:_current});        
                    $('#rotationBox').cycle('pause');
                    _initRight=true;
                    _initLeft=false;
                }
                $('#rotationBox').cycle('next');
            });
        });
        $('.left-arrow').each(function(){
            $(this).bind('click',function() {
                if (!_initLeft) {
                    $('#rotationBox').cycle({fx: 'scrollRight',after:_after,startingSlide:_current});        
                    $('#rotationBox').cycle('pause');                
                    _initRight=false;
                    _initLeft=true;
                }
                $('#rotationBox').cycle('prev');
            });
        });
    }
});
