/*
	COPYRIGHT 1996, 2009, 2010 JAMES H. ZISCH. ALL RIGHTS RESERVED.
	CONTACT:  James H. Zisch - Computer Services (JHZ-CS) http://www.jhz-cs.com/
*/

function bannerInit() {
	try {
		bInitColors();
		bInitText();
		bRef = getBRef();
		bInitHandlers();
		bReset();
	}
	catch (err) { errHandler(err,'bannerInit'); }
}

function bInitColors() {
	try {
		bOverColor = getCSSBySelector(pgTopBannerhoverRef).style.color;
		var tColor = getCSSBySelector(pgTopBannerselector).style.color;
		bOutColor = tColor;
		var bColor = getCSSBySelector(pgTopBannerselector).style.backgroundColor;

		if (tColor.search(/#/) != -1) tColor = hexToRGB(tColor);
		tColor = tColor.replace(/rgb\(|\)| /g,'');

		if (bColor.search(/#/) != -1) bColor = hexToRGB(bColor);
		bColor = bColor.replace(/rgb\(|\)| /g,'');

		bBgR = parseFloat(bColor.split(/,/)[0]);
		bBgG = parseFloat(bColor.split(/,/)[1]);
		bBgB = parseFloat(bColor.split(/,/)[2]);

		bTxR = parseFloat(tColor.split(/,/)[0]);
		bTxG = parseFloat(tColor.split(/,/)[1]);
		bTxB = parseFloat(tColor.split(/,/)[2]);

		lightToDark = ((bBgR+bBgG+bBgB) > (bTxR+bTxG+bTxB)) ? true : false;
		darkToLight = (lightToDark) ? false : true;

		if (lightToDark) {
			bDeltaR = parseInt(bBgR * bDelta);
			bDeltaG = parseInt(bBgG * bDelta);
			bDeltaB = parseInt(bBgB * bDelta);
		}
		else {
			bDeltaR = parseInt(bTxR * bDelta);
			bDeltaG = parseInt(bTxG * bDelta);
			bDeltaB = parseInt(bTxB * bDelta);
		}
	}
	catch(err) { errHandler(err,'bInitColors'); }
}

function bInitText() {
	try {
		bInitBannerArrays();
		if (sector.search(/services|solutions|support/) == -1) return;
		bText.length = 0;
		if (sector == 'services')	bText = bServ;
		if (sector == 'solutions')	bText = bSols;
		if (sector == 'support')	bText = bSupp;
	}
	catch(err) { errHandler(err,'bInitText'); }
}

function bInitHandlers() {
	try {
		var x = document.getElementById(pgTopBannerID);
		x.onclick		= bClick;
		x.onmouseover	= bOver;
		x.onmouseout	= bOut;
	}
	catch(err) { errHandler(err,'bInitHandlers'); }
}

function bReset() {
	try {
		bClearTimers();
		bRef = getBRef();
		bFade = (lightToDark) ? true : false;
		bCurR = bBgR;
		bCurG = bBgG;
		bCurB = bBgB;
		with (document.getElementById(pgTopBannerID)) {
			color		= 'rgb('+bCurR+','+bCurG+','+bCurB+')';
			innerHTML	= bText[bRef].text;
			title		= bText[bRef].title;
		}
		bDeltaTimer = setInterval('bAdjust()',bDeltaInt);
	}
	catch(err) { errHandler(err,'bReset'); }
}

function bAdjust() {
	try {
		(bFade) ? bAdjDarken() : bAdjLighten();
		if (darkToLight) {
			if (bFade && bCurR <= bBgR && bCurG <= bBgG && bCurB <= bBgB) 
				bReset();
			if (! bFade && bCurR >= bTxR && bCurG >= bTxG && bCurB >= bTxB)
				bPeak(true);
		}
		else if (lightToDark) {
			if (bFade && bCurR <= bTxR && bCurG <= bTxG && bCurB <= bTxB)
				bPeak(false);
			if (! bFade && bCurR >= bBgR && bCurG >= bBgG && bCurB >= bBgB)
				bReset();
		}
		
		document.getElementById(pgTopBannerID).style.color = 
			'rgb('+parseInt(bCurR)+','+parseInt(bCurG)+','+parseInt(bCurB)+')';
	}
	catch(err) { errHandler(err,'bAdjust'); }
}

function bPeak(m) {
	bClearTimers();
	bFade = m;
	bSetPause();
}

function bAdjLighten() {
	bCurR += bDeltaR;
	bCurG += bDeltaG;
	bCurB += bDeltaB;
	if (darkToLight && bCurR > bTxR) bCurR = bTxR;
	if (darkToLight && bCurG > bTxG) bCurG = bTxG;
	if (darkToLight && bCurB > bTxB) bCurB = bTxB;
	if (lightToDark && bCurR > bBgR) bCurR = bBgR;
	if (lightToDark && bCurG > bBgG) bCurG = bBgG;
	if (lightToDark && bCurB > bBgB) bCurB = bBgB;
}

function bAdjDarken() {
	bCurR -= bDeltaR;
	bCurG -= bDeltaG;
	bCurB -= bDeltaB;
	if (darkToLight && bCurR < bBgR) bCurR = bBgR;
	if (darkToLight && bCurG < bBgG) bCurG = bBgG;
	if (darkToLight && bCurB < bBgB) bCurB = bBgB;
	if (lightToDark && bCurR < bTxR) bCurR = bTxR;
	if (lightToDark && bCurG < bTxG) bCurG = bTxG;
	if (lightToDark && bCurB < bTxB) bCurB = bTxB;
}

function bSetPause() {
	try {
		bPauseTimer = setTimeout('bPause()', bPauseInt);
	}
	catch(err) { errHandler(err,'bSetPause'); }
}

function bPause() {
	try {
		bClearTimers();
		bDeltaTimer = setInterval('bAdjust()', bDeltaInt);
	}
	catch(err) { errHandler(err,'bPause'); }
}

function bClearTimers() {
	try {
		if (bPauseTimer) clearTimeout(bPauseTimer);
		if (bDeltaTimer) clearTimeout(bDeltaTimer);
	}
	catch(err) { errHandler(err,'bClearTimers'); }
}

function getBRef() {
	try {
		var x = parseInt(Math.floor(Math.random() * (bText.length - 1)));
		if (bText[x] && x != bRef) return x;
		(x < (bText.length - 2)) ? ++x : --x;
		if (bText[x] && x != bRef) return x;
		return 0;
	}
	catch(err) { errHandler(err,'getBRef'); }
}

function bOver() {
	try {
		bClearTimers();
		with (document.getElementById(this.id).style) {
			bOutColor	= color;
			color		= bOverColor;
		}
	}
	catch(err) { errHandler(err,'bOver'); }
}

function bOut() {
	try {
		document.getElementById(this.id).style.color = bOutColor;
		bDeltaTimer = setInterval('bAdjust()', bDeltaInt);
	}
	catch(err) { errHandler(err,'bOut'); }
}

function bClick() {
	try {
		if (! bText[bRef].link) return;
		if (location.href.search(bText[bRef].link) == -1) location.href = bText[bRef].link;
	}
	catch(err) { errHandler(err,'bClick'); }
}

function bInitBannerArrays () {
	//	default
	bText[bText.length] = {
		text : 'offering application systems design, development, support and training services on a project basis',
		link : '/services/index.html',
		title : 'Click to learn more...'
	};
	bText[bText.length] = {
		text : 'recommends extensive use of platform independent open source standards based technologies for global deployment',
		link : '/solutions/info/index.html',
		title : 'Click to learn more...'
	};
	bText[bText.length] = {
		text : 'providing platform independent solutions supportive of unrestrictive migration capabilities satisfying future considerations requirements',
		link : '/solutions/info/index.html',
		title : 'Click to learn more...'
	};
	bText[bText.length] = {
		text : 'providing dynamic real-time page generation solutions ideal for installations with massive amounts of data that requires frequent change',
		link : '/solutions/info/index.html',
		title : 'Click to learn more...'
	};
	bText[bText.length] = {
		text : 'offerings include ready-made fully customizable open-source application systems solutions for achieving your objectives rapidly and affordably',
		link : '/solutions/index.html',
		title : 'Click to learn more...'
	};

	//	services
	bServ[bServ.length] = {
		text : 'offers services to clients on a fixed price time-of-completion project basis assuring successful implementation of your objectives on-time and on-budget',
		link : '/services/index.html',
		title : 'Click to learn more...'
	};
	bServ[bServ.length] = {
		text : 'specializes in design, development and deployment of client server application system solutions using open standards',
		link : '/services/index.html',
		title : 'Click to learn more...'
	};
	bServ[bServ.length] = {
		text : 'offers initial project requirements analysis without cost or obligation providing you a feasiblity study of your objectives',
		link : '/services/index.html',
		title : 'Click to learn more...'
	};
	
	//	solutions
	bSols[bSols.length] = {
		text : 'solutions support all server platform environments including shared hosted configurations',
		link : '/solutions/info/index.html',
		title : 'Click to learn more...'
	};
	bSols[bSols.length] = {
		text : 'offers dynamic real-time input and template driven  solutions for dynamic processing functionality',
		link : '/solutions/info/tmpls.html',
		title : 'Click to learn more...'
	};
	bSols[bSols.length] = {
		text : 'offers solutions that are fully customizable supportive of your specific requirements allowing you to deploy without compromise',
		link : '/solutions/info/tmpls.html',
		title : 'Click to learn more...'
	};
	bSols[bSols.length] = {
		text : 'solution offerings that are both easy to use and maintain with a minimum level of expertise',
		link : '/solutions/info/index.html',
		title : 'Click to learn more...'
	};
	
	//	support
	bSupp[bSupp.length] = {
		text : 'offers numerous guides about the various aspects you\'ll encounter developing for Internet driven technologies',
		link : '/support/guides/html/index.html',
		title : 'Click to learn more...'
	};
	bSupp[bSupp.length] = {
		text : 'offers guides about using Javascript&reg; providing client-side conditional logical processing &amp; dynamic display functionality reducing server load',
		link : '/support/guides/js/index.html',
		title : 'Click to learn more...'
	};
	bSupp[bSupp.length] = {
		text : 'offers guides about utilizing CSS (Cascading Style Sheets) to provide page formatting, aesthetics and much more...',
		link : '/support/guides/css/index.html',
		title : 'Click to learn more...'
	};
	bSupp[bSupp.length] = {
		text : 'offers guides about "new" user aspects and terms you\'ll encounter on the Internet',
		link : '/support/guides/gen/terms.html',
		title : 'Click to learn more...'
	};
}

var bRef,
	bText = new Array,
	bSols = new Array,
	bServ = new Array,
	bSupp = new Array,
	bDeltaR, bDeltaG, bDeltaB,
	bPauseTimer, bDeltaTimer,
	bTxR, bTxG, bTxB,
	bBgR, bBgG, bBgB,
	bCurR, bCurG, bCurB,
	bOutColor, bOverColor,
	lightToDark, darkToLight,
	bFade,
	pgTopBannerID		= 'pgTopBanner',
	pgTopBannerselector	= '#main',
	pgTopBannerhoverRef	= '#PgC a:hover';

//	Variable Settings
var bDelta = .03,		//	RGB delta %
	bDeltaInt = 40,		//	banner automation msecs delta interval
	bPauseInt = 8000;	//	banner pause  msecs delta interval 
