function objTEDDSDownloads (sName, aArray, iDisplay) {
        this.currId = -1;
        if (aArray)
        {
                this.aDownloads = aArray;
        } else {
                this.aDownloads = new Array();
        };

        this.name = sName;
        this.speed = 5000;
        this.displayNo = iDisplay;
        this.timer = 0;
        this.paused = false;
        this.len = this.aDownloads.length;
  	this.objDIV = null;
};

objTEDDSDownloads.prototype.setup = setupDownloads
objTEDDSDownloads.prototype.show = showDownloads
objTEDDSDownloads.prototype.next = nextDownloads
objTEDDSDownloads.prototype.play = playDownloads
objTEDDSDownloads.prototype.pause = pauseDownloads
objTEDDSDownloads.prototype.resume = resumeDownloads

function setupDownloads(){
        this.objDIV = objById('latest_downloads');
        with (this)     
        {
                if (objDIV) {
                        objDIV.onmouseover = pause;
                        objDIV.onmouseout = resume;
                        play();
                } else {
                        clearTimeout(timer);
                        timer = setTimeout(name+'.setup()', speed);
                };
        };
};

function nextDownloads()
{
        with (this)
        {
                currId++;
                if (currId >= aDownloads.length)
                {
                        currId = 0;
                };
                show(currId);
        };
};

function playDownloads()
{
  with(this)
  {
        if (!paused){
                next();
        }

        clearTimeout(timer);
        timer = setTimeout(name+'.play()', speed);
  };
};

function pauseDownloads()
{
        this.paused = true;
};

function resumeDownloads()
{
        this.paused = false;
};

function showDownloads(aId){
        with (this)
        {
                var lHTML = '<ul>';
                if (len < displayNo) {
                        var lShow = len;
                } else {
                        var lShow = displayNo;
                };
                for (i=0; i< lShow; i++){
                        if ((aId + i) < len) {
                                lHTML += '<li><a href="http://www.cscworld.com/tedds/downloads.html">' + aDownloads[(aId+i)] + '</a></li>';
                        } else {
                                lHTML += '<li><a href="http://www.cscworld.com/tedds/downloads.html">' + aDownloads[((aId+i)-len)] + '</a></li>';
                        };
                };
                objDIV.innerHTML = lHTML;
        };
};

var DownloadList = [
	'RC Wall Design (EN 1992-1)',
	'Rigid Diaphragm Force Distribution',
	'RC Column Design (EN1992-1)',
	'Timber Joist Design (BS5268)',
	'Structural Wood Beam (NDS 2005)'
        ];


function createDownloads ()
{
	TEDDSDownloads1 = new objTEDDSDownloads('TEDDSDownloads1', DownloadList, 3);
	TEDDSDownloads1.setup();
}

addLoadEvent(createDownloads);