// JavaScript Document

bnrArray = new Array(
new Array(
    'ad1.gif',
	'http://hrd.apec.org/index.php/Capacity_Building_Network_%28CBN%29',
	'Image of business people.  The banner reads, Capacity Building Network promoting human resource development through government/public, private and not-for-profit sectors in strengthening markets '
	),
    new Array(
	'ad2.gif',
	'http://hrd.apec.org/index.php/Education_Network_%28EDNET%29',
	'Image of high school students.  Education Networks, promoting education for all'
	),
	new Array(
	'ad3.gif',
	'http://hrd.apec.org/index.php/Labour_and_Social_Protection_Network_%28LSPN%29',
	'Image of a scientist.  Labour and Social Protection Network, fostering strong and flexible labour markets...'
	),
	//new Array(
	//'ad4.gif',
	//'http://hrd.apec.org/index.php/31st_Human_Resources_Development_Working_Group_Meeting',
	//'Image of the Chigago Skyline.  31st Human Resources Development Working Group Meeting, Chicago, Illinois, United States, 22–25 June 2009'
	//),
    new Array(
	'ad5.gif',
	'http://hrd.apec.org/index.php/Human_Resources_Development_Working_Group_%28HRDWG%29',
	'APEC members on the beach with the APEC logo in the sand. Human Resources Development Working Group (HRDWG), Programs touching on issues ranging from education to capacity building.'
	)
);

var prd = 5000;
var tmr;
var sts = 0;
var idx = 0;
var ida = 'homeRBa';
var idi = 'homeRBimg';

function bnrInit() {
    idx = mod(new Date().getSeconds(), bnrArray.length);
    document.write('<a href="' + bnrArray[idx][1] + '" id="' + ida + '">');
    document.write('<img src="images/' + bnrArray[idx][0] + '" alt="' + bnrArray[idx][2] + '" id="' + idi + '" width="400" height="165" border="0">');
    document.write('</a>');
    bnrStart();
}

function bnr(step, e) {
    if (step == '0') {
        if (sts == 1) { bnrStop(); } else { bnrStart(); }
        e.src = (sts == 1 ? 'images/stop.gif' : 'images/play.gif');
        e.title = (sts == 1 ? 'Stop Banners' : 'Start Banners');
    }
    else if (sts == 1) { bnrStep(step); }
    else if (sts == 0) { bnrStep(step); bnrStop(); }
}

function bnrStart() {
    idx++;
    if (idx >= bnrArray.length) { idx = 0; }
    document.getElementById(ida).href = bnrArray[idx][1];
    document.getElementById(idi).src = 'images/' + bnrArray[idx][0];
    document.getElementById(idi).alt = bnrArray[idx][2];
    tmr = setTimeout('bnrStart()', prd);
    sts = 1;
}

function bnrStop() {
    clearTimeout(tmr);
    sts = 0;
}

function bnrStep(step) {
    bnrStop();
    if (step == '-1') {
        if (idx == 1) { idx = bnrArray.length - 1; }
        else if (idx == 0) { idx = bnrArray.length - 2; }
        else { idx -= 2; }
    }
    bnrStart();
}

function mod(X, Y) {
    return (X - Math.floor(X / Y) * Y);
}