var motto = 0;
var t = 0;

var actual = 0;
var next = 0;
var actual_s = "";
var next_s = "";
var actual_l = 0;
var next_l = 0;

var step = 0;
var steps = 0;
var period = 0;
var mottos = [
 "Multiply your assets",
 "Need innovation?",
 "Get new perspective",
 "Complex problems need complex solutions",
 "New light to your future"
];
function motto_change(a,s) {
    steps = s;
    actual = a;
    next = (actual+1) % mottos.length;
    actual_s = mottos[actual];
    next_s = mottos[next];
    actual_l = actual_s.length;
    next_l = next_s.length;
    //direction = actual_l <= next_l;
    direction = false;
    //period = (1000/24)*(steps/Math.max(actual_l,next_l));
    period = (1000/24)*(steps/(actual_l+next_l));
    if (motto==0)
        motto = document.getElementById('motto');
    step = 0;
    change_letter();
}
function change_letter() {
    if (direction) {
        //text = next_s.substr(0,step+1).concat(actual_s.substr(step+1,actual_l-step-1));
        text = next_s.substr(0,step-actual_l+1);
        motto.innerHTML = text.split(' ').join('&nbsp;');
    } else {
        //text = actual_s.substr(0,actual_l-step-1).concat(next_s.substr(actual_l-step-1,next_l-(actual_l-step-1)));
        text = actual_s.substr(0,actual_l-step-1);
        motto.innerHTML = text.split(' ').join('&nbsp;');
    }
    //_typeface_js.initialize();
    step = step+1;
    if (step >= actual_l)
        direction = true;
    t = setTimeout("change_letter()",period);
    //if (step >= Math.max(actual_l,next_l))
    if (step >= actual_l+next_l)
        clearTimeout(t);
}

