﻿var overlay = document.getElementById('overlay');
var bubble = document.getElementById('thoughtbubble');
var bubbletop = document.getElementById('bubbletop');
var bubblebottom = document.getElementById('bubblebottom');
var bubbleleft = document.getElementById('bubbleleft');
var bubblecontent = document.getElementById('bubblecontent');
var bubbleright = document.getElementById('bubbleright');
var quotetext = document.getElementById('quotetext');
var colorR;
var colorG;
var colorB;
var bubbleLeft;
var bubbleTop;
var quotes = new Array();
var height = new Array();
var today = new Date();
var day = today.getDate() - 1;
var quotetextHeight;
var widthSet;
var heightSet;
var bubbleWidthAdd = 36;
var bubbleLeftOffset = 18;
var timeOut;

if (navigator.appName == 'Microsoft Internet Explorer')
    timeOut = 5;
else
    timeOut = 20;

//Quotes
quotes[0] = '“One person’s definition of success is another’s first step. Only you can rate your accomplishments, and find peace within yourself” -Anonymous';
quotes[1] = '“What is there to be afraid of? The worst thing that can happen is you fail. So what? I failed at a lot of things. My first record was horrible.”  -John Mellencamp';
quotes[2] = '“Although the world is full of suffering, it is also full of the overcoming of it.”-Helen Keller'
quotes[3] = '“When fate hands you a lemon, make lemonade.”  -Dale Carnegie';
quotes[4] = '“I gain strength, courage and confidence by every experience in which I must stop and look fear in the face... I say to myself, I\'ve lived through this and can take the next thing that comes along... We must do the things that we think we cannot do.” -Eleanor Roosevelt';
quotes[5] = '“To forgive is the highest, most beautiful form of love. In return, you will receive untold peace and happiness.” -Dr. Robert Muller';
quotes[6] = '“What you get by reaching your destination is not nearly as important as what you will become by reaching your destination.” -Zig Ziglar';
quotes[7] = '“If we all did the things we are capable of doing, we would literally astound ourselves.” -Thomas Edison';
quotes[8] = '“Every individual human being born on this earth has the capacity to become a unique and special person, unlike any who has ever existed before or will ever exist again.” -Elisabeth Kubler-Ross, b. 1926 American Psychiatrist and Writer';
quotes[9] = '“I didn’t belong as a kid, and that always bothered me. If only I’d known that one day my differentness would be an asset than my early life would have been much easier.” -Bette Midler, b. 1945 American Singer and Comedian';
quotes[10] = '“You can do or be whatever you want in your own life. Nothing can stop you, except for your own fears. Don’t blame anyone else..you have the power to make the decision. Just do it.” -Nola Diamatopoulos Australian Creative Workshop Tutor';
quotes[11] = '“Do not fear to hope..Each time we smell the autumn’s dying scent, We know that primrose time will come again,” -Samuel Taylor Coleridge, 1772-1834 English Poet';
quotes[12] = '“There is one thing which gives radiance to everything. It is the idea of something around the corner.” -Gilbert Chesterton (1874-1936)';
quotes[13] = '“Action may not bring happiness, but there is no happiness without action.” -Benjamin Disraeli, 1804-1881 English Statesman and Writer';
quotes[14] = '“My personal trials have also taught me the value of unmerited suffering. As my sufferings mounted I soon realized that there were two ways that I could respond to my situation: either to react with bitterness or seek to transform the suffering into a creative force.” -Martin Luther King, 1929-1968 American Civil Rights Leader and Minister';
quotes[15] = '“There is an Indian belief that everyone is a house of four rooms: a physical, a mental, an emotional and a spiritual room. Most of us tend to live in one room most of the time, but unless we go into every room every day, even if only to keep it aired, we are not complete.” -Rumer Godden';
quotes[16] = '“We can\'t do great things in this life . . . We can only do small things with great love.” -Mother Theresa';
quotes[17] = '“It\'s not the wound that shapes our lives, it\'s the choice we make as adults between embracing our wounds or raging against them.” –Unknown';
quotes[18] = 'Fear says, “I want you to be safe. “Love says, “You are safe.” - Emmanuel';
quotes[19] = '“Faith is free and available to all people at all times. It only requires that one fully embrace possibility, and the ultimate value is in the depth of the embrace.” -Patch Adams, M.D.';
quotes[20] = '“Motivation is an external, temporary high that pushes you forward. Inspiration is a sustainable internal glow which pulls you forward.” -Thomas Leonard';
quotes[21] = '“I\'d rather be optimistic and a fool, than pessimistic and right.” -Unknown';
quotes[22] = '“You can\'t do anything about the length of your life, but you can do something about its width and depth.” -Shira Tehrani';
quotes[23] = '“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.” -Charles Swindoll';
quotes[24] = '“Consult not your fears but your hopes and dreams. Think not about your frustrations, but about your unfulfilled potential. Concern yourself not with what you tried and failed in, but with what is still possible for you to do.” -Pope John XXIII';
quotes[25] = '“The most difficult phase of life is not when no one understands you, it is when you don\'t understand yourself.” -Author Unknown';
quotes[26] = '“It\'s amazing how many cares disappear when you decide not to be something, but to be someone.” -Coco Chanel';
quotes[27] = '“The purpose of learning is growth, and our minds, unlike our bodies, can continue growing as we continue to live.” - Mortimer Adler';
quotes[28] = '“...the process of discovering who I really am begins with knowing who I really don\'t want to be.” -Unknown';
quotes[29] = '“There is an Indian belief that everyone is a house of four rooms: a physical, a mental, an emotional and a spiritual room. Most of us tend to live in one room most of the time, but unless we go into every room every day, even if only to keep it aired, we are not complete.” -Rumer Godden';
quotes[30] = '“We can\'t do great things in this life . . . We can only do small things with great love.” -Mother Theresa';


