// JavaScript Document

/************************************************************************************
This is created by Puchu ...... RentACoder 
For more information please visit : http://www.rentacoder.com/RentACoder/DotNet/SoftwareCoders/ShowBioInfo.aspx?lngAuthorId=7234186
*************************************************************************************/

var fromColorCode ;										//this is the start color code of the text"
var toColorCode;										//this is the end color code of the text"
var transionTime;												//transition effect time in seconds
var focusedTime;												//time in seconds for which the animation will remain stopped
var ContainerID;									//text container div Id
var ContainerBorderWidth;
var ContainerBorderColor;
var ContainerStyleTop;											//text container div top position in pixel
var ContainerStyleLeft;										//text container div left position in pixel
var ContainerStyleWidth;										//text container div width in pixel
var ContainerStyleHeight;										//text container div height in pixel
var ContainerStyleBgColor;								//text container div backgroung color code
var WrapperID;											//text Wrapper div Id

/**************************************below are the variables you can NOT customize*********************/

function init()
{
	fromDecimal = hexToDecimal(fromColorCode);
	toDecimal = hexToDecimal(toColorCode);
	
	r1 =   fromDecimal.split("|")[0];
	g1 =  fromDecimal.split("|")[1];
	b1 =  fromDecimal.split("|")[2];
	
	r2 = toDecimal.split("|")[0];
	g2 = toDecimal.split("|")[1];
	b2 = toDecimal.split("|")[2];
	
	if((r1 ==r2 ) &&(g1 ==g2 ) &&(b1 ==b2 ) )
	{
		r1 +=1;
		g1 +=1;
		b1 +=1;
	}
	
	rDiff = (r1 - r2)/24;
	gDiff = (g1 - g2)/24;
	bDiff = (b1 - b2)/24;
	
	
	r =  r1;
	g =  g1;
	b =  b1;
	
	interval = transionTime*40;
}

/**************************************************************
Function To fade out text
***************************************************************/
function fadeOutText()
{ 
	if(Math.ceil(r -r2) == 0 || Math.floor(r -r2) == 0)
	{	
		stayFocused(focusedTime);
	}
	else
	{
		r -= rDiff;
		g -= gDiff;
		b -= bDiff;
		document.getElementById(ContainerID).style.color="rgb("+Math.ceil(r)+","+Math.ceil(g)+","+Math.ceil(b)+")";
		setTimeout("fadeOutText()",interval); 
	}

}

/**************************************************************
Function To still the text animation
***************************************************************/
function stayFocused(counter)
{
	if(counter > 0)
	{
		counter--;
		setTimeout("stayFocused(" + counter + ")",1000); 
	}
	else
	{
		fadeInText();
	}
}
/**************************************************************
Function To fade in text
***************************************************************/
function fadeInText()
{ 
	if(Math.ceil(r -r1) == 0 || Math.floor(r -r1) == 0)
	{
		changeTextRandom();
		fadeOutText();

	}
	else
	{
		r += rDiff;
		g += gDiff;
		b += bDiff;
		document.getElementById(ContainerID).style.color="rgb("+Math.ceil(r)+","+Math.ceil(g)+","+Math.ceil(b)+")";
		setTimeout("fadeInText()",interval); 
	}

}

/**************************************************************
Function To convert hex to decimal
***************************************************************/
function hexToDecimal(hex)
{
		hex = hex.replace(/#/g,"");

		rhex=hex.substring(0,2);
    	rdec=eval("0x" + rhex); 
    
    	ghex=hex.substring(2,4);
    	gdec=eval("0x" + ghex); 
    	bhex=hex.substring(4,6);
    	bdec=eval("0x" + bhex);
		decimal=(rdec+ "| " + gdec + "| " + bdec);

		return decimal;
}

/**************************************************************
Function To change the text randomly
***************************************************************/

function changeTextRandom() {
	
		wrapperDivElem = document.getElementById(WrapperID);
		if(wrapperDivElem != null)
		{
			innerDivs = wrapperDivElem.getElementsByTagName("div");
			var randomnumber=Math.floor(Math.random()*innerDivs.length);	
			document.getElementById(ContainerID).innerHTML = innerDivs[randomnumber].innerHTML;
		}
}


/**************************************************************
Function To create div dynamically
***************************************************************/
function create_div_dynamic(){
	
	wrapperDivElem = document.getElementById(WrapperID);
	if(wrapperDivElem != null)
	{
		innerDivs = wrapperDivElem.getElementsByTagName("div");
		for(var i = 0; i < innerDivs.length; i++)
		{
			innerDivs[i].style.display = "none";
		}
		wrapperDivElem.style.height=ContainerStyleHeight;
		wrapperDivElem.style.width=ContainerStyleWidth;
	}

	wrapperDivElem.innerHTML += "<table border=0 cellpadding=0 cellspacing=0><tr><td id=\"" + ContainerID + "\" align=\"center\" valign=\"middle\" style=\"width:" + ContainerStyleWidth + "px; height:" + ContainerStyleHeight + "px;border:" + ContainerBorderWidth + "px solid " + ContainerBorderColor + ";font-weight:bold;background-color:" + ContainerStyleBgColor + "\"></td></tr></table>";
	init();
	changeTextRandom();
	fadeOutText();

}

/**************************************************************
Function To Detect Browser
***************************************************************/
  
function isIE6() 
{  

	var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
	//return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent); 
	return IE6;
}

function isIE7()
{
	IE7 = false/*@cc_on|| @_jscript_version == 7@*/;
	return IE7;
}

window.onload = create_div_dynamic;