﻿  
    function pageLoad()
    {
        // we can't have the hidden frame div visibility:hidden initially
        // because the fade doesn't work.  The next function is necessary
        // to hide it prior setting the text.
        new AjaxControlToolkit.Animation.FadeOutAnimation($get(hiddenID),.1,15,0,0,true).play();
        GetContentLength();
        setInterval("doAnimation();",timeInterval);
    }
    
    // using web request to get content
    function ServerGetNextContent()
    {
        var wRequest = new Sys.Net.WebRequest();
        wRequest.set_url(contentUrl); 
        wRequest.set_httpVerb("GET");
        wRequest.add_completed(OnRequestCompleted);
        wRequest.invoke();
    }
    
    // using web service to get content
    function ServiceGetNextContent()
    {
        Fader.HypnoQuote.NextQuote(curIndex,OnServiceRequestCompleted);    
        curIndex =  curIndex < contentLength-1 ? curIndex + 1:0;
    }
    
    function GetContentLength()
    {
        Fader.HypnoQuote.GetContentLength(OnGetContentLengthCompleted);
    }
        
    // callback function for webservice
    function OnServiceRequestCompleted(result, eventArgs)
    {
        var pnl = $get(hiddenID);
        pnl.innerHTML = result;
        crossFade();
    }
    
    function OnGetContentLengthCompleted(result, eventArgs)
    {
        contentLength = result;
        ServiceGetNextContent();
    }
    
    // callback function for asynchronous GET
    function OnRequestCompleted(executor, eventArgs)
    {
        if(executor.get_responseAvailable())
        {
            var pnl = $get(hiddenID);
            pnl.innerHTML = executor.get_responseData();
            crossFade();
        }
    } 
        
    function doAnimation()
    {
        var pnVisible = $get(visibleID);
        var pnHidden = $get(hiddenID);
        ServiceGetNextContent();
    }
    
    function swapBuffers()
    {
        var x = visibleID;
        visibleID = hiddenID;
        hiddenID = x;
    }
    
    function crossFade()
    {
        var pnVisible = $get(visibleID);
        var pnHidden = $get(hiddenID);
        var fadeout = new $AA.FadeOutAnimation(pnVisible,transitionTime,25,0,1,true);
        var fadein = new AjaxControlToolkit.Animation.FadeInAnimation(pnHidden,transitionTime,25,0,1,true);
        var paral = new AjaxControlToolkit.Animation.ParallelAnimation(pnVisible,transitionTime,25,[fadeout,fadein],1);
        var animSeq = new AjaxControlToolkit.Animation.SequenceAnimation(pnVisible, transitionTime, 25, [paral], 1);
        animSeq.play();
        swapBuffers();
    }

