﻿// JScript File


// The PreviewItem Class
function PreviewItem(DisplayText,AlternativeText,URL)
{
    this.DisplayText=DisplayText;
    this.AlternativeText=AlternativeText;
    this.URL=URL;
}

// Global Variables
var glbPreviewLink;
var glbPreviewMessage;
var glbAlternativeText;
var glbItemCount = 0;
var glbPreviewProgress = 'start';

// Array to hold PreviewItem collection
var arNewsBlurbs = new Array();

// Function to handle PreviewItem click
function fnOpenPreviewLink()
{
    window.location.href = glbPreviewLink;
}

// Function to switch previews
function fnPreviews()
{
    if (arNewsBlurbs.length > 0)
    {
        // Create a PreviewItem based on the current PreviewItem collection object
        var CurrentPreviewItem = new PreviewItem('','');
        CurrentPreviewItem = arNewsBlurbs[glbItemCount];
        
        // Set the URL and Display Message for the Preview
        glbPreviewLink = CurrentPreviewItem.URL;
        glbPreviewMessage = CurrentPreviewItem.DisplayText;
        glbAlternativeText = CurrentPreviewItem.AlternativeText;
        
        if (glbPreviewProgress == 'start')
        {
                        
            // Call function to fade in the new preview
            fnFadeIn();

            document.getElementById('divPreviews').innerHTML = glbPreviewMessage;
            document.getElementById('divPreviews').title = glbAlternativeText;
            
            if (glbItemCount >= arNewsBlurbs.length - 1)
            {
                // Reset the PreviewItem sentinal value
                glbItemCount = 0;
            }
            else
            {
                // Increment the PreviewItem sentinal value
                glbItemCount += 1;
            }
        }
        
        t=setTimeout("fnPreviews()",10000);
    }
}

// Global variable to remember fade state
var glbFadeOpc = 0;

// Function to fade the in the new PreviewItem
function fnFadeIn()
{
    var opc = '0';
    
    // Determine whether the element is not opaque
    if(glbFadeOpc < 10)
    {
        switch (glbFadeOpc)
        {
            case 0:
                opc='10';
                break;
            case 1:
                opc='20';
                break;
            case 2:
                opc='30';
                break;
            case 3:
                opc='40';
                break;
            case 4:
                opc='50';
                break;
            case 5:
                opc='60';
                break;
            case 6:
                opc='70';
                break;
            case 7:
                opc='80';
                break;
            case 8:
                opc='90';
                break;
            case 9:
                opc='100';
                break;
        }
        
        // Increment for next time around
        glbFadeOpc += 1;
        
        // Get the style object for the element to be faded in
        styleObj=document.getElementById('divPreviews').style;
        
        // Set the opacity for various browsers
        styleObj.opacity = (opc / 100); 
        styleObj.MozOpacity = (opc / 100); 
        styleObj.KhtmlOpacity = (opc / 100); 
        styleObj.filter = "alpha(opacity=" + opc + ")";
        
        //document.getElementById('spnFadeCounter').innerHTML = opc;
        
        // Repeat after 0.1 of a second
        s=setTimeout("fnFadeIn()",100);
    
    }
    else
    {
        glbFadeOpc = 0;
    }

}

function fnPreviewProgress(action)
{
    glbPreviewProgress = action
}
