/* Start Rotating banner code */
var theImage = new Array()
theImage[0] = '0px -150px';
theImage[1] = '0px -225px';
theImage[2] = '0px -300px';

var hover_eff = new Array()
hover_eff[0] = '0 -24px';
hover_eff[1] = '0 1px';
hover_eff[2] = '0 -74px';
hover_eff[3] = '0 -49px';
hover_eff[4] = '0 -125px';
hover_eff[5] = '0 -100px';
hover_eff[6] = '0 -200px';
hover_eff[7] = '0 -175px';
hover_eff[8] = '0 -275px';
hover_eff[9] = '0 -250px';

function orimage() {
	document.getElementById("myImage1").style.backgroundPosition = "0 -100px";
	document.getElementById("myImage2").style.backgroundPosition = "0 -175px";
	document.getElementById("myImage3").style.backgroundPosition = "0 -250px";
}

active = Math.floor(Math.random() * 3);
if (rd_temp_config.top_banner_rotate_yn=='N') active=parseInt(rd_temp_config.top_banner_default_norotate)-1; //For stopping rotation
var arrayLength = 3;
k = 1;
var fadeinTimer, fadeoutTimer, hideTimer;

function animate(i, interaction) {
	clearTimeout(fadeinTimer);
	clearTimeout(fadeoutTimer);
	clearTimeout(hideTimer);
	if (interaction == "first") {
		fadeIn(i);
		active = i;
		k = active;
		timerID = setInterval("autorotator()", 7000);
	}
	if (interaction == true) timerID = clearInterval(timerID);
	orimage();
	if (active != i) {
		fadeOut(active);
		fadeIn(i);
		active = i;
	}
	document.getElementById("myImage" + (i + 1)).style.backgroundPosition = theImage[i];
	if (interaction == true) {
		k = active;
		timerID = setInterval("autorotator()", 7000);
	}
	
	if (rd_temp_config.top_banner_rotate_yn=='N') clearTimeout(timerID); //For stopping rotation
}

function hov (item,val) {
	for (i=0; i<3; i++)
		if (theImage[i]==item.style.backgroundPosition)
			return;
	item.style.backgroundPosition = hover_eff[val];
}

function autorotator() {
	animate(k, false);
	if (k != 2)
		k = k + 1;
	else
		k = 0;
}

function getElm(eID) {
	return document.getElementById(eID);
}

function show(eID) {
	getElm(eID).style.display = 'block';
}

function hide(eID) {
	getElm(eID).style.display = 'none';
}

function setOpacity(eID, opacityLevel) {
	var eStyle = getElm(eID).style;
	eStyle.opacity = opacityLevel / 100;
	eStyle.filter = 'alpha(opacity=' + opacityLevel + ')';
}

function fadeIn(eID) {
	setOpacity(eID, 0);
	show(eID);
	var timer = 0;
	for (var i = 1; i <= 100; i++) {
		fadeinTimer = setTimeout("setOpacity('" + eID + "'," + i + ")", timer * 5);
		timer++;
	}
}

function fadeOut(eID) {
	var timer = 0;
	for (var i = 100; i >= 1; i--) {
		fadeoutTimer = setTimeout("setOpacity('" + eID + "'," + i + ")", timer * 3);
		timer++;
	}
	hideTimer = setTimeout("hide('" + eID + "')", 500);
} 


/* Start Rotating Fading text */
var DivID = "attentioncopyid";
var Speed = 30;
var Content = new Array();


Content[0] = '<a href="' + rd_temp_config.banner_news_room_url1 + '">' + rd_temp_config.banner_news_room_txt1 + '</a>';
Content[1] = '<a href="' + rd_temp_config.banner_news_room_url2 + '">' + rd_temp_config.banner_news_room_txt2 + '</a>';
Content[2] = '<a href="' + rd_temp_config.banner_news_room_url3 + '">' + rd_temp_config.banner_news_room_txt3 + '</a>';

var MaskColors = new Array;
MaskColors[0] = "#000000";
var ContentTop = Content.length - 1;
var MaskTop = MaskColors.length - 1;
var DigitList = "0123456789ABCDEF".split("");
var DigitPointer = 15;
var ContentPointer = ContentTop;
var ColorPointer = MaskTop;
var CurrentDirection = 'up';

function FadeFunction() {
	if (DigitPointer == 15) {
		ContentPointer++;
		if (ContentPointer > ContentTop) ContentPointer = 0;
		ColorPointer++;
		if (ColorPointer > MaskTop) ColorPointer = 0;

		if (document.getElementById) {
			var container = document.getElementById(DivID);
			container.innerHTML = '';
			container.innerHTML = Content[ContentPointer];
		}
		else if (document.all) {
			var divx = document.all[DivID];
			divx.innerHTML = Content[ContentPointer];
		}
		CurrentDirection = 'down';
	}
	else if (DigitPointer == 0) CurrentDirection = 'up';

	if (CurrentDirection == 'up') DigitPointer++;
	else DigitPointer--;

	re = /0/g;
	var thiscolor = MaskColors[ColorPointer].replace(re, DigitList[DigitPointer]);
	document.getElementById(DivID).getElementsByTagName("a")[0].style.color = thiscolor;
	if (thiscolor == "#000000") {
		fadeingTimer = clearInterval(fadeingTimer);
		setTimeout("resumefader()", 3000);
	}
}

function resumefader() {
	fadeingTimer = setInterval("FadeFunction()", Speed);
}
