﻿// JScript File


// js functions for the RotatingArticle.ascx


var milliseconds = 5000;
var i=1;
var int;
var old=-1;
var rotating=true;

function rotate(spec){
	if(spec!=null){
		i=spec;
		//control(0);
	}
	
	if(old!=-1) {
	    document.getElementById(old).style.display = 'none';
	} else {
	    document.getElementById(1).style.display = 'none';
	}
	
	//turn on selected div
	document.getElementById(i).style.display = 'block';
	
	//update counter
	document.getElementById('articlecounter').innerHTML = 'Article ' + i + ' of 8';
	
	old=i;
	i++;
	
	if(i>8)i=1;
}

function control(op){
	if(!op){
		document.getElementById('stop').style.display = 'none';
		document.getElementById('play').style.display = 'inline';
		clearInterval(int);
	} else {
		document.getElementById('stop').style.display = 'inline';
		document.getElementById('play').style.display = 'none';
		int = setInterval('rotate()', milliseconds);
	}
}

function initializeRotatingArticle() {
    int = setInterval('rotate()', milliseconds);
    document.getElementById(1).style.display = 'block';
}

function previous() {
    var icon = document.getElementById("startstopicon")    
    icon.src = "/Images/playbutton.png";
        
    clearInterval(int);  //pause
    rotating=false;    

    i--;
    i--;
    if(i<1)i=1;
    
    rotate(i);
         
}

function next() {
    var icon = document.getElementById("startstopicon")    
    icon.src = "/Images/playbutton.png";
    
    clearInterval(int);  //pause
    rotating=false;

    rotate(i);    
}

function togglestartstop() {

    var icon = document.getElementById("startstopicon")
   
    if (!rotating) {
        icon.src = "/Images/pausebutton.png";
        int = setInterval('rotate()', milliseconds);   //start   
        rotating=true; 
        rotate(i);           
    } else {         
        icon.src = "/Images/playbutton.png";
        clearInterval(int);  //pause   	                 
        rotating=false;
    }	    
}