﻿// aidrs banners
$(document).ready(function () {

    //slider
    var autoPlayTime = 10000;
    autoPlayTimer = setInterval(autoPlay, autoPlayTime);

    //banner
    $('.banner .next').click(function () {
        banner('.banner', 'next', 'stop');
    });
    $('.banner .previous').click(function () {
        banner('.banner', 'previous', 'stop');
    });

    //    next previous pozicija
    //    var yPosition = $('#banner').height() - 2 - $('#banner .next').height() - 2;
    //    $('#banner .next').css('top', yPosition);
    //    $('#banner .previous').css('top', yPosition);

    //projects
    $('.project .next').click(function () {
        banner('.project', 'next', 'stop');
    });
    $('.project .previous').click(function () {
        banner('.project', 'previous', 'stop');
    });

    //press
    $('.press .next').click(function () {
        banner('.press', 'next', 'stop');
    });
    $('.press .previous').click(function () {
        banner('.press', 'previous', 'stop');
    });

    //album
    $('.album .next').click(function () {
        banner('.album', 'next', 'stop');
    });
    $('.album .previous').click(function () {
        banner('.album', 'previous', 'stop');
    });

    //other
    $('.other .next').click(function () {
        banner('.other', 'next', 'stop');
    });
    $('.other .previous').click(function () {
        banner('.other', 'previous', 'stop');
    });
});

// banner slider
function banner(arg, slideTo, autoPlay) {
    var animSpeed = 500;
    var easeType = 'easeInOutCubic';
    var sliderWidth = $(arg).width();
    var leftPosition = $(arg + ' .inside').css("left").replace("px", "");
    $(arg + " .element").each(function (i) {
        totalContent = i * sliderWidth;
        $(arg + ' .inside').css("width", totalContent + sliderWidth);
    });
    if (!$(arg + " .inside").is(":animated")) {
        if (slideTo == 'next') { //next
            if (autoPlay == 'stop') {
                clearInterval(autoPlayTimer);
            }
            if (leftPosition == -totalContent) {
                $(arg + ' .inside').animate({ left: 0 }, animSpeed, easeType); //reset
            } else {
                $(arg + ' .inside').animate({ left: '-=' + sliderWidth }, animSpeed, easeType); //next
            }
        } else if (slideTo == 'previous') { //previous
            if (autoPlay == 'stop') {
                clearInterval(autoPlayTimer);
            }
            if (leftPosition == '0') {
                $(arg + ' .inside').animate({ left: '-' + totalContent }, animSpeed, easeType); //reset
            } else {
                $(arg + ' .inside').animate({ left: '+=' + sliderWidth }, animSpeed, easeType); //previous
            }
        } else {
            var slide2 = (slideTo - 1) * sliderWidth;
            if (leftPosition != -slide2) {
                clearInterval(autoPlayTimer);
                $(arg + ' .inside').animate({ left: -slide2 }, animSpeed, easeType); //go to number
            }
        }
    }
}
