(function() {

    jQuery(document).ready(function() {
        init();
    });

    var arrayOfSlides;
    var noOfSlides;
    var index = 0; //refers to dot index

    function init() {
        setupDots();

        if (noOfSlides > 1) {
            jQuery(".slidePanels li").bind("click", function(event) { changeOnClick(this); });
            setInterval(changeOnTimer, 15000);
        }
    }

    function setupDots() {
        arrayOfSlides = [];

        jQuery(".slide").each(function() {

            var slide = $(this);

            if (slide.find('.text').html().length > 10) {
                arrayOfSlides.push(slide);
                slide.css('height', slide.height() + 10);

            }
        });

        noOfSlides = arrayOfSlides.length;

        jQuery("<ul class='slidePanels'></ul>").insertAfter(".jsBanner .inner");

        if (noOfSlides > 1) {
            for (var i = 0; i < noOfSlides; i++) {
                jQuery(".slidePanels").append("<li class='dot'>Panel " + (i + 1) + "</li>");
            }
            jQuery(".slidePanels li:first").addClass("active")
            jQuery(".slide:first").addClass("activeSlide");
        }
    }

    function changeOnTimer() {
        if (index == (arrayOfSlides.length - 1)) {
            index = 0;
        }
        else {
            index = index + 1;
        }

        scrollSlide(index);
    }

    function changeOnClick(clicked) {
        index = jQuery.inArray(clicked, jQuery(".slidePanels li"));
        scrollSlide(index);
    }

    function scrollSlide(index) {
        jQuery(".slidePanels li").eq(index).addClass("active");
        jQuery(".slidePanels li").eq(index).siblings().removeClass("active");

        var scrollAmount = 0;
        var slideWidth = 940;
        scrollAmount = slideWidth * index;

        jQuery('#banner .inner').animate({
            left: -scrollAmount
        }, 500);

    }

    //easeOutQuart
    //800, 'easeInOutCirc'
    //1600, 'easeInOutBack'
    // 1200, 'easeInOutElastic'
    //1800, 'easeOutBounce'




})();


	
