/**
 * Java scripts para versao 2011 do site da MacWeb
 * @author Glauber Portella <glauber.portella@macweb.com.br>
 */
$(function(){
    $.backstretch("images/background.jpg", {
        speed: 150
    });
    
    //posicionarLogo();

    //$(window).resize(onResize);

    // Credito: Robert Penners easing equations (http://www.robertpenner.com/easing/).
    jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
        if ((t/=d) < (1/2.75)) {
            return c*(7.5625*t*t) + b;
        } else if (t < (2/2.75)) {
            return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
        } else if (t < (2.5/2.75)) {
            return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
        } else {
            return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
        }
    };  

    if ($('#banners-home').length > 0) {		
        $('#banners-home').jcarousel({
            auto: 4,
            size: 3,
            scroll: 1,
            visible: 1,
            wrap: 'last',
            easing: 'BounceEaseOut',
            animation: 1000,
            initCallback: carousel_initCallback
        });
    }
    
    if ($('#slider-ideias').length > 0) {
        $('#slider-ideias').jcarousel({
            auto: 6,
            size: 6,
            scroll: 1,
            visible: 1,
            wrap: 'last',
            easing: 'BounceEaseOut',
            animation: 1000,
            initCallback: carousel_initCallback
        });
    }    
});

/**
 * Posicionar logotipo na tela
 */
function posicionarLogo(){
    $("#logo").css({
        top: $(document).height() - $("#logo").height() - 100 + 'px'
    });
}

function onResize(){
    posicionarLogo();
}

function carousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

