// byteMyCode.com
// ©1998-2006  All Rights Reserved.
// Fade snippet
function fadeSnippet(nSnippetID, nNewRanking)
{
	// Declare variables
	var nDelay = 0;
	var nFPS = 100;
	var nFrames = 6;
	var strColorFrom = "#0C86B5";
	var strColorTo = "#56AA04";
	var rf = parseInt(strColorFrom.substr(1, 2), 16);
	var gf = parseInt(strColorFrom.substr(3, 2), 16);
	var bf = parseInt(strColorFrom.substr(5, 2), 16);
	var rt = parseInt(strColorTo.substr(1, 2),16);
	var gt = parseInt(strColorTo.substr(3, 2), 16);
	var bt = parseInt(strColorTo.substr(5, 2), 16);

	// Hide controls
	var cItem = document.getElementById("vote_snippet_controls_" + nSnippetID);
	if (cItem)
	{
		cItem.style.display = "none";
	}

	// Get item
	cItem = document.getElementById("vote_snippet_" + nSnippetID);
	if (cItem)
	{
		// -- Fade background
		for (var i = 1; i <= nFrames; i++)
		{
			// -- -- Make text color
			r = Math.floor(rf * ((nFrames - i) / nFrames) + rt * (i / nFrames));
			g = Math.floor(gf * ((nFrames - i) / nFrames) + gt * (i / nFrames));
			b = Math.floor(bf * ((nFrames - i) / nFrames) + bt * (i / nFrames));
			h = makeFadeHex(r, g, b);

			// -- -- New ranking
			if (i == 3)
			{
				nDelay += nFPS;
				setTimeout("newRanking(" + nSnippetID + ", " + nNewRanking + ")", nDelay);
			}

			// -- Make delay
			nDelay += nFPS;

			// -- -- Change background
			setTimeout("changeSnippetBack(" + nSnippetID + ", " + i + ", '" + h + "')", nDelay);
		}

		// -- Hide controls
		nDelay += nFPS;

	}
}

// Make fade hex
function makeFadeHex(r, g, b)
{
	r = r.toString(16); if (r.length == 1) r = '0' + r;
	g = g.toString(16); if (g.length == 1) g = '0' + g;
	b = b.toString(16); if (b.length == 1) b = '0' + b;
	return "#" + r + g + b;
}

// Hide controls
function newRanking(nSnippetID, nNewRanking)
{
	// Fade font
	var cItem = document.getElementById("vote_snippet_res_" + nSnippetID);
	if (cItem)
	{
		cItem.innerHTML = nNewRanking;
	}
}

// Change background
function changeSnippetBack(nSnippetID, nIndex, strColor)
{
	// Fade background
	var cItem = document.getElementById("vote_snippet_" + nSnippetID);
	if (cItem)
	{
		cItem.style.backgroundImage = "url(/img/snippet_vote_back_" + nIndex + ".gif)";
	}

	// Fade font
	var cItem = document.getElementById("vote_snippet_res_" + nSnippetID);
	if (cItem)
	{
		cItem.style.color = strColor;
	}
}

