/************************************************************************
		Copyright 2011 Darren Berry (design@darrenberry.co.uk)

		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 arrBanner = new Array();
var nCurrentBanner = 0;
var nBannerCount = 0;
var bannerTimer, fadeTimer;

function addBanner(image)
{
	arrBanner[nBannerCount] = new Image();
	arrBanner[nBannerCount].src = image;
	nBannerCount++;
}

function startBanners()
{
	bannerTimer = window.setInterval('nextBanner(true)', 8000);
}

function stopBanners()
{
	if (bannerTimer)
		clearInterval(bannerTimer);
	if (fadeTimer)
		clearTimeout(fadeTimer);
}

function nextBanner(fadeIn)
{
	setBanner(nCurrentBanner + 1, fadeIn);
}

function setBanner(banner, fadeIn)
{
	if (fadeTimer)
		clearTimeout(fadeTimer);
	
	if ((objA = document.getElementById('banner-a')) &&
		(objB = document.getElementById('banner-b')))
	{
		nCurrentBanner = banner % nBannerCount;

		objB.src = objA.src;
		setOpacity(objB, 100);
		
		setOpacity(objA, 0);
		objA.src = arrBanner[nCurrentBanner].src;
		
		opacity = (fadeIn) ? 0 : 100;
		fadeTimer = setTimeout('fadeBannerIn(' + opacity + ')', 0);
	}
}

function fadeBannerIn(opacity)
{
	if (obj = document.getElementById('banner-a'))
		setOpacity(obj, opacity);
	
	if (obj = document.getElementById('banner-b'))
		setOpacity(obj, 100 - opacity);
	
	if (opacity < 100)
	{
		if (fadeTimer)
			clearTimeout(fadeTimer);
		opacity =  Math.min(opacity + 5, 100);
		fadeTimer = setTimeout('fadeBannerIn(' + opacity + ')', 50);
	}
}

function setOpacity(obj, opacity)
{
	obj.style.opacity = opacity / 100;
	obj.style.filter = 'alpha(opacity=' + opacity + ')';
}


