﻿    var g_ViewerTimeout;
    var g_TimerSet = false;
    var g_Current = 0;
    var g_Num = 0;
    var g_Images;

    function rotate()
    {
        //clear the timer just in case 
        if(g_TimerSet)
        {
           window.clearTimeout(g_ViewerTimeout);
           g_TimerSet = false;  
        }
        
        g_Current = (g_Current + 1) % g_Num;
        document.getElementById("viewerimage").src = g_Images[g_Current]; 
        g_ViewerTimeout = window.setTimeout(rotate, 5000); 
        g_TimerSet = true;
    }
    
    function stopviewer()
    {
        window.clearTimeout(g_ViewerTimeout);
        g_TimerSet = false; 
        document.getElementById("stop").style.backgroundPosition = "bottom left";
        document.getElementById("start").style.backgroundPosition = "top right";
    }
    
    function startviewer()
    {
        rotate();
        document.getElementById("stop").style.backgroundPosition = "top left";
        document.getElementById("start").style.backgroundPosition = "bottom right";        
    }
    
    function setviewer(images)
    {
        g_Images = images.split(',');
        g_Num = g_Images.length;
        g_ViewerTimeout = window.setTimeout(rotate, 5000);
        g_TimerSet = true;
    }
    
    //window.onload = window_onload;