/************************************************************************
		Copyright 2009 Darren Berry

		All rights reserved. The information contained in this document
		is confidential and may also be proprietary and trade secret. It
		is the intellectual property of Darren Berry, and without
		prior written approval from Darren Berry no part of this
		document may be reproduced or transmitted in any form or by any
		means, including but not limited to electronic, mechanical,
		photocopying or stored in any retrieval system of whatever nature.
		The use of copyright notice does not imply unrestricted public
		access to any part of this document. 
*************************************************************************/

var timerBanner = null;
var colTitleStart, colTitleEnd, colTextStart, colTextEnd;
var nPos, nCount, nImagePos, nImageCount, nDelay, nStepDelay, nStep, nSteps;
var arrHex, arrImage, arrTitle, arrText;

function initBanner()
{
	arrImage = Array();
	arrTitle = Array();
	arrText = Array();
	nPos = nCount = 0;
	nImagePos = nImageCount = 0;
	timerBanner = null;
	arrHex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
	colTitleStart = dehexize("#999999");
	colTitleEnd = dehexize("#FFFFFF");
	colTextStart = dehexize("#FFFFFF");
	colTextEnd = dehexize("#000000");
	nDelay = 6000;
	nStepDelay = 100;
	nSteps = 16;
	nStep = 0;
	document.getElementById("bannertitle").style.zIndex = 2;
	document.getElementById("bannertext").style.zIndex = 1;
}

function addBannerImage(strImage)
{
	arrImage[nImageCount] = new Image();
	arrImage[nImageCount++].src = strImage;
}


function addBannerText(strTitle, strText)
{
	arrTitle[nCount] = strTitle;
	arrText[nCount] = strText;
	nCount++;
}

function setBannerTitle(nCurPos)
{
	document.getElementById("bannertitle").innerHTML = arrTitle[nCurPos];
	setTimeout("fadeBanner(-1)", nDelay);
}

function setBannerText(nCurPos)
{
	document.getElementById("bannertext").innerHTML = arrText[nCurPos];
	setTimeout("fadeBanner(1)", nDelay);
}

function updateBannerImage()
{
	if (obj = document.getElementById("banner"))
	{
		if (obj.filters)
		{
			obj.style.filter = "blendTrans(duration=2)";
			obj.filters.blendTrans.Apply();
		}
		obj.style.backgroundImage = "url('" + arrImage[nPos].src + "')";
		if (obj.filters)
			obj.filters.blendTrans.Play();
	}
}

function startBanner()
{
	setBannerText(nPos);
}

function fadeBanner(nIncr)
{
	nStep += nIncr;
	if (nStep < 0)
		setBannerText(nPos);
	else if (nStep >= nSteps)
		setBannerTitle(nPos = ++nPos % nCount);
	else
	{
		if ((nStep == (nSteps -1)) && (nIncr == -1))
			updateBannerImage();

		updateColor(hexize(colTitleStart, colTitleEnd, nStep / nSteps), "bannertitle");
		updateColor(hexize(colTextStart, colTextEnd, nStep / nSteps), "bannertext");
		if (nStep == (nSteps / 2))
		{
			nSwap = document.getElementById("bannertitle").style.zIndex;
			document.getElementById("bannertitle").style.zIndex = document.getElementById("bannertext").style.zIndex;
			document.getElementById("bannertext").style.zIndex = nSwap;
		}
		timerBanner = setTimeout("fadeBanner(" + nIncr + ")", nStepDelay);
	}
}

function stopBanner()
{
	if (timerBanner)
		clearTimeout(timerBanner);
}

function updateColor(strColor, strID)
{
	document.getElementById(strID).style.color = strColor; 
} 

function hexize(s, e, incr)
{
	return "#" + hex(Math.floor(s[0] + (e[0] - s[0]) * incr)) +
				 hex(Math.floor(s[1] + (e[1] - s[1]) * incr)) +
				 hex(Math.floor(s[2] + (e[2] - s[2]) * incr));
}

function dehexize(strColor)
{
	colorArr = new Array(0, 0, 0); 
	for (i = 1; i < 7; i++)
	{ 
		for (j = 0; j < 16; j++)
		{ 
			if (strColor.charAt(i) == arrHex[j])
				colorArr[Math.floor((i - 1) / 2)] += (i % 2) ? (eval(j) * 16) : eval(j); 
		}
	}
	
	return colorArr; 
}

function hex(i)
{ 
	return "" + arrHex[Math.floor(i / 16)] + arrHex[i % 16];
}
