﻿var iIndex = 0;
//pickup the hidden variable from c# to populate the Feature Event
var myLabelValue = document.getElementById("hdnValue").value;

window.onload = function() { document.getElementById("Featured").innerHTML = myLabelValue + document.getElementById("dvPhilEventTitle" + iIndex).value; document.getElementById("Featured").href = document.getElementById("dvPhilEventLink" + iIndex).value; }
            
function changeNews(direction) {
    var iNext = iIndex + direction;
    if ( iNext < 0 )
        iNext = iCount - 1;
    else if ( iNext >= iCount )
        iNext = 0;
    
    if ( iNext > iIndex )
        scrollRight( document.getElementById("dvPhilBox").scrollLeft, iNext * 511, 2000 );
    else
        scrollRight( document.getElementById("dvPhilBox").scrollLeft, iNext * 511, 2000 );
        
    iIndex = iNext;
    //use myLabelValue - from hidden variable
    document.getElementById("Featured").innerHTML = myLabelValue + document.getElementById("dvPhilEventTitle" + iIndex).value;
    document.getElementById("Featured").href = document.getElementById("dvPhilEventLink" + iIndex).value;
}

function scrollRight( startLoc, endLoc, duration ) {
    var diff = endLoc - startLoc;
    
    duration = duration / 100;
    
    scroll(endLoc, Math.round(diff/duration));
}

function scrollLeft( startLoc, endLoc, duration ) {
    var diff = endLoc - startLoc;
    
    duration = duration / 100;
    
    scroll(endLoc, Math.round(diff/duration) * -1);
}

function scroll( endLoc, movement ) {
    document.getElementById("dvPhilBox").scrollLeft += movement; 
    
    if ( movement > 0 ) {
        if ( document.getElementById("dvPhilBox").scrollLeft + movement < endLoc ) {
            setTimeout("scroll(" + endLoc + "," + movement + ");",20);
        } else {
            document.getElementById("dvPhilBox").scrollLeft = endLoc;
        }
    } else {
        if ( document.getElementById("dvPhilBox").scrollLeft + movement > endLoc ) {
            setTimeout("scroll(" + endLoc + "," + movement + ");",20);
        } else {
            document.getElementById("dvPhilBox").scrollLeft = endLoc;
        }
    }
}