function SlideShow()
{
    this.imgId = '';
    this.labelId = '';
    this.countId = '';
    this.pictureArray = new Array();
    this.pictureIndex = 0;
    this.IsLoaded = false;
    this.landingZoneId = '';
    this.loadingZoneId = '';
    this.slideShowRunning = false;
    this.startId = '';
    this.stopId = '';
    this.prevId = '';
    this.nextId = '';
    
    this.Init = function(imgid, labelid, countId, landingZoneId, loadingZoneId, startId, stopId, prevId, nextId)
    {
        this.imgId = imgid;
        this.labelId = labelid;
        this.countId = countId;
        this.pictureArray = new Array();
        this.pictureIndex = 0;
        this.IsLoaded = false;
        this.landingZoneId = landingZoneId;
        this.loadingZoneId = loadingZoneId;
        this.slideShowRunning = false;
        this.startId = startId;
        this.stopId = stopId;
        this.prevId = prevId;
        this.nextId = nextId;
        this.timeoutId = null;
    }
    this.Add = function(img, tooltip)
    {
        this.pictureArray.push(new Array(img, tooltip));
    }
    this.Next = function()
    {
        if (this.pictureArray.length > 0)
        {
            if (this.pictureIndex < this.pictureArray.length-1)
            {
                this.pictureIndex = this.pictureIndex + 1;
            }
            else
            {
                this.pictureIndex = 0;
            }
            OnPopupPicturePropSet(this, this.pictureIndex);
        }
    }
    this.Prev = function()
    {
        if (this.pictureArray.length > 0)
        {
            if (this.pictureIndex > 0)
            {
                this.pictureIndex = this.pictureIndex - 1;
            }
            else
            {
                this.pictureIndex = this.pictureArray.length - 1;
            }
            OnPopupPicturePropSet(this, this.pictureIndex);
        }
    }
    this.NextObject = function(obj) 
    {
	    var n = obj;
	    do n = n.nextSibling;
	    while (n && n.nodeType != 1);
	    return n;
    }
    this.PreviousObject = function(obj) 
    {
	    var p = obj;
	    do p = p.previousSibling;
	    while (p && p.nodeType != 1);
	    return p;
    }
    this.SetRunningState = function(slideShowRunning)
    {
        this.slideShowRunning = slideShowRunning;
        if (this.slideShowRunning)
        {
            var obj = document.getElementById(this.startId);
            var nextSibling;var prevSibling;
            if (obj != null)
            {
                obj.style.display = 'none';
                nextSibling = this.NextObject(obj);
                if (nextSibling != null) nextSibling.style.display = '';
            }
            obj = document.getElementById(this.stopId);
            if (obj != null)
            {
                obj.style.display = '';
                prevSibling = this.PreviousObject(obj);
                if (prevSibling != null) prevSibling.style.display = 'none';
            }
            obj = document.getElementById(this.prevId);
            if (obj != null)
            {
                obj.style.display = 'none';
                nextSibling = this.NextObject(obj);
                if (nextSibling != null) nextSibling.style.display = '';
            }
            obj = document.getElementById(this.nextId);
            if (obj != null)
            {
                obj.style.display = 'none';
                nextSibling = this.NextObject(obj);
                if (nextSibling != null) nextSibling.style.display = '';
            }
            this.timeoutId = null;
        }
        else
        {
            var obj = document.getElementById(this.startId);
            var nextSibling;var prevSibling;
            if (obj != null)
            {
                obj.style.display = '';
                nextSibling = this.NextObject(obj);
                if (nextSibling != null) nextSibling.style.display = 'none';
            }
            obj = document.getElementById(this.stopId);
            if (obj != null)
            {
                obj.style.display = 'none';
                prevSibling = this.PreviousObject(obj);
                if (prevSibling != null) prevSibling.style.display = '';
            }
            obj = document.getElementById(this.prevId);
            if (obj != null)
            {
                obj.style.display = '';
                nextSibling = this.NextObject(obj);
                if (nextSibling != null) nextSibling.style.display = 'none';
            }
            obj = document.getElementById(this.nextId);
            if (obj != null)
            {
                obj.style.display = '';
                nextSibling = this.NextObject(obj);
                if (nextSibling != null) nextSibling.style.display = 'none';
            }
            if (this.timeoutId != null)
            {
                clearTimeout(this.timeoutId)
                this.timeoutId = null;
            }
        }
    }
}
var gRunningSlideshow = null;
function OnPopupSlidshowStart(slideShow)
{
    gRunningSlideshow = slideShow;
    slideShow.SetRunningState(true);
    slideShow.Next();
}
function OnPopupSlideshowStop(slideShow)
{
    gRunningSlideshow = null;
    slideShow.SetRunningState(false);
}
function OnPopupPictureNextSet(slideShow)
{
    slideShow.Next();
}
function OnPopupSlideshowNext()
{
    if (gRunningSlideshow != null)
    {
        if (gRunningSlideshow.slideShowRunning)
        {
            gRunningSlideshow.Next();
        }
    }
}
function OnPopupPicturePrevSet(slideShow)
{
    slideShow.Prev();
}
var plLandingZoneId;var plLoadingZoneId;var plCountId;var plIndex;var plLength;var plLoaded;
function OnPopupImageLoaded()
{
    document.getElementById(plCountId).innerHTML = plIndex + '&nbsp;/&nbsp;' + plLength;

    //document.getElementById(plLandingZoneId).style.display = '';
    document.getElementById(plLoadingZoneId).style.display = 'none';

    if (gRunningSlideshow != null)
    {
        if (gRunningSlideshow.slideShowRunning)
        {
            if (plLoaded == false)
            {
                plLoaded = true;
                var fn = function(){
                    OnPopupSlideshowNext();
                }
                gRunningSlideshow.timeoutId = setTimeout(fn, 5000); 
            }
        }
    }
}
function OnPopupPicturePropSet(slideShow, index)
{
    //document.getElementById(slideShow.landingZoneId).style.display = 'none';
    document.getElementById(slideShow.loadingZoneId).style.display = '';

    plLandingZoneId = slideShow.landingZoneId;
    plLoadingZoneId = slideShow.loadingZoneId;
    plCountId = slideShow.countId;
    plIndex = index + 1;
    plLength = slideShow.pictureArray.length;

    var img = document.getElementById(slideShow.imgId);
    img.onload = OnPopupImageLoaded;
    plLoaded = false;img.src = slideShow.pictureArray[index][0];
    img.alt = img.title = slideShow.pictureArray[index][1];
    var lbl = document.getElementById(slideShow.labelId);
    lbl.title = lbl.alt = slideShow.pictureArray[index][1];

    slideShow.pictureIndex = index;
}
function OnClosePicturePopup(slideShow)
{
    var img = document.getElementById(slideShow.imgId);
    img.src = "images/modules/photogallery/blank.png";
    img.alt = img.title = "";
    var lbl = document.getElementById(slideShow.labelId);
    lbl.title = lbl.alt = "";
    document.getElementById(slideShow.countId).innerHTML = "";

    gRunningSlideshow = null;
    slideShow.SetRunningState(false);
}
try
{
    if (typeof Sys == 'undefined')
    {
        ;
    }
    else
    {
        if( Sys && Sys.Application ){
           Sys.Application.notifyScriptLoaded();
        }
    } 
}
catch(e)
{
;
}
