﻿$(document).ready(function() {
    var backfade_id = 'back-fader_splash';
    $('body').append($('<div>').attr('id', backfade_id).css({ 'z-index': '3900', 'position': 'absolute', 'top': '0px', 'bottom': '0px', 'right': '0px', 'left': '0px', 'display': 'block', 'background-color': '#000000' }));

    splashText('Welcome to the', 'official site of...', 120, function() {
        splashText('Lula', 'La Rose', 155, function() {
            $('#' + backfade_id).fadeOut(1000);
            $(document).trigger('animDone');
        })
    });
});

function splashText(txt1, txt2, fontSize, callback) {
    var sh = $(window).height(); var sw = $(window).width();
    var midPad = 50;

    var l1 = $('<div>').html(txt1).attr('class', 'bigTxt').css({ 'font-size': fontSize + 'px', 'z-index': 15000 });
    l1.pos({ top: 100, left: -1000 });
    var l2 = $('<div>').html(txt2).attr('class', 'bigTxt').css({ 'font-size': fontSize + 'px', 'z-index': 15000 });
    l2.pos({ top: 100, right: -1000 });

    $('body').append(l1); $('body').append(l2);

    var l1w = l1.width(); var l1h = l1.height();
    var l2w = l2.width(); var l2h = l2.height();

    l1.pos({ top: (sh / 2) - l1h, left: (-1 * l1w) });
    l2.pos({ top: (sh / 2), left: (sw + l1w) });

    l1.animate({
        left: (sw / 2) - (l1w / 2) - midPad
    }, 250, 'linear');
    l2.animate({
        left: (sw / 2) - (l2w / 2) + midPad
    }, 250, 'linear', function() {
        l1.animate({
            left: ((sw / 2) - (l1w / 2)) + midPad
        }, 1250, 'linear');
        l2.animate({
            left: (sw / 2) - (l2w / 2) - midPad
        }, 1250, 'linear', function() {
            l1.animate({
                left: sw
            }, 250, 'linear');
            l2.animate({
                left: -1 * l2w
            }, 250, 'linear', function() {
                l1.remove(); l2.remove();
                if (callback != null) callback();
            });
        });
    });
}