function PresentationInformation(pID, totSlides, curIndex, format, previewId) 
{
	this.presentationID = pID;
	this.totalSlides = totSlides;
	this.currentSlideIndex = curIndex;
	this.slideFormat = format;
	this.previewContainerID = previewId
}

var Presentations = new Array();

function ShowNextSlide(presentationID, imageID, prevButtonID, nextButtonID, textArea) 
{
	var presentation = Presentations[presentationID];
	
	if ( presentation.totalSlides == 0 || (presentation.currentSlideIndex == presentation.totalSlides) ) 
	{
		return;
	}

	if ( presentation.currentSlideIndex == 1 ) 
	{
		document.getElementById(prevButtonID).src = "../includes/Images/btnPreviousSlide.gif";
	}
	
	presentation.currentSlideIndex++;

	if ( presentation.currentSlideIndex == presentation.totalSlides ) 
	{
		document.getElementById(nextButtonID).src = "../includes/Images/btnNextSlideDisabled.gif";
	}
	
	document.getElementById(textArea).innerHTML = presentation.currentSlideIndex;
	document.getElementById(imageID).src = FormatImageFileName(presentation.slideFormat, presentation.currentSlideIndex);
    GetPreviewSlideHtml(presentation);
}

function ShowPrevSlide(presentationID, imageID, prevButtonID, nextButtonID, textArea) 
{
	var presentation = Presentations[presentationID];
	
	if ( presentation.totalSlides == 0 || (presentation.currentSlideIndex == 1) ) 
	{
		return;
	}

	if ( presentation.currentSlideIndex == presentation.totalSlides ) 
	{
		document.getElementById(nextButtonID).src = "../includes/Images/btnNextSlide.gif";
	}

	presentation.currentSlideIndex--;

	if ( presentation.currentSlideIndex == 1 ) 
	{
		document.getElementById(prevButtonID).src = "../includes/Images/btnPreviousSlideDisabled.gif";
	}

	document.getElementById(textArea).innerHTML = presentation.currentSlideIndex;
	document.getElementById(imageID).src = FormatImageFileName(presentation.slideFormat, presentation.currentSlideIndex);
    GetPreviewSlideHtml(presentation);
}

function ToggleDetails(detailsPanelId, detailsButtonId, viewText, hideText)
{
    if (detailsPanelId)
    {
        var detailsPanel = document.getElementById(detailsPanelId);
        var detailsButton = document.getElementById(detailsButtonId);
        
        //Deatils have not been shown yet.
        if (detailsPanel.FadeState == null)
        {
            detailsPanel.FadeState = -2;  //Means totally opaque
            detailsPanel.style.opacity = 0;  //Set to toally opaque
            detailsPanel.style.filter = "alpha(opacity=0)"; //Set to toally opaque
            detailsPanel.style.visibility = "visible";  // make visible
        }

        if (detailsPanel.FadeState == 2)
        {
            detailsButton.alt = viewText;
            detailsButton.title = viewText;
        }
        else
        {
            detailsButton.alt = hideText;
            detailsButton.title = hideText;
        }

        FadeElement(detailsPanelId);
    }
}

function HideDetails(detailsPanelId, detailsButtonId, viewText)
{
    if (detailsPanelId)
    {
        var detailsPanel = document.getElementById(detailsPanelId)
        var detailsButton = document.getElementById(detailsButtonId)

        if (detailsPanel.FadeState == 2)
        {
            detailsButton.alt = viewText;
            detailsButton.title = viewText;
            FadeElement(detailsPanelId);
        }
    }
}

var TimeToFade = 250.0;

function FadeElement(eid)
{
    var element = document.getElementById(eid);
    if (element == null)
        return;

    if (element.FadeState == null)
    {
        if (element.style.opacity == null
        || element.style.opacity == ''
        || element.style.opacity == '1')
        {
            element.FadeState = 2;  //Not Opaque
        }
        else
        {
            element.FadeState = -2;  //Totally Opaque
        }
    }

    if (element.FadeState == 1 || element.FadeState == -1)
    {
        element.FadeState = element.FadeState == 1 ? -1 : 1;
        element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    }
    else
    {
        element.FadeState = element.FadeState == 2 ? -1 : 1;
        element.FadeTimeLeft = TimeToFade;
        setTimeout("AnimateFade(" + new Date().getTime()
        + ",'" + eid + "')", 33);
    }
}

function AnimateFade(lastTick, eid)
{
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var element = document.getElementById(eid);

    if (element.FadeTimeLeft <= elapsedTicks)
    {
        element.style.opacity = element.FadeState == 1 ? '1' : '0';
        element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
        element.FadeState = element.FadeState == 1 ? 2 : -2;
        return;
    }

    element.FadeTimeLeft -= elapsedTicks;
    var newOpVal = element.FadeTimeLeft / TimeToFade;
    if (element.FadeState == 1)
        newOpVal = 1 - newOpVal;

    element.style.opacity = newOpVal;
    element.style.filter =
      'alpha(opacity = ' + (newOpVal * 100) + ')';

    setTimeout("AnimateFade(" + curTick
      + ",'" + eid + "')", 33);
}

function FormatImageFileName(slideFormat, slideIndex) 
{
    var slidePath = String.format(slideFormat, slideIndex);
	return slidePath;
}

function SetErrorSlide(imageID, presentationID) 
{
	var presentation = Presentations[presentationID];
	document.getElementById(imageID).src = "../includes/Images/SlideNotFound.jpg";
	GetNoSlidePreviewHtml(presentation);
}

// Move an element directly on top of another element (and optionally
// make it the same size)
function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = (location.y - 97) + 'px';
    top.style.left = (location.x - 291) + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

//Gets a value from the server.
function GetPreviewSlideHtml(presentation) 
{
    PageMethods.GetPreviewSlideHtml(presentation.presentationID, presentation.currentSlideIndex, GetPreviewSlideHtmlSucceeded, GetPreviewSlideHtmlFailed, presentation);
}

// Callback function invoked on successful 
// completion of the page method.
function GetPreviewSlideHtmlSucceeded(previewHTML, presentation, methodName) 
{
    if (methodName == "GetPreviewSlideHtml")
    {
        var previewContainer = $get(presentation.previewContainerID);
        previewContainer.innerHTML = previewHTML;
    }
}

// Callback function invoked on failure 
// of the page method.
function GetPreviewSlideHtmlFailed(error, userContext, methodName) 
{
    if(error !== null) 
    {
        if (methodName == "GetPreviewSlideHtml")
        {
            alert( "An error occurred while retrieving the slide preview: " + error.get_message());
        }
    }
}






//Gets a value from the server.
function GetNoSlidePreviewHtml(presentation) 
{
    PageMethods.GetNoSlidePreviewHtml(GetNoSlidePreviewHtmlSucceeded, GetNoSlidePreviewHtmlFailed, presentation);
}

// Callback function invoked on successful 
// completion of the page method.
function GetNoSlidePreviewHtmlSucceeded(previewHTML, presentation, methodName) 
{
    if (methodName == "GetNoSlidePreviewHtml")
    {
        var previewContainer = $get(presentation.previewContainerID);
        previewContainer.innerHTML = previewHTML;
    }
}

// Callback function invoked on failure 
// of the page method.
function GetNoSlidePreviewHtmlFailed(error, userContext, methodName) 
{
    if(error !== null) 
    {
        if (methodName == "GetNoSlidePreviewHtml")
        {
            alert( "An error occurred while retrieving the slide preview: " + error.get_message());
        }
    }
}




