﻿var speed = 100; // uitgedrukt in pixels/sec
var currentBlobNr = 0;

function activateBlob() {


    letABlobOnTheLoose();
    setInterval(function() {
        var random = Math.floor(Math.random() * 4);
        if (random == 3) {
            letABlobOnTheLoose();
        }
    }, 1000);
    
}

function letABlobOnTheLoose() {
    currentBlobNr++;
    var uniqueBlobID = "BLOB" + currentBlobNr;
    $('#core_blob_placeholder').append('<div id="' + uniqueBlobID + '" class="blob"></div>');
    $('#' + uniqueBlobID).css({ 'top': '40px', 'left': '460px' });


    //Animate part1
    var blob_arc1 = {
        center: [430, -90],
        radius: 30,
        start: 90,
        end: 180
    }
    var blob_arc2 = {
        center: [60, -150],
        radius: 30,
        start: 0,
        end: 270,
        dir: -1
    }
    //omhoog!                                           //afstand = 130px
    $('#' + uniqueBlobID).animate({ 'top': '-90px' }, (130 / speed) * 1000, 'linear'); 

    //eerste bocht                                      //afstand = 47px
    $('#' + uniqueBlobID).animate({ path: new $.path.arc(blob_arc1) }, (47 / speed) * 1000, 'linear');

    //naar links!                                       //afstand = 380px
    $('#' + uniqueBlobID).animate({ 'left': '60px' }, (380 / speed) * 1000, 'linear'); 

    //tweede bocht van rechts naar boven                //afstand = 47px
    $('#' + uniqueBlobID).animate({ path: new $.path.arc(blob_arc2) }, (47 / speed) * 1000, 'linear'); 

    //omhoog tot een afslag of het einde                //afstand = 465px
    $('#' + uniqueBlobID).animate({ 'top': '-555px' }, (465 / speed) * 1000, 'linear', function() {

        //alert($('#' + uniqueBlobID).offset().top);
        $('#' + uniqueBlobID).remove();


        alert($('#black_container').offset().top + +'50px');
        $('#global_blob_placeholder').append('<div id="' + uniqueBlobID + '" class="blob"></div>');
        $('#' + uniqueBlobID).css({ 'top': $('#black_container').offset().top +50+ 'px', 'left': '30px' });



        //IS ER NIETS OPGEKLAPT? STUUR HEM DAN NAAR BOVENAAN!
        sendBlobToTheTop(uniqueBlobID);
    });
}

function sendBlobToTheTop(uniqueBlobID) {
    $('#' + uniqueBlobID).animate({ 'top': '-20px' }, (374 / speed) * 1000, 'linear', function() {
        $('#' + uniqueBlobID).remove();
    });
}
