var newsArray = new Array();
var nIndex = 0;
var timerID = null;

function rotateNews() {
    var len = newsArray.length;
    if(nIndex >= len) {
        nIndex = 0;
    }
    document.getElementById('divArticleSlide').innerHTML = newsArray[nIndex];
    nIndex++;
    timerID = setTimeout('rotateNews()', 5000);
    showhidePauseButton(true,len);
	showhidePlayButton(false, len); 
}

function pauseNews() {
	var len = newsArray.length
    if (timerID != null) {
        clearTimeout(timerID);
        timerID = null;
    }
    showhidePauseButton(false,len);
    showhidePlayButton(true,len);    
}

function playNews() {
    if (timerID == null) {
        timerID = setTimeout('rotateNews()', 1000);
    }
}


function makeNews(i,a,t,d,l,p,ia,as,at,iv,vs,vt,id,ds,dt,icount,iTotal) {
    this.img = i;
    this.alt = a;
    this.title = t;
    this.datestring =d;
    this.link = l;
    this.pullquote = p;
    this.imgaudio = ia;
    this.audiosrc = as;
    this.audiotxt = at;
    this.imgvideo = iv;
    this.videosrc = vs;
    this.videotxt = vt;
    this.imgdoc = id;
    this.docsrc = ds;
    this.doctxt = dt;
    this.itemcount = icount;
    this.itemTotal = iTotal;
    this.write = writeNews;
}

function writeNews() {
	var len = this.itemTotal;
	var nextstr = 0;
    var prevstr = 0;    
    var str = '';
    var stylestr = '';
    
    if ((this.itemcount - 1) == -1){
		prevstr = len - 1;
	} else {
		prevstr = (this.itemcount - 1);
	}
    if ((this.itemcount + 1) == len){
		nextstr = 0;
	} else {
		nextstr = (this.itemcount + 1);
	}
	stylestr = "showpanel";
	
	
	str += '<div id="panel' + this.itemcount + '" class="' + stylestr + '">';
    str += '<div class="top">';
    str += '    <div class="topleft">';
    str += '        <a href="' + this.link + '" alt="' + this.alt + '">';
    str += '            <img  src="' + this.img.src + '"/>';
    str += '        </a>';
    str += '    </div>';
    str += '		<div class="buttons">';
    str += '			<a href="javascript:switchpanel(' + prevstr + ');"><div class="previous">Previous</div></a>';
    str += '			<a href="javascript:pauseNews();"><div style="display: block; visibility: visible;" id="bntPause' + this.itemcount + '" class="pausebutton">Pause</div></a>';
    str += '			<a href="javascript:playNews();"><div id="bntPlay' + this.itemcount + '" style="display: none; visibility: hidden;" class="playbutton">Play</div></a>';
    str += '			<a href="javascript:switchpanel(' + nextstr + ');"><div class="next">Next</div></a>';
    str += '		</div>';
    str += '</div>';
    str += '<div class="bottom">';
    str += '    <h1>';
    str += '        <a href="' + this.link + '">' + this.title + '</a>';
    str += '    </h1>';
    str += '    <span class="pullquotedate">' + this.datestring + '</span>';
    str += '    <span class="pullquotetext">' + this.pullquote + '</span>';
    str += '	<div class="clearline">&nbsp;</div>';
    
    str += '    <div class="topright">';
    str += '			<div class="toprightrelated"></div>';
    if (this.audiosrc > ''){
		str += '<div class="related">';
		str += '		<a href="' + this.audiosrc + '">';
		str += '			<img class="rleft" src="' + this.imgaudio + '"/>';
		str += '		</a>';
		str += this.audiotxt;
		str += '</div>';
		str += '<div class="clearline"></div>';
    }
    
     if (this.videosrc > ''){
		str += '<div class="related">';
		str += '		<a href="' + this.videosrc + '">';
		str += '			<img class="rleft" src="' + this.imgvideo + '"/>';
		str += '		</a>';
		str += this.videotxt;
		str += '</div>';
		str += '<div class="clearline"></div>';
    }
     if (this.docsrc > ''){
		str += '<div><div class="related">';
		str += '		<a href="' + this.docsrc + '">';
		str += '			<img class="rleft" src="' + this.imgdoc + '"/>';
		str += '		</a>';
		str += this.doctxt;
		str += '</div>';
		str += '<div class="clearline"></div></div>';
    }
    str += '    </div>';
        
    
    str += '</div>';
    str += '</div>';
    
    return str;
}
function showhidePauseButton(flag,count) {
   for (ii=0; ii < count;ii++) {
		var bnt = GetObjectById('bntPause' + ii);
		Set_Visibility(bnt, flag);
   } 
}

function showhidePlayButton(flag,count) {
	for (ii = 0; ii < count;ii++) {
		var bnt = GetObjectById('bntPlay' + ii);
		Set_Visibility(bnt,flag);
	}
}

function GetObjectById(ObjectID) {    
    return document.getElementById(ObjectID);    
}


function Set_Visibility(myDiv, visibilityFlag) {   
    if (myDiv != null) {
        if (visibilityFlag == false) {
            myDiv.style.display='None';
            myDiv.style.visibility = "hidden";            
        } else {            
            myDiv.style.display='Block'; 
            myDiv.style.visibility = "visible";            
        }                
    }    
}
function switchpanel(activepanel){
	var len = newsArray.length;
	
	 document.getElementById('divArticleSlide').innerHTML = newsArray[activepanel];
}


 