function showBubble()
{
    widthSet = 0;
    heightSet = 0;
    quotetext.innerHTML = quotes[day];
    overlay.style.display = 'block';

    quotetextHeight = quotetext.offsetHeight;
    bubble.style.visibility = 'visible';
    bubble.style.width = '36px';
    bubble.style.height = '36px';
    
    if (!isNaN(parseInt(bubble.style.left)))
        bubble.style.left = (parseInt(bubble.style.left) + bubbleLeft) + 'px';
    
    bubbleLeft = 0;

    if (!isNaN(parseInt(bubble.style.top)))
        bubble.style.top = (parseInt(bubble.style.top) + bubbleTop) + 'px';

    bubbleTop = 0;


    bubbletop.style.width = '0px';
    bubblebottom.style.width = '0px';
    bubbleleft.style.height = '0px';
    bubblecontent.style.height = '0px';
    bubblecontent.style.width = '0px';
    bubbleright.style.height = '0px';

    quotetext.style.visibility = 'hidden';
    colorR = 166;
    colorG = 0;
    colorB = 30;

    growWidth();
}

function growWidth()
{
    if (parseInt(bubble.style.width) < 468)
    {
        bubble.style.width = parseInt(bubble.style.width) + bubbleWidthAdd + 'px';
        bubble.style.left = (parseInt(bubble.offsetLeft) - bubbleLeftOffset) + 'px';
        bubbleLeft = bubbleLeft + bubbleLeftOffset;
        bubbletop.style.width = parseInt(bubbletop.style.width) + bubbleWidthAdd + 'px';
        bubblebottom.style.width = parseInt(bubblebottom.style.width) + bubbleWidthAdd + 'px';
        bubblecontent.style.width = parseInt(bubblecontent.style.width) + bubbleWidthAdd + 'px';
        setTimeout(growWidth, timeOut);
    }
    else
    {
        growHeight();
    }
}

function growHeight()
{
    var bubbleHeightIncrement;
    var bubbleTopOffset;
    
    bubbleHeightIncrement = 4;
    bubbleTopOffset = 2;

    if (parseInt(bubblecontent.style.height) < quotetextHeight)
    {
        bubble.style.top = (parseInt(bubble.offsetTop) - bubbleTopOffset) + 'px';
        bubbleTop = bubbleTop + bubbleTopOffset;
        bubbleleft.style.height = parseInt(bubbleleft.style.height) + bubbleHeightIncrement + 'px';
        bubblecontent.style.height = parseInt(bubblecontent.style.height) + bubbleHeightIncrement + 'px';
        bubbleright.style.height = parseInt(bubbleright.style.height) + bubbleHeightIncrement + 'px';
        setTimeout(growHeight, timeOut);
    }
    else
    {
        quotetext.style.visibility = 'visible';
        quotetext.style.color = '#A6001E';
        setTimeout(fadeText, 100);
    }
}

function fadeText()
{ 
    if(colorR < 255 || colorG < 255 || colorB < 255)
    {
        if (colorR < 255)
            colorR += 4;
        if (colorG < 255)
            colorG += 10;
        if (colorB < 255)
            colorB += 10;
        document.getElementById("quotetext").style.color = "rgb(" + colorR + "," + colorG + "," + colorB + ")";
        setTimeout(fadeText,10);
    }
    else
        setTimeout(closeBubble,15000);
}

function closeBubble()
{
    bubble.style.visibility = 'hidden';
    quotetext.style.visibility = 'hidden';
    overlay.style.display = 'none';
}

