$(function () {
    $('#mainVisual').find('p')
                    .fadeIn(1000)
                    .delay(500)
                    .fadeOut(500)
                    .end()
                    .find('h2')
                    .css({ opacity: 0 })
                    .delay(2000)
                    .animate({ opacity: 1, left: 23 }, 1000, 'easeOutExpo');
        
    $('#servicePod').delay(2300).animate(
        { opacity: 1, top: 0 },
        { duration: 1000, easing: 'easeOutExpo', complete: function(){
            var func = (function () {
                var index = 0;
                var previous = '';
                var max = $('#servicePod li').size();
                var selectors = [];
                for (var i = 1; i <= max; i++) {
                    var num = ('#0' + i).slice(-2);
                    selectors.push('#servicePod li.service' + num);
                }
                var getNext = function () {
                    index = index === selectors.length ? 0 : index;
                    previous = index === 0 ? selectors[selectors.length - 1] : selectors[index - 1];
                    return selectors[index++];
                };
                var getPrevious = function () {
                    return previous;
                };
                return function () {
                    var $current = $(getNext());
                    var $previous = $(getPrevious());
                    $previous.find('img')
                        .css('z-index', 4700)
                        .delay(1000)
                        .animate({ top: '320px' }, 0)
                        .fadeOut(0);
                    $current.find('img')
                        .css('z-index', 4900)
                        .fadeIn(200)
                        .animate({ top: '0px' }, 1000 ,'easeOutCubic');
                    $previous.find('p')
                        .css('z-index', 4800)
                        .delay(1000)
                        .fadeOut(0);
                    $current.find('p')
                        .delay(200)
                        .css('z-index', 5000)
                        .fadeIn(200);
                };
            })();
            func();
            setInterval(func, 3000);
        }}
    );
    
    var fukidashi = $('#topInterview .fukidashi');
    fukidashi.find('li').css({ opacity: 0 });
    $('#topInterview li[class^=interview]').hover(function () {
        $('.fukidashi' + $(this).attr('class').substr(9, 2), fukidashi).stop().animate({ opacity: 1, marginTop: -10}, 300, 'easeOutExpo');
    }, function () {
        $('.fukidashi' + $(this).attr('class').substr(9, 2), fukidashi).stop().animate({ opacity: 0, marginTop: 0}, 300, 'easeOutExpo');
    });
});
