﻿
var improvingImg = new Array();
improvingImg[0] = "http://thf_media.s3.amazonaws.com/index/images/rise-fall-graphics/rwanda.png";
improvingImg[1] = "http://thf_media.s3.amazonaws.com/index/images/rise-fall-graphics/djibouti.png";
improvingImg[2] = "http://thf_media.s3.amazonaws.com/index/images/rise-fall-graphics/seychelles.png";               

var improvingCountry = new Array();
improvingCountry[0]="Rwanda";
improvingCountry[1]="Djibouti";
improvingCountry[2] = "Seychelles";

var improvingChange = new Array();
improvingChange[0]="+3.6";
improvingChange[1]="+3.4";
improvingChange[2]="+3.3";

var decliningImg = new Array();
decliningImg[0] = "http://thf_media.s3.amazonaws.com/index/images/rise-fall-graphics/iceland.png";
decliningImg[1] = "http://thf_media.s3.amazonaws.com/index/images/rise-fall-graphics/algeria.png";
decliningImg[2] = "http://thf_media.s3.amazonaws.com/index/images/rise-fall-graphics/timorleste.png";

var decliningCountry = new Array();
decliningCountry[0]="Iceland";
decliningCountry[1]="Algeria";
decliningCountry[2]="Timor-Leste";

var decliningChange = new Array();
decliningChange[0]="-5.5";
decliningChange[1]="-4.5";
decliningChange[2]="-3.0";             


var imgIndex = 0;
var totalImages = improvingImg.length;//Note:improving/declining must be the same number          

function MM_setTextOfLayer(objId,x,newText) { //v9.0
     with (document) if (getElementById && ((obj=getElementById(objId))!=null))
    with (obj) innerHTML = unescape(newText);
}     

function cycleImages() {           
                                                       
    if (imgIndex == totalImages) 
    {  	                  
       imgIndex = 0;
    }

    document.improvingCountry.src=improvingImg[imgIndex];                    
    document.decliningCountry.src=decliningImg[imgIndex];
                        
    var tempStr = '';
    var shortName;
    
    shortName = improvingCountry[imgIndex];
    shortName = shortName.replace(' ', '');
    shortName = shortName.replace('-', '');
    var improvingText = '<a href="./country/' + shortName + '">' + improvingCountry[imgIndex];
    improvingText = improvingText + '</a> (' + improvingChange[imgIndex] + ') is among the most improved.'                    
    
    shortName = decliningCountry[imgIndex];
    shortName = shortName.replace(' ', '');
    shortName = shortName.replace('-', '');
    var decliningText = '<a href="./country/' + shortName + '">' + decliningCountry[imgIndex];
    decliningText = decliningText + '</a> (' + decliningChange[imgIndex] + ') is among the most declined.';
    
    MM_setTextOfLayer('improvingCountryText','',improvingText);
    MM_setTextOfLayer('decliningCountryText','',decliningText);
    // set the time below for length of image display
    // i.e., "4*1000" is 4 seconds
    setTimeout("cycleImages()", 5*1000);
    imgIndex++;
}

cycleImages();
