﻿//FAZ TROCA DE IMAGENS
//$(function () {var myOptions = {noImages: 3,path: "images/home/",timerInterval: 6000,randomise: false};$('#container').easySlides(myOptions);});

//FAZ CARROUSEL DOS CASES
$(function () {var slides = $('.project');var numberOfSlides = slides.length;$('#banners').css('width', slides.width() * numberOfSlides);var div = $('div#clientBanner'), ul = $('ul#banners'), ulPadding = 15;var divWidth = div.width(); div.css({ overflow: 'hidden' }); var lastLi = ul.find('li:last-child');div.mousemove(function (e) {var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth; div.scrollLeft(left);}); });

//FAZ O HOVER DOS CASES
$(function () { var hoverAnim = { init: function () { var project = $('#clientBanner li'); project.children().children('.hover-bg').fadeTo(500, 0.0); project.children('.hover').stop().css("display", "none"); project.hover(function () { $(this).children('.hover').stop().css("display", "block"); $(this).children().children('.hover-bg').stop().fadeTo(500, 0.60); }, function () { $(this).children().children('.hover-bg').stop().fadeTo(500, 0.00, function () { $(this).children('.hover').stop().css("display", "none"); }); }); project.click(function () { location.href = $(this).children("a").attr("href"); }); } }; hoverAnim.init(); });

//RERIRA ESPACO EM BRANCO DO TWITTER
$(function () { setTimeout(function () { $(".twtr-hd:first-child").css("display", "none"); }, 2000); });

//FUNÇÃO DE TROCA DE IMAGENS MOBILE
$(function () {var trocaMobile = $("#trocaMobile li");var contador = 1;var contadorAnt = 0;$(trocaMobile).css('display', 'none');$(trocaMobile).css('opacity', '1');$(trocaMobile).eq(0).fadeIn(500);if ($(trocaMobile).length > 1) {setInterval(function () {$(trocaMobile).eq(contadorAnt).stop().fadeOut(2000);$(trocaMobile).eq(contador).stop().fadeIn(3000);contadorAnt = contador;contador++;if (contador >= $(trocaMobile).length) {contador = 0;}}, 6000);}});


var AgenciaFoster = { _init: function () {
    AgenciaFoster._overscroll('#sidebar .content');
},

    /*Habilita a barra de rolagem*/
    _overscroll: function (element) {

        h = $(element).height();
        w = $(element + ' .item').width() * $(element + ' .item').size();

        wa = w - $(document).width();

        cnt = $(document.createElement('div'));
        cnt.css({
            position: 'relative',
            overflow: 'hidden',
            height: h,
            width: wa + w,
            marginLeft: -wa
        });

        $(element).css({ left: wa });

        dsp = $(document.createElement('div'));
        dsp.css({
            width: '100%',
            overflow: 'hidden'
        });

        $(element).wrap(dsp);
        $(element).wrap(cnt);

        var _startPos = 0,
			_stopPos = 0,
			_timer = 1;

        var _left = 0;
        var el;

        $(element).draggable({
            axis: 'x',
            containment: 'parent',
            distance: 0,
            scrollSpeed: -5,
            start: function (e) {
                $(element).stop(true, true);
                $(element).addClass('csr-closed');
                _startPos = e.pageX;
                el = e.target;

            },
            drag: function () {
                _timer++;
            },
            stop: function (e) {
                $(element).removeClass('csr-closed');

                _stopPos = e.pageX;

                _left = (5 * (_stopPos - _startPos) / _timer);


                _left = ($(element).offset().left + _left > 0 && _stopPos > _startPos) ? 0 - $(element).offset().left : _left;
                _left = ($(element).offset().left + _left < -wa && _stopPos < _startPos) ? -wa - $(element).offset().left : _left;


                $(element).stop(false, true).animate({
                    left: '+=' + _left
                }, 500, 'easeOutCubic');

                _timer = 1;

                if (_stopPos == _startPos) {
                    $('.content a').unbind('click').click(function () {
                        window.open($(this).attr('href'));
                    });
                }
            }
        });
    } 
}


window.onload = AgenciaFoster._init;
