﻿/// <reference name="MicrosoftAjax.js"/>

function GetHTMLContent(listUrl, phContent, scrollRate, wpId, nextContentIndex, cacheTimespan) {
    var userContext = [];
    Array.add(userContext, phContent);
    Array.add(userContext, scrollRate);
    Array.add(userContext, nextContentIndex);

    var ret = PSP3HTMLContentViewer.Services.HTMLContentViewer.GetHtmlContent(listUrl, wpId, cacheTimespan, onComplete, onError, userContext);
    return (true);
}

function RotateHtmlContents(args, userContext) {    
    var phContent = userContext[0];
    var scrollRate = userContext[1];
    var nextContentIndex = userContext[2];

    var obj = $get(phContent);
    if (obj != null) {        
        obj.innerHTML = args[nextContentIndex];
    }

    if (nextContentIndex >= (args.length - 1)) {
        nextContentIndex = 0;
    } else {
        nextContentIndex++;
    }

    userContext[2] = nextContentIndex;

    setTimeout(function() { RotateHtmlContents(args, userContext); }, scrollRate);
}

function onComplete(args, userContext) {
    RotateHtmlContents(args, userContext);
}

function onError(args) {
    //alert('An error occured when retrieving values from the server.');
}