(function ($) {
    $.fn.vAlign = function() {
        return this.each(function(i){
            var ah = parseInt($(this).height()) + parseInt($(this).css('padding-top')) + parseInt($(this).css('padding-bottom'));
            var ph = $(this).parent().height();
            var mh = (ph - ah) / 2;
            $(this).css('margin-top', mh);
        });
    };
})(jQuery);

$(document).ready(function()
{
    //  Center content
    $('.to-be-centered').vAlign();

    switch($('body').attr('id')) {
        case 'nous':
            $('.medias ul').cycle({
                fx: 'fade',
                timeout: 6000,
                next: '.medias .arrow-next',
                prev: '.medias .arrow-previous',
                onPrevNextEvent: function(idx, slide) {
                    $('.detail-nous li').fadeOut({
                        speed: 'fast'
                    });
                    $('.detail-nous li.detail-nous-'+slide).animate({
                        opacity: 'toggle'
                    });
                }
            }).cycle('pause');
            break;

        default:
            $('.medias ul').cycle({
                fx: 'fade',
                timeout: 6000,
                next: '.medias .arrow-next',
                prev: '.medias .arrow-previous'
            });
            break;
    }

    $('.billboard').cycle({
        fx: 'fade',
        timeout: 7000
    });

    //  CAROUSEL Borders Effect
    $('.news .bordered span').bind('mouseover', function(){
        $(this).animate({width: '110px', height: '83px', left: '0', top: '0'}, 100);
    }).bind('mouseout', function(){
        $(this).animate({width: '122px', height: '95px', left: '-6px', top: '-6px'}, 100);
    });

    $('a.reference_item').hover(function(){
        $('img', this).fadeOut();
    }, function(){
        $('img', this).fadeIn();
    });

    $('#pages-agences ul').cycle({
        fx: 'scrollHorz',
        timeout: 5000,
        timeout: 0,
        next:   '.arrow-next',
        prev:   '.arrow-previous',
        nowrap: 1
    });
});

