var text_container = text_string.split("__");

var i,array_length
//var counter
//counter = 0

var hex_1,hex_2,hex_3
hex_1 = 255 // Initial color value = white.
hex_2 = 255
hex_3 = 255

i = 0;

array_length = text_container.length - 1 //5-1=4

//alert(array_length);
var delay = 4000; 

var lock = false; 

function textshow(counter)
{   
        //i = 4
        //5 = 4 + 1
        //i=0
        //-1=0-1
        i = i+counter;

        if (i <= array_length && i >= 0 )
        { //alert(i);       
            document.getElementById('sample').innerHTML=text_container[i]
            fadetext();         
        }
        else if (i > array_length)  //5
        { //alert(i);
            i = 0;          
            document.getElementById('sample').innerHTML=text_container[i]
            fadetext();         
        } 
        
        else if (i < 0) //-1
        { //alert(i);
            i = array_length;           
            document.getElementById('sample').innerHTML=text_container[i]
            fadetext();         
        } 
        else
        {}      
}

function auto_show() 
{ 
    if (lock == true) 
    {  
        //stop the loop
        lock = false; 
        window.clearInterval(run); 
    }       
    else if (lock == false) 
    { 
        //play the text
        lock = true; 
        run = setInterval("textshow(1)", delay); 
    } 
} 


function fadetext()
{   
    //225->0
    //----------------------------------------------
    //(255-hex1)/20 = 10.2
    //(255-hex2)/15 = 10.2
    //(255-hex3)/10 = 10.2
    //---------------------------------------------
    if(hex_1 >= 51 && hex_2 >=102 && hex_3 >=153)  
    { 
        hex_1-=20; 
        hex_2-=15; 
        hex_3-=10; 
    
        document.getElementById('sample').style.color="rgb("+hex_1+","+hex_2+","+hex_3+")"; //fade in the first div node
        
        //rgb(hex, hex, hex) //51,102,153
        
        document.getElementById('sample').firstChild.style.color="rgb("+hex_1+","+hex_2+","+hex_3+")";//fade in other nodes
                
        setTimeout("fadetext()",90);    
        
    }
    else
    {   
        hex_1=255 //reset hex value
        hex_2=255 //reset hex value
        hex_3=255 //reset hex value
    }   
}

auto_show();

