/*
**
** Shout Slideshow: JavaScript Slideshow Class
** Created 23.02.2011
**
** $VER: shout.slideshow.js 1.4 (19.05.2011)
**
** Outstanding Issues (05.04.2011):
**  - Pause/Restart video if playing offscreen
**
*/

/* global flags */
var SHOUT_Slideshow_Next                    = -1;
var SHOUT_Slideshow_Previous                = -2;
var SHOUT_Slideshow_Current                 = -3;

var SHOUT_Slideshow_Video_ZIndex            = 1;
var SHOUT_Slideshow_Video_OffScreen         = 2;
var SHOUT_Slideshow_Video_PreLoad           = 3;

var SHOUT_Slideshow_Transition_Fade         = 1;
var SHOUT_Slideshow_Transition_SlideOver    = 2;
var SHOUT_Slideshow_Transition_SlidePush    = 3;

var SHOUT_Slideshow_Top                     = -1;
var SHOUT_Slideshow_Bottom                  = -2;

/* slideshow class */
function SlideShow(listctrl, seconds, loading, transition, videomode)
    {
        /* global class pointer */
        var _this = this;

        /* public variables */
        this.DebugMode = false;
        this.Playing = false;                                                       /* private */
        this.DisableiDeviceVideos = true;

        this.Width = 0;
        this.Height = 0;
        this.TimerObject = -1;                                                      /* private */
        this.TimeOut = seconds * 1000;                                              /* private */
        this.AudioLevel = 50;
        this.Transition = (typeof transition == 'undefined') ? SHOUT_Slideshow_Transition_Fade:transition;
        this.TransitionTime = 500;

        this.VideoMode = (typeof videomode == 'undefined') ? SHOUT_Slideshow_Video_ZIndex:videomode;
        this.MoveToX = 0;
        this.MoveToY = 0;
        this.FrameOffsetX = -1;                                                     /* private */
        this.FrameOffsetY = -1;                                                     /* private */
        this.OffScreenResize = true;
        this.OffScreenWidth = 1;
        this.OffScreenHeight = 1;

        this.ShowLoadingAnimation = (typeof loading == 'undefined') ? true:loading; 
        this.LoadingTimeOut = 1500;                                                 /* private */
        this.LoadingFadeTimeOut = 2000;                                             /* private */

        this.ListControl = listctrl;                                                /* private */
        this.ReferenceControl = '';
                
        this.CurrentSlide = 0;                                                      /* private */
        this.SlideData = new Array();                                               /* private */
        this.SlideCount = $(this.ListControl + ' li').size();                       /* private */
        this.VideoCount = $(this.ListControl + ' li.video').size();                 /* private */

        this.DelayCallBacks = false;
        this.CBVideoStart = null;
        this.CBVideoEnd = null;        
        this.CBVideoMouseOver = null;
        this.CBVideoMouseOut = null;
        
        this.FlowPlayerSWF = '';
        this.FlowPlayerKey = '';
        this.FlowPlayerWMode = 'window';
        this.FlowPlayerNCUrl = '';

        /* public prototypes */
        this.Play = SS_Play;
        this.Start = SS_Start;
        this.Pause = SS_Pause;
        this.Resume = SS_Resume;
        this.Toggle = SS_Toggle;
        this.Stop = SS_Stop;
        this.NextSlide = SS_NextSlide;
        this.PreviousSlide = SS_PreviousSlide;
        this.UpdateSelectedReference = SS_UpdateSelectedReference;
        this.InsertSlide = SS_InsertSlide;
        this.InsertOverlay = SS_InsertOverlay;
        this.StartTimer = SS_StartTimer;                                            /* private */
        this.StopTimer = SS_StopTimer;                                              /* private */
        this.StartVideo = SS_StartVideo;                                            /* private */
        this.PlayVideo = SS_PlayVideo;                                              /* private */
        this.StopVideo = SS_StopVideo;                                              /* private */
        this.PauseVideo = SS_PauseVideo;                                            /* private */
        this.ResumeVideo = SS_ResumeVideo;                                          /* private */
        this.ToggleVideoPlayback = SS_ToggleVideoPlayback;                          /* private */
        this.SlideField = SS_SlideField;                                            /* private */
        this.SlideIndex = SS_SlideIndex;                                            /* private */
        this.MoveOffScreen = SS_MoveOffScreen;                                      /* private */
        this.MoveOnScreen = SS_MoveOnScreen;                                        /* private */
        this.BuildSlideData = SS_BuildSlideData;                                    /* private */
        this.DebugInfo = SS_DebugInfo;                                              /* private */

        /* collect slide information */
        this.BuildSlideData();

        /* setup controls */
        $(this.ListControl + ' li:first').addClass('active');

        /* functions */
        function SS_Play()
            {
                var _this = this;

                /* move videos offscreen if needed */
                if(this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                    {
                        $(this.ListControl + ' li').each(function(index)
                            {
                                if((_this.SlideData[index]['type'] == 'video'))
                                    {
                                        _this.MoveOffScreen(null, index);
                                    }
                            });
                    }

                /* display loading banner */
                if(this.ShowLoadingAnimation != false)
                    {
                        $("<li class='loading'></li>").appendTo(this.ListControl);
                        setTimeout( function()
                            { 
                                $(_this.ListControl + ' li.loading').fadeOut(_this.LoadingFadeTimeOut, function()
                                    {
                                        /* remove loading slide */
                                        $(_this.ListControl + ' li.loading').remove();

                                        /* start slideshow */
                                        _this.Start();
                                    });                        
                             }, this.LoadingTimeOut);
                    }
                else
                    {
                        /* start slideshow */
                        this.Start();
                    }
            }

        function SS_Start()
            {
                /* check if the next slide to fade in is a video -(window mode or offscreen and type is video) */
                if(((this.FlowPlayerWMode == 'window') || (this.VideoMode == SHOUT_Slideshow_Video_OffScreen)) && (this.SlideField(SHOUT_Slideshow_Next, 'type') == 'video'))
                    {
                        /* start buffering before it starts */
                        this.StartVideo(SHOUT_Slideshow_Next);
                    }

                /* start timer if current slide isn't a video */
                if(this.SlideField(SHOUT_Slideshow_Current, 'type') != 'video') this.StartTimer();

                /* update flag */
                this.Playing = true;

                this.DebugInfo();
            }
            
        function SS_Pause()
            {
                this.Stop();
                this.PauseVideo();
                
                this.DebugInfo();
            }
            
        function SS_Resume()
            {
                this.Start();
                this.ResumeVideo();
                
                this.DebugInfo();
            }

        function SS_Toggle()
            {
                if(this.Playing != false)
                    {
                        this.Pause();
                    }
                else
                    {
                        this.Resume();
                    }
            }

        function SS_Stop()
            {
                this.StopTimer();
                this.Playing = false;
                
                this.DebugInfo();
            }

        function SS_NextSlide(stop, manual)
            {
                var _this = this;

                /* update slide counter */
                this.CurrentSlide = this.CurrentSlide + 1;
                if(this.CurrentSlide == this.SlideCount) this.CurrentSlide = 0;
                this.UpdateSelectedReference();
                
                /* update slide references */
                var active = $(this.ListControl + ' li.active');
                if(active.length == 0 ) active = $(this.ListControl + ' li:last');
                var next =  active.next().length ? active.next() : $(this.ListControl + ' li:first');
                active.addClass('last-active');

                /* stop timer if requested */
                if(stop != false) this.StopTimer();

                /* restart timer if manually called */
                if(manual != false && stop != true) this.StartTimer();

                /* check if the next slide to fade in is a video -(window mode or offscreen and type is video) */
                if(((this.FlowPlayerWMode == 'window') || (this.VideoMode == SHOUT_Slideshow_Video_OffScreen)) && (this.SlideField(SHOUT_Slideshow_Next, 'type') == 'video'))
                    {
                        /* start buffering before it starts */
                        this.StartVideo(SHOUT_Slideshow_Next);
                    }

                /* stop current video playing if manually navigated to next slide */
                if((manual != false) && (this.SlideField(SHOUT_Slideshow_Previous, 'type') == 'video')) this.StopVideo(SHOUT_Slideshow_Previous);

                /* video specific functionality */
                if(this.SlideField(SHOUT_Slideshow_Current, 'type') == 'video')
                    {
                        /* stop timer if video playing */
                        this.StopTimer();

                        if(this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                            {
                                /* move video into focus if offscreen */
                                this.MoveOnScreen(null, SHOUT_Slideshow_Current);

                                /* if delay callbacks is enabled, execute now */
                                if(this.DelayCallBacks != false) this.CBVideoStart();
                            }
                        else
                            {
                                /* normal playback */
                                if(this.FlowPlayerWMode != 'window') this.StartVideo(SHOUT_Slideshow_Current);
                            }
                    }

                /* slide transition */
                switch(this.Transition)
                    {
                        default:
                        case SHOUT_Slideshow_Transition_Fade:
                            {
                                next.css({opacity: 0.0})
                                    .addClass('active')
                                    .animate({opacity: 1.0}, _this.TransitionTime, function()
                                        {
                                            SS_NextSlideFinish(active, _this);
                                        });
                            }
                        break;

                        case SHOUT_Slideshow_Transition_SlideOver:
                        case SHOUT_Slideshow_Transition_SlidePush:
                            {
                                /* move current slide too */
                                if(this.Transition == SHOUT_Slideshow_Transition_SlidePush)
                                    {
                                        active.animate({left: '-' + this.Width}, _this.TransitionTime + 50, function() { active.css({left: '0px'}); });
                                    }

                                /* slide next slide in */
                                next.css({left: this.Width})
                                    .addClass('active')
                                    .animate({left: '0px'}, _this.TransitionTime, function()
                                        {
                                            SS_NextSlideFinish(active, _this);
                                        });
                            }
                        break;
                    }

                this.DebugInfo();
            }

        function SS_NextSlideFinish(active, obj)
            {
                active.removeClass('active last-active');

                /* move previous video off-screen AFTER transition */
                if(_this.SlideField(SHOUT_Slideshow_Previous, 'type') == 'video')
                    {
                        if(_this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                            {
                                /* if delay callbacks is enabled, execute now */
                                if(_this.DelayCallBacks != false) _this.CBVideoEnd();

                                /* move back off-screen */
                                _this.MoveOffScreen(null, SHOUT_Slideshow_Previous);
                            }
                    }
            }

        function SS_PreviousSlide(stop, manual)
            {
                /* update slide counter */
                this.CurrentSlide = this.CurrentSlide - 1;
                if(this.CurrentSlide == -1) this.CurrentSlide = this.SlideCount - 1;
                this.UpdateSelectedReference();

                /* update slide references */
                var active = $(this.ListControl + ' li.active');
                if(active.length == 0 ) active = $(this.ListControl + ' li:first');
                var prev =  active.prev().length ? active.prev() : $(this.ListControl + ' li:last');
                active.addClass('last-active');

                /* stop timer if requested */
                if(stop != false) this.StopTimer();

                /* restart timer if manually called */
                if(manual != false && stop != true) this.StartTimer();

                /* check if the next slide to fade in is a video -(window mode or offscreen and type is video) */
                if(((this.FlowPlayerWMode == 'window') || (this.VideoMode == SHOUT_Slideshow_Video_OffScreen)) && (this.SlideField(SHOUT_Slideshow_Previous, 'type') == 'video'))
                    {
                        /* start buffering before it starts */
                        this.StartVideo(SHOUT_Slideshow_Previous);
                    }

                /* stop video if manually navigated */
                if((manual != false) && (this.SlideField(SHOUT_Slideshow_Next, 'type') == 'video')) this.StopVideo(SHOUT_Slideshow_Next);

                /* video specific functionality */
                if(this.SlideField(SHOUT_Slideshow_Current, 'type') == 'video')
                    {
                        /* stop timer if video playing */
                        this.StopTimer();

                        if(this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                            {
                                /* move video into focus if offscreen */
                                this.MoveOnScreen(null, SHOUT_Slideshow_Current);

                                /* if delay callbacks is enabled, execute now */
                                if(this.DelayCallBacks != false) this.CBVideoStart();
                            }
                        else
                            {
                                /* normal playback */
                                if(this.FlowPlayerWMode != 'window') this.StartVideo(SHOUT_Slideshow_Current);
                            }
                    }

                /* slide transition */
                switch(this.Transition)
                    {
                        default:
                        case SHOUT_Slideshow_Transition_Fade:
                            {
                                prev.css({opacity: 0.0})
                                    .addClass('active')
                                    .animate({opacity: 1.0}, _this.TransitionTime, function()
                                        {
                                            SS_PreviousSlideFinish(active, _this);
                                        });
                            }
                        break;

                        case SHOUT_Slideshow_Transition_SlideOver:
                        case SHOUT_Slideshow_Transition_SlidePush:
                            {
                                /* move current slide too */
                                if(this.Transition == SHOUT_Slideshow_Transition_SlidePush)
                                    {
                                        active.animate({left: this.Width}, _this.TransitionTime + 50, function() { active.css({left: '0px'}); });
                                    }

                                /* slide next slide in */
                                prev.css({left: '-' + this.Width})
                                    .addClass('active')
                                    .animate({left: '0px'}, _this.TransitionTime, function()
                                        {
                                            SS_PreviousSlideFinish(active, _this);
                                        });
                            }
                        break;
                     }

                this.DebugInfo();
            }

        function SS_PreviousSlideFinish(active, obj)
            {
                active.removeClass('active last-active');

                /* move previous video off-screen AFTER fade in */
                if(_this.SlideField(SHOUT_Slideshow_Next, 'type') == 'video')
                    {
                        if(_this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                            {
                                /* if delay callbacks is enabled, execute now */
                                if(_this.DelayCallBacks != false) _this.CBVideoEnd();

                                /* move back off-screen */
                                _this.MoveOffScreen(null, SHOUT_Slideshow_Next);
                            }
                    }
            }

        function SS_UpdateSelectedReference()
            {
                if(this.ReferenceControl != '')
                    {
                        var _this = this;
                        
                        /* remove current reference */
                        $(this.ReferenceControl + '.selected').removeClass('selected');

                        /* set new selected reference */
                        $(this.ReferenceControl).each(function(index)
                            {
                                if(index == _this.CurrentSlide)
                                    {
                                        $(this).addClass('selected');
                                        return;
                                    }
                            });
                    }
            }

        function SS_InsertSlide(pos, type, ref, src, id, title)
            {
                if(this.Playing != true)
                    {
                        var html = '';

                        /* build html code */
                        html = html + '<li class="' + type + '"><a href="' + ref + '" id="' + id + '" title="' + title + '">';
                        if(type == 'image') html = html + '<img src="' + src + '" alt="' + title + '" />';
                        html = html + '</a></li>';

                        /* pre-insert checks */
                        if(pos == 0) pos = SHOUT_Slideshow_Top;
                        if(pos >= this.SlideCount) pos = SHOUT_Slideshow_Bottom;

                        /* insert */
                        switch(pos)
                            {
                                /* predefined positions */
                                case SHOUT_Slideshow_Top:
                                    {
                                        /* remove active field if not playing */
                                        $(this.ListControl + ' li:first').removeClass('active');

                                        /* add new control */
                                        $(this.ListControl + ':first').prepend(html);

                                        /* make active if not playing */
                                        if(this.Playing != true) $(this.ListControl + ' li:first').addClass('active');
                                    }
                                break;

                                case SHOUT_Slideshow_Bottom:
                                    {
                                        $(this.ListControl + ':last').append(html);
                                    }
                                break;

                                /* other position */
                                default:
                                    {
                                        var _this = this;

                                        $(this.ListControl + ' li').each(function(index)
                                            {
                                                if(index == pos)
                                                    {
                                                        $(html).insertBefore($(this));
                                                        return;
                                                    }
                                            });                                
                                    }
                                break;
                            }

                        /* rebuild slide data */
                        this.BuildSlideData();
                    }
            }

        function SS_InsertOverlay(pos, image, x, y)
            {
                if(this.Playing != true)
                    {
                        var _this = this;

                        /* pre-insert checks */
                        if(pos < 0) pos = 0;
                        if(pos >= this.SlideCount) pos = this.SlideCount;

                        /* locate slide */
                        $(this.ListControl + ' li').each(function(index)
                            {
                                if(index == pos)
                                    {
                                        /* insert image */
                                        $(this).append('<img class="overlay" src="' + image +  '" alt="Image Overlay" style="left: ' + x + 'px; top: ' + y + 'px;" />');

                                        return;
                                    }
                            });
                    }
            }

        function SS_StartTimer()
            {
                if(this.TimeOut != 0)
                    {
                        var _this = this;

                        /* restart if already started */
                        if(this.TimerObject != -1) this.StopTimer();

                        /* set timer */
                        this.TimerObject = setInterval( function()
                            {
                                _this.NextSlide(false);
                            }, this.TimeOut);
                    }
            }

        function SS_StopTimer()
            {
                if(this.TimeOut != 0)
                    {
                        /* clear and reset */
                        clearInterval(this.TimerObject);
                        this.TimerObject = -1;
                    }
            }

        function SS_StartVideo(vid)
            {
                var _this = this;

                /* get video identifier */
                if(typeof vid == 'number') vid = this.SlideField(vid, 'id');

                /* play video */
                $f(vid, { src: _this.FlowPlayerSWF, wmode: _this.FlowPlayerWMode },
                    {
                        /* commercial registration */
                        key: _this.FlowPlayerKey,
                        
                        /* setup */
                        canvas:     {
	                                    backgroundColor: '#161616',
	                                    backgroundGradient: 'none'
	                                },

                        plugins:    {
                                        controls: null,
		                                rtmp:
		                                    {
			                                    url: 'flowplayer.rtmp-3.2.3.swf',
			                                    netConnectionUrl: _this.FlowPlayerNCUrl
		                                    }
                                    },

                        play:       {
                                        opacity: 0.0
                                    },

                        logo:       {
                                        opacity: 0.0
                                    },

                        clip:       {
                                        provider: 'rtmp',
                                        autoPlay: true,
                                        autoBuffering: false,
                                        bufferLength: 3,
                                        fadeInSpeed: 2000,
                                        fadeOutSpeed: 2000
                                    },

                        /* events */
                        onLoad: function()
                            {
                                /* set audio level */
                                this.setVolume(_this.AudioLevel);
                            },

                        onMouseOver: function()
                            {
                                /* custom callback */
                                if(_this.CBVideoMouseOver != null) _this.CBVideoMouseOver();
                            },
                            
                        onMouseOut: function()
                            {
                                /* custom callback */
                                if(_this.CBVideoMouseOut != null) _this.CBVideoMouseOut();                            
                            },

                        onBufferFull: function()
                            {
                            },
                        
                        onStart: function()
                            {
                                /* custom callback */
                                if(_this.CBVideoStart != null && _this.DelayCallBacks != true) _this.CBVideoStart();
                            },
                            
                        onLastSecond: function()
                            {
                                /* custom callback */
                                if(_this.CBVideoEnd != null && _this.DelayCallBacks != true) _this.CBVideoEnd();
                                
                                /* show next slide and start timer */
                                _this.NextSlide(false, true);
                            }
                    });
            }

        function SS_PlayVideo(vid)
            {
                /* get video identifier */
                if(typeof vid == 'number') vid = this.SlideField(vid, 'id');
                $f(vid).play();                
            }

        function SS_StopVideo(vid)
            {
                /* get video identifier */
                if(typeof vid == 'number') vid = this.SlideField(vid, 'id');
                $f(vid).stop();
            }

        function SS_PauseVideo(vid)
            {
                if(typeof vid == 'undefined') vid = SHOUT_Slideshow_Current;

                if(this.SlideField(vid, 'type') == 'video')
                    {
                        var vid = this.SlideField(vid, 'id');
                        $f(vid).pause();
                    }
            }

        function SS_ResumeVideo()
            {
                if(this.SlideField(SHOUT_Slideshow_Current, 'type') == 'video')
                    {
                        var vid = this.SlideField(SHOUT_Slideshow_Current, 'id');
                        if($f(vid).isPaused()) $f(vid).resume();
                    }
            }
            
        function SS_ToggleVideoPlayback()
            {
                if(this.SlideField(SHOUT_Slideshow_Current, 'type') == 'video')
                    {
                        var vid = this.SlideField(SHOUT_Slideshow_Current, 'id');
                        
                        if($f(vid).isPaused())
                            {
                                $f(vid).resume();
                            }
                        else
                            {
                                $f(vid).pause();
                            }
                    }
            }

        function SS_MoveOffScreen(obj, index)
            {
                if(this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                    {
                        if((typeof index == 'undefined') || (index == null)) index = SHOUT_Slideshow_Current;

                        if((typeof obj == 'undefined') || (obj == null))
                            {
                                if(index < 0) index = this.SlideIndex(index);
                                obj = this.SlideData[index]['obj'];
                            }

                        /* hide */
                        obj.css('opacity', '0.0');
                        
                        if(this.OffScreenResize != false)
                            {
                                obj.css('width', this.OffScreenWidth + 'px');
                                obj.css('height', this.OffScreenHeight + 'px');
                            }

                        /* move */
                        var vindex = this.SlideData[index]['vindex'];
                        var y = (parseInt(obj.css('height')) * vindex) + (1 * vindex);
                        obj.css('left', this.MoveToX + 'px');
                        obj.css('top', (this.MoveToY + y) + 'px');
                    }
            }

        function SS_MoveOnScreen(obj, index)
            {
                if(this.VideoMode == SHOUT_Slideshow_Video_OffScreen)
                    {
                        if((typeof index == 'undefined') || (index == null)) index = SHOUT_Slideshow_Current;

                        if((typeof obj == 'undefined') || (obj == null))
                            {
                                if(index < 0) index = this.SlideIndex(index);
                                obj = this.SlideData[index]['obj'];
                            }

                        /* show and move */
                        if(this.OffScreenResize != false)
                            {
                                obj.css('width', this.SlideData[index]['width']);
                                obj.css('height', this.SlideData[index]['height']);
                            }

                        obj.css('opacity', '1.0');
                        obj.css('left', this.FrameOffsetX);
                        obj.css('top', this.FrameOffsetY);
                    }
            }

        function SS_SlideField(flag, field)
            {
                var slideref = -1;

                /* get reference */
                slideref = this.SlideIndex(flag);

                return this.SlideData[slideref][field];
            }

        function SS_SlideIndex(flag)
            {
                switch(flag)
                    {
                        case SHOUT_Slideshow_Next:
                            {
                                index = this.CurrentSlide + 1;
                                if(index == this.SlideCount) index = 0;
                            }
                        break;

                        case SHOUT_Slideshow_Previous:
                            {
                                index = this.CurrentSlide - 1;
                                if(index < 0) index = this.SlideCount - 1;
                            }
                        break;

                        default:
                        case SHOUT_Slideshow_Current:
                            {
                                index = this.CurrentSlide;
                            }
                        break;
                    }
                    
                return index;                
            }

        function SS_BuildSlideData()
            {
                var _this = this;

                if(this.Playing != true)
                    {
                        /* delete current array if it exists */
                        if(this.SlideData.length > 0)
                            {
                                delete(this.SlideData);

                                this.SlideData = new Array();
                                this.SlideCount = $(this.ListControl + ' li').size();
                                this.VideoCount = $(this.ListControl + ' li.video').size();
                            }

                        /* dimensions */
                        this.Width = $(this.ListControl).css('width');
                        this.Height = $(this.ListControl).css('height');

                        /* remove videos from ipad/ipod/iphone if requested */
                        if(this.DisableiDeviceVideos != false)
                            {
                                if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))|| (navigator.userAgent.match(/iPad/i)))
                                    {
                                        $(this.ListControl + ' li.video').each(function(index) { $(this).remove(); });
                                    }
                            }

                        /* build new array of slide information */
                        var vindex = 0;
                        var zindex = this.SlideCount;
                        $(this.ListControl + ' li').each(function(index)
                            {
                                /* new sub array */
                                _this.SlideData[index] = new Array();

                                /* slide identifier */
                                _this.SlideData[index]['obj'] = $(this);
                                _this.SlideData[index]['id'] = $(this).find('a').attr('id');

                                /* retrieve slide title */
                                if($(this).find('a').attr('title') != undefined)
                                    {
                                        _this.SlideData[index]['title'] = $(this).find('a').attr('title');
                                    }

                                /* determine slide types */
                                if($(this).hasClass('active'))
                                    {
                                        $(this).removeClass('active');
                                        _this.SlideData[index]['type'] = $(this).attr('class');
                                        $(this).addClass('active');
                                    }
                                else
                                    {
                                        _this.SlideData[index]['type'] = $(this).attr('class');
                                    }
                                
                                /* store video dimensions */
                                if((_this.SlideData[index]['type'] == 'video'))
                                    {
                                        _this.SlideData[index]['vindex'] = vindex++;
                                        _this.SlideData[index]['width'] = $(this).css('width');
                                        _this.SlideData[index]['height'] = $(this).css('height');
                                    }

                                /* retrieve positioned slide offset (use first image as it won't move) */
                                if((_this.SlideData[index]['type'] == 'image') && (_this.FrameOffsetX == -1))
                                    {
                                        _this.FrameOffsetX = $(this).css('left');
                                        _this.FrameOffsetY = $(this).css('top');
                                    }
                            });
                    }
            }

        function SS_DebugInfo()
            {
                if(this.DebugMode != false)
                    {
                        if($('body').find('div#shoutslideshow-debug') != true)
                            {
                                var style = 'position: absolute; z-index: 99999; top: 0px; left: 0px; font-size: 8pt; margin: 15px 0px 0px 15px; padding: 20px; border: 1px dotted #ff0000; background-color: #fcdfdf;';
                                $('body').append('<div id="shoutslideshow-debug" style="' + style + '"></debug>');
                            }
                            
                        var debug = '';

                        debug = debug + '<strong>Current Slide</strong><br />';
                        debug = debug + 'Index: ' + this.CurrentSlide + ' (' + (this.CurrentSlide + 1) + ' of ' + this.SlideCount + ')<br />';
                        debug = debug + 'Unique ID: ' + this.SlideField(SHOUT_Slideshow_Current, 'id') + '<br />';
                        debug = debug + 'Title: ' + this.SlideField(SHOUT_Slideshow_Current, 'title') + '<br />';
                        debug = debug + 'Type: ' + this.SlideField(SHOUT_Slideshow_Current, 'type') + '<br />';
                        debug = debug + '<br />';

                        debug = debug + '<strong>Next Slide</strong><br />';
                        debug = debug + 'Unique ID: ' + this.SlideField(SHOUT_Slideshow_Next, 'id') + '<br />';
                        debug = debug + 'Title: ' + this.SlideField(SHOUT_Slideshow_Next, 'title') + '<br />';
                        debug = debug + 'Type: ' + this.SlideField(SHOUT_Slideshow_Next, 'type') + '<br />';
                        debug = debug + '<br />';

                        debug = debug + '<strong>Previous Slide</strong><br />';
                        debug = debug + 'Unique ID: ' + this.SlideField(SHOUT_Slideshow_Previous, 'id') + '<br />';
                        debug = debug + 'Title: ' + this.SlideField(SHOUT_Slideshow_Previous, 'title') + '<br />';
                        debug = debug + 'Type: ' + this.SlideField(SHOUT_Slideshow_Previous, 'type') + '<br />';
                        debug = debug + '<br />';

                        debug = debug + '<strong>Other Information</strong><br />';
                        debug = debug + 'Dimensions: ' + this.Width + ' by ' + this.Height + '<br />';
                        debug = debug + 'Status: ' + (this.Playing?'Playing':'Stopped') + '<br />';
                        debug = debug + 'Slide TimeOut: ' + (this.TimeOut == 0?'Manual':(this.TimeOut/1000) + ' seconds') + '<br />';
                        debug = debug + 'Transition Type: ' + (this.Transition == SHOUT_Slideshow_Transition_Fade?'Fade':'Slide') + '<br />';
                        debug = debug + 'Transition Time: ' + (this.TransitionTime/1000) + ' seconds<br />';
                        debug = debug + 'Timer Status: ' + (this.TimerObject == -1?'Not Set':'Set') + '<br />';
                        debug = debug + 'Frame Offset X (left): ' + this.FrameOffsetX + '<br />';
                        debug = debug + 'Frame Offset Y (top): ' + this.FrameOffsetY + '<br />';
                        debug = debug + 'Audio Level: ' + this.AudioLevel + '%<br />';
                        debug = debug + 'Video Mode: ' + (this.VideoMode == SHOUT_Slideshow_Video_ZIndex?'Z-Index':'Off Screen') + '<br />';
                        debug = debug + 'Disable iDevice Videos: ' + (this.DisableiDeviceVideos?'Yes':'No') + '<br />';
                        debug = debug + '<br />';
                        
                        debug = debug + '<strong>Custom Callback Functions</strong><br />';
                        debug = debug + 'Video Start: ' + (this.CBVideoStart == null?'Not Set':'Set') + '<br />';
                        debug = debug + 'Video End: ' + (this.CBVideoEnd == null?'Not Set':'Set') + '<br />';                        
                        debug = debug + 'Video Mouse Over: ' + (this.CBVideoMouseOver == null?'Not Set':'Set') + '<br />';
                        debug = debug + 'Video Mouse Out: ' + (this.CBVideoMouseOut == null?'Not Set':'Set');

                        $('div#shoutslideshow-debug').html(debug);
                    }
            }
    }
