(function () {
   "use strict";

    var control = {
        interval: 1,
        oldInterval: 1,
        maxSpeed: 20
    };

    var data = {
        placement: [],
        list: []
    };
    data.list.push(
        ['A little learning is a dangerous thing; Drink deep, or taste not the Pierian spring.', 'Alexander Pope', undefined],
        ['The magic of first love is our ignorance that it can ever end.', 'Benjamin Disraeli', undefined],
        ['Many forms of Government have been tried and will be tried in this world of sin and woe. No one pretends that democracy is perfect or all-wise. Indeed, it has been said that democracy is the worst form of government except all those other forms that have been tried from time to time.', 'Winston Churchill', undefined],
        ['I made this letter very long, because I did not have the leisure to make it shorter.', 'Blaise Pascal', undefined],
        ['One man that has a mind and knows it can always beat ten men who haven\'t and don\'t.', 'George Bernard Shaw', undefined],
        ['Neither a lofty degree of intelligence nor imagination nor both together go to the making of genius. Love, love, love, that is the soul of genius.', 'Nikolaus von Jacquin', undefined],
        ['Few men have virtue to withstand the highest bidder.', 'George Washington', undefined],
        ['Some books are to be tasted, others to be swallowed, and some few to be chewed and digested.', 'Francis Sr.', undefined],
        ['An appeaser is one who feeds a crocodile - hoping it will eat him last.', 'Winston Churchill', undefined],
        ['The difference between a successful person and others is not a lack of strength, not a lack of knowledge, but rather in a lack of will.', 'Vince Lombardi', undefined],
        ['An inventor is simply a fellow who doesn\'t take his education too seriously.', 'Charles Kettering', undefined],
        ['Imagination is a quality given a man to compensate him for what he is not, and a sense of humor was provided to console him for what he is.', 'Oscar Wilde', undefined],
        ['Any man who reads too much and uses his own brain too little falls into lazy habits of thinking.', 'Albert Einstein', undefined],
        ['The quality of a person\'s life is in direct proportion to their commitment to excellence, regardless of their chosen field of endeavor.', 'Vince Lombardi', undefined],
        ['He that goes a borrowing goes a sorrowing.', 'Benjamin Franklin', undefined],
        ['I am patient with stupidity but not with those who are proud of it.', 'Edith Sitwell', undefined],
        ['The Almighty has His own purposes.', 'Abraham Lincoln', undefined],
        ['We are always paid for our suspicion by finding what we suspect.', 'Henry David Thoreau', undefined],
        ['The child is father of the man.', 'William Wordsworth', undefined],
        ['God helps them that help themselves.', 'Benjamin Franklin', undefined],
        ['Love your Neighbour; yet don\'t pull down your Hedge.', 'Benjamin Franklin', undefined],
        ['I am not bound to win, but I am bound to be true. I am not bound to succeed, but I am bound to live by the light that I have. I must stand with anybody that stands right, and stand with him while he is right, and part with him when he goes wrong.', 'Abraham Lincoln', undefined],
        ['Nothing is particularly hard if you divide it into small jobs.', 'Henry Ford', undefined],
        ['My words fly up, my thoughts remain below:  Words without thoughts never to heaven go.', 'William Shakespeare', undefined],
        ['Children are the world\'s most valuable resource and its best hope for the future.', 'John F. Kennedy', undefined],
        ['Keep away from people who try to belittle your ambitions. Small people always do that, but the really great make you feel that you, too, can become great.', 'Mark Twain', undefined],
        ['Home is the place where, when you have to go there, They have to take you in.', 'Robert Frost', undefined],
        ['Success is never final. Failure is never fatal. It is courage that counts.', 'Winston Churchill', undefined],
        ['Believe those who are seeking the truth. Doubt those who find it.', 'Andre Gide', undefined],
        ['Science is a wonderful thing if one does not have to earn one\'s living at it.', 'Albert Einstein', undefined],
        ['Power tends to corrupt and absolute power corrupts absolutely.', 'Lord Acton', undefined],
        ['If you\'re ridin\' ahead of the herd, take a look back every now and then to make sure it\'s still there.', 'Will Rogers', undefined],
        ['Lettin\' the cat outta the bag is a whole lot easier \'n puttin\' it back in.', 'Will Rogers', undefined],
        ['You can get everything in life you want if you will just help enough other people get what they want.', 'Zig Ziglar', undefined],
        ['Once you say you\'re going to settle for second, that\'s what happens to you in life, I find.', 'John F. Kennedy', undefined],
        ['To be prepared for war is one of the most effective means of preserving peace.', 'George Washington', undefined],
        ['If we have no peace, it is because we have forgotten that we belong to each other.', 'Teresa Calcutta', undefined],
        ['Never leave that till tomorrow which you can do today.', 'Benjamin Franklin', undefined],
        ['In my stars I am above thee, but be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness; thrust upon em.', 'William Shakespeare', undefined],
        ['The quickest way to double your money is to fold it over and put it back in your pocket.', 'Will Rogers', undefined],
        ['Winning is a habit. Unfortunately, so is losing.', 'Vince Lombardi', undefined],
        ['Time is money.', 'Benjamin Franklin', undefined],
        ['For fools rush in where angels fear to tread.', 'Alexander Pope', undefined],
        ['Forgive your enemies, but never forget their names.', 'John F. Kennedy', undefined],
        ['Always bear in mind that your own resolution to succeed, is more important than any other one thing.', 'Abraham Lincoln', undefined],
        ['Hitch your wagon to a star.', 'Ralph Waldo Emerson', undefined],
        ['The greatest lesson in life is to know that even fools are right sometimes.', 'Winston Churchill', undefined],
        ['Example is not the main thing in influencing others, it is the only thing.', 'Albert Schweitzer', undefined],
        ['You cannot help men permanently by doing for them what they could and should do for themselves.', 'William Boetcker', undefined],
        ['Real friendship is shown in times of trouble; prosperity is full of friends.', 'Anonymous', undefined],
        ['Advice is what we ask for when we already know the answer but wish we didn\'t.', 'Erica Mann Jong', undefined],
        ['I want to know [God\'s] thoughts, the rest are details.', 'Albert Einstein', undefined],
        ['There are no gains without pains.', 'Benjamin Franklin', undefined],
        ['If you can\'t stand the heat, get out of the kitchen.', 'Eugene Purcell', undefined],
        ['When you come to the end of your rope, tie a knot and hang on.', 'Franklin D. Roosevelt', undefined],
        ['Early to Bed, and Early to Rise, Makes a Man Healthy, Wealthy, and Wise.  ', 'Benjamin Franklin', undefined],
        ['In heaven all the interesting people are missing.', 'Friedrich Wilhelm Nietzsche', undefined],
        ['The pen is mightier than the sword.', 'Edward Bulwer-Lytton', undefined],
        ['The buck stops here.', 'Harry S. Truman', undefined],
        ['To err is human, to forgive divine.', 'Alexander Pope', undefined],
        ['Ask not what your country can do for you, ask what you can do for your country.', 'John F. Kennedy', undefined],
        ['Speak softly and carry a big stick; you will go far.', 'Theodore Roosevelt', undefined],
        ['An eye for eye only ends up making the whole world blind.', 'Mahatma Gandhi', undefined],
        ['The difference between stupidity and genius is that genius has its limits.', 'Albert Einstein', undefined],
        ['The hardest thing in the world to understand is income taxes.', 'Albert Einstein', undefined],
        ['It\'s not whether you get knocked down, it\'s whether you get up.', 'Vince Lombardi', undefined],
        ['Imagination is more important than knowledge. For knowledge is limited, whereas imagination embraces the entire world', 'Albert Einstein', undefined],
        ['Never interrupt your enemy when he is making a mistake.', 'Napoleon Bonaparte', undefined],
        ['Keep your friends close and your enemies closer.', 'Mario Puzo', undefined],
        ['You can fool all the people some of the time, and some of the people all the time, but you cannot fool all the people all the time.', 'Anonymous', undefined],
        ['The time to repair the roof is when the sun is shining.', 'John F. Kennedy', undefined],
        ['I have not failed. I\'ve just found 10,000 ways that won\'t work.', 'Thomas A. Edison', undefined],
        ['He who lives by the sword, dies by the sword.', 'Jesus Christ', undefined],
        ['My life is my message.', 'Mahatma Gandhi', undefined],
        ['Be more concerned with your character than with your reputation, because your character is what you really are, while your reputation is merely what others think you are.', 'John Wooden', undefined],
        ['Two things are infinite: the universe and human stupidity; and I\'m not sure about the the universe.', 'Albert Einstein', undefined],
        ['A wise girl kisses but doesn\'t love, listens but doesnt believe, and leaves before she is left.', 'Marilyn Monroe', undefined],
        ['Falling in love is not at all the most stupid thing that people do, but gravitation cannot be held responsible for it.', 'Albert Einstein', undefined],
        ['Oh, East is East, and West is West, and never the twain shall meet; Till Earth and Sky stand presently at God\'s great Judgment Seat; But there is neither East nor West, Border, nor Breed, nor Birth, When two strong men stand face to face, tho they come from the ends of the earth!', 'Rudyard Kipling', undefined],
        ['There never was a good war or a bad peace.', 'Benjamin Franklin', undefined],
        ['God, grant me the serenity to accept the things I cannot change, courage to change the things I can, and the wisdom to know the difference.', 'Reinhold Niebuhr', undefined],
        ['I think and think for months and years. Ninety-nine times, the conclusion is false. The hundredth time I am right.', 'Albert Einstein', undefined],
        ['What lies behind us and what lies before us are tiny matters compared to what lies within us.', 'Ralph Waldo Emerson', undefined],
        ['The best executive is one who has sense enough to pick good people to do what he wants done, and self-restraint enough to keep from meddling with them while they do it.', 'Theodore Roosevelt', undefined],
        ['No man is justified in doing evil on the ground of expedience.', 'Theodore Roosevelt', undefined],
        ['The way to see by Faith is to shut the Eye of Reason.', 'Benjamin Franklin', undefined],
        ['A mind always employed is always happy. This is the true secret, the grand recipe, for felicity.', 'Thomas Jefferson', undefined],
        ['Whatever the mind can conceive and believe, the mind can achieve.', 'Napoleon Hill', undefined],
        ['If you would be loved, love and be lovable.', 'Benjamin Franklin', undefined],
        ['He who permits himself to tell a lie once, finds it much easier to do it a second and a third time till at length it becomes habitual.', 'Thomas Jefferson', undefined],
        ['The language of friendship is not words, but meanings.', 'Henry David Thoreau', undefined],
        ['He has all the virtues I dislike and none of the vices I admire.', 'Winston Churchill', undefined],
        ['A thing of beauty is a joy forever; its loveliness increases; it will never pass into nothingness.', 'John Keats', undefined],
        ['Believe you are defeated, believe it long enough, and it is likely to become a fact.', 'Norman Vincent Peale', undefined],
        ['Never ascribe to malice that which can adequately be explained by incompetence.', 'Napoleon Bonaparte', undefined],
        ['What doesn\'t kill us makes us stronger.', 'Friedrich Wilhelm Nietzsche', undefined],
        ['I cannot believe that God would choose to play dice with the universe.', 'Albert Einstein', undefined],
        ['Whenever you are to do a thing, though it can never be known but to yourself, ask yourself how you would act were all the world looking at you, and act accordingly.', 'Thomas Jefferson', undefined],
        ['A picture is worth a thousand words.', 'Fred R. Bernard', undefined]);

    control.moveText = function() {
        if(control.interval) {
            var elems = document.querySelectorAll('.move');
            var elemsLength = elems.length;
            for(var i=0; i<elemsLength; i++) {
                var quote = elems[i];
                quote.style.left = quote.offsetLeft+control.interval+'px';
            }
        }
        window.setTimeout(control.moveText, 20);
    };

    control.incSpeed = function() {
        if(control.interval <= control.maxSpeed) {
    };

    control.decSpeed = function() {
        if(control.interval > 0) {
            control.interval-=1;
        }
    };

    control.toggleMovement = function() {
        if(control.interval) {
            control.oldInterval = control.interval;
            control.interval = 0;
        } else {
            control.interval = control.oldInterval;
        }
    };

    control.addQuote = function(quote) {
        var headerHeight = control.header.scrollHeight;
        var bodyHeight = window.innerHeight - headerHeight;
        var elementTop = (Math.floor(Math.random() * (bodyHeight - 200)) + headerHeight);
        var placementLength = data.placement.length;
        if(placementLength > 0) {
            for(var i=0; i<placementLength; i++) {
                if(elementTop > (data.placement[i] - 200) && elementTop < (data.placement[i] + 200)) {
                    return;
                }
            }
        }

        var newQuote = document.createElement('div');
        newQuote.className = 'quote move';
        newQuote.innerHTML = '„'+quote[0]+'“<br />';
        var newAuthor = document.createElement('span');
        newAuthor.className = 'author';
        newAuthor.innerHTML = '- '+quote[1];
        newQuote.appendChild(newAuthor);
        newQuote.style.top = elementTop+'px';
        data.placement[data.placement.length] = elementTop;
        quote[2] = newQuote;
        control.body.appendChild(newQuote);
        newQuote.style.width = newQuote.offsetWidth+'px';
    };

    control.calcNextQuote = function() {
        var choice = Math.floor(Math.random() * data.list.length);
        if(control.interval && !data.list[choice][2]) {
            control.addQuote(data.list[choice]);
        }
    };

    control.clearQuotes = function() {
        var maxWidth = document.body.offsetWidth+500;
        var listLength = data.list.length;
        var placementLength = data.placement.length;
        for(var i=0; i<listLength; i++) {
            var quoteElement = data.list[i][2];
            if(quoteElement) {
                for(var j=0; j<placementLength; j++) {
                    if(quoteElement.offsetLeft > 0 && data.placement[j] === quoteElement.offsetTop) {
                        data.placement.splice(j, 1);
                    }
                }
                if(quoteElement.offsetLeft > maxWidth) {
                    quoteElement.parentNode.removeChild(quoteElement);
                    data.list[i][2] = undefined;
                }
            }
        }
    };

    control.toggleTooltip = function(e) {
        var tooltip = control.wrapper.querySelector('div.'+e.target.className);
        if(tooltip.classList.contains('hidden')) {
            tooltip.classList.remove('hidden');
        } else {
            tooltip.classList.add('hidden');
        }
    };

    control.init = function() {
        control.wrapper = document.querySelector('div.wrapper');
        control.header = document.querySelector('header');
        control.buttonSlow = document.querySelector('button.slow');
        control.buttonToggle = document.querySelector('button.toggle');
        control.buttonFast = document.querySelector('button.fast');
        control.body = document.querySelector('div.body');

        control.buttonSlow.addEventListener('mouseover', control.toggleTooltip, true);
        control.buttonSlow.addEventListener('mouseout', control.toggleTooltip, true);
        control.buttonSlow.addEventListener('click', control.decSpeed, true);
        control.buttonToggle.addEventListener('mouseover', control.toggleTooltip, true);
        control.buttonToggle.addEventListener('mouseout', control.toggleTooltip, true);
        control.buttonToggle.addEventListener('click', control.toggleMovement, true);
        control.buttonFast.addEventListener('mouseover', control.toggleTooltip, true);
        control.buttonFast.addEventListener('mouseout', control.toggleTooltip, true);
        control.buttonFast.addEventListener('click', control.incSpeed, true);

        setInterval(control.calcNextQuote, 400);
        setInterval(control.clearQuotes, 400);
        control.moveText();
    };

    window.onload = function() {
        control.init();
    };
}());
            control.interval+=1;
        }