function FullScreenBar(mplayer)
{
    
    
    mplayer.eventList.addListener(MediasitePlayer.Events.FullScreen,Event.createDelegate(this,this.handleFullScreenChange));
    
    var controlPanel = mss.FindName(FullScreenBar.Names.Main);
    
    if (null!=controlPanel)
    {
        controlPanel.addEventListener("MouseEnter", Event.createDelegate(this, this.handleFullScreenPanelMouseEnter));
	    controlPanel.addEventListener("MouseLeave", Event.createDelegate(this, this.handleFullScreenPanelMouseLeave));
    }

	mss.AddAnimationMouseEventListeners("FullScreen_PlayButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handlePlayMouseUp));
	mss.AddAnimationMouseEventListeners("FullScreen_SkipBackButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handleSkipBackMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_StopButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handleStopMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_PreviousSlideButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handlePreviousSlideMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_NextSlideButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handleNextSlideMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_MuteButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handleMuteMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_CaptionButton",Event.createDelegate(window.mplayer.playBar, window.mplayer.playBar.handleCaptionMouseUp));

    mss.AddAnimationMouseEventListeners("FullScreen_FullScreenButton",Event.createDelegate(this, this.handleFullScreenMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_PipButton",Event.createDelegate(this, this.handlePipMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_SideBySideButton", Event.createDelegate(this, this.handleSideBySideMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_SoloButton", Event.createDelegate(this, this.handleSoloMouseUp));
    mss.AddAnimationMouseEventListeners("FullScreen_SwapButton", Event.createDelegate(this, this.handleSwapMouseUp));
    
	if (mss.FindName(FullScreenBar.Names.TimeGuide))
	{
		this.positionSlider = new SfSlider("FullScreen_Time",SfSliderOrientation.Horizontal);
	    this.positionSlider.OnLoad();
	    this.positionSlider.eventList.addListener(SfSlider.Events.Click,Event.createDelegate(this, this.handleTimeSliderGuideClick));
	    this.positionSlider.eventList.addListener(SfSlider.Events.Drag,Event.createDelegate(this, this.handleTimeSliderThumbDrag));
	}

   
}

FullScreenBar.Names={};
FullScreenBar.Names.Main = "FullScreen";
FullScreenBar.Names.Top = "FullScreen_Top";
FullScreenBar.Names.Bottom="FullScreen_Bottom";
FullScreenBar.Names.BottomBackground="FullScreen_BottomBackground";
FullScreenBar.Names.Tray = "FullScreen_Tray";
FullScreenBar.Names.TrayLeft = "FullScreen_Tray_Left";
FullScreenBar.Names.TrayCenter = "FullScreen_Tray_Center";
FullScreenBar.Names.TrayRight="FullScreen_Tray_Right";
FullScreenBar.Names.TrayBackground="FullScreen_Tray_Background"
FullScreenBar.Names.Show="FullScreen_Show";
FullScreenBar.Names.Hide="FullScreen_Hide";
FullScreenBar.Names.Enter="FullScreen_Enter";
FullScreenBar.Names.Leave="FullScreen_Leave";
FullScreenBar.Names.PositionText="FullScreen_PositionText";
FullScreenBar.Names.DurationText="FullScreen_DurationText";
FullScreenBar.Names.CurrentSlideText="FullScreen_CurrentSlideText";
FullScreenBar.Names.TotalSlidesText="FullScreen_TotalSlidesText";
FullScreenBar.Names.TimeGuide = "FullScreen_Time_Guide";
FullScreenBar.Names.TimeGuideOverlay = "FullScreen_Time_Guide_Overlay";
FullScreenBar.Names.TimeGuideBackground="FullScreen_Time_Guide_Background";
FullScreenBar.SecondaryRectOffset = new Rectangle(340, 340, 320, 240);

FullScreenBar.prototype =
{


    handleFullScreenPanelMouseEnter: function(sender, eventArgs)
    {
        mss.Animate(FullScreenBar.Names.Show);
        mss.Animate(MediasitePlayer.AnimationEvent.FullScreenUserModeEnter);
    },

    handleFullScreenPanelMouseLeave: function(sender, eventArgs)
    {
        mss.Animate(FullScreenBar.Names.Hide);
        mss.Animate(MediasitePlayer.AnimationEvent.FullScreenUserModeLeave);
    },

    handleFullScreenMouseUp: function(sender, eventArgs)
    {
        mss.content.fullScreen = !mss.content.fullScreen;
    },

    handlePipMouseUp: function(sender, eventArgs)
    {
        var pipManager = window.mplayer.pipManager;
        pipManager.CurrentDisplayType = DisplayType.Pip;
        pipManager.Update();
    },

    handleSideBySideMouseUp: function(sender, eventArgs)
    {
        var pipManager = window.mplayer.pipManager;
        pipManager.CurrentDisplayType = DisplayType.SideBySide;
        pipManager.Update();
    },

    handleSoloMouseUp: function(sender, eventArgs)
    {
        var pipManager = window.mplayer.pipManager;
        pipManager.CurrentDisplayType = DisplayType.Solo;
        pipManager.Update();
    },

    handleSwapMouseUp: function(sender, eventArgs)
    {
        var pipManager = window.mplayer.pipManager;
        if (pipManager.CurrentPrimaryDisplay == PrimaryDisplay.Slide)
        {
            pipManager.CurrentPrimaryDisplay = PrimaryDisplay.Video;
        }
        else
        {
            pipManager.CurrentPrimaryDisplay = PrimaryDisplay.Slide;
        }
        pipManager.Update();
    },

    handleTimeSliderGuideClick: function(position)
    {
        window.mplayer.SeekTime(position);
    },

    handleTimeSliderThumbDrag: function(eventArgs)
    {
        if (eventArgs.DragType == SfSliderDragEventType.DragBegin)
        {
            draggingPosition = true;
        }
        if (eventArgs.DragType == SfSliderDragEventType.DragMove)
        {
            window.mplayer.UpdatePositionStatus(eventArgs.Position);
            this.positionSlider.SetPosition(eventArgs.Position);

            var positionText = mss.FindName(FullScreenBar.Names.PositionText);
            if (positionText != null)
            {
                positionText.Text = mss.FormatTimeMMSS(eventArgs.Position);
            }
        }
        if (eventArgs.DragType == SfSliderDragEventType.DragEnd)
        {
            window.mplayer.SeekTime(eventArgs.Position);
        }
    },

    handleTimer: function(currentPosition)
    {
        if (this.positionSlider != null)
        {
            if (this.positionSlider.Dragging)
            {
                return;
            }
            this.positionSlider.SetPosition(currentPosition);
        }

        var positionText = mss.FindName(FullScreenBar.Names.PositionText);
        if (positionText != null)
        {
            positionText.Text = mss.FormatTimeMMSS(currentPosition);
        }
    },

    handleSlideChanged: function(slideNumber)
    {
        var panel = mss.FindName(FullScreenBar.Names.CurrentSlideText);

        if (panel != null)
        {
            panel.Text = "" + slideNumber;
        }
    },

    SaveRects: function()
    {
        var panel = mss.FindName(Media.Names.Main);

        if (panel)
        {
            this.savedMediaRect = new Rectangle();
            this.savedMediaRect.GetCanvasRect(panel);

            this.savedMediaClipRect = this.savedMediaRect.Clone();
            this.savedMediaClipRect.Left = 0;
            this.savedMediaClipRect.Top = 0;

        }

        panel = mss.FindName(Media.Names.SlideWindow);

        if (panel)
        {
            this.savedSlideWindowClipRect = new Rectangle();
            this.savedSlideWindowClipRect.GetCanvasRect(panel);
            this.savedSlideWindowClipRect.Left = 0;
            this.savedSlideWindowClipRect.Top = 0;
        }

    },

    RestoreRects: function()
    {
        var panel = mss.FindName(Media.Names.Main);

        if (panel)
        {
            this.savedMediaRect.SetCanvasRect(panel);
        }

        panel = mss.FindName(Media.Names.MainClip);
        if (panel)
        {
            this.savedMediaClipRect.SetClipRect(panel);
        }


        panel = mss.FindName(Media.Names.SlideWindowClip);
        if (panel)
        {
            this.savedSlideWindowClipRect.SetClipRect(panel);
        }

    },

    CreateAnimation: function()
    {
        var fullScreenRect = new Rectangle(0, 0, this.actualWidth, this.actualHeight);

        var shrinkRect = new Rectangle(40, 90, (this.actualWidth * 3) / 4, (this.actualHeight * 3) / 4);
        var w = 320;
        var h = 240;

        var shrinkRectSmall = new Rectangle(this.actualWidth - w - 20, this.actualHeight - h - 20, w, h);
        var animateDuration = "0:0:0.5";
        var wrapper = "VideoWindow";
        var element = "VideoElement";


        var pipMode = window.mplayer.pipManager.GetCurrentMode();

        if (pipMode == PipMode.SlideFullScreen || pipMode == PipMode.VideoInSlide)
        {
            wrapper = "SlideWindow";
            element = "SlideImage";
        }

        var shrinkString = dani.OpenAnimation("FullScreenShrinkVideo");
        shrinkString = dani.MoveCanvas(shrinkString, wrapper, shrinkRect.Left, shrinkRect.Top, animateDuration);
        shrinkString = dani.SizeCanvas(shrinkString, wrapper, shrinkRect.Width, shrinkRect.Height, animateDuration);
        shrinkString = dani.SizeCanvas(shrinkString, element, shrinkRect.Width, shrinkRect.Height, animateDuration);

        //        shrinkString = dani.MoveCanvas(shrinkString, "SlideWindow", shrinkRectSmall.Left, shrinkRectSmall.Top, animateDuration);
        //        shrinkString = dani.SizeCanvas(shrinkString, "SlideWindow", shrinkRectSmall.Width, shrinkRectSmall.Height, animateDuration);
        //        shrinkString = dani.SizeCanvas(shrinkString, "SlideImage", shrinkRectSmall.Width, shrinkRectSmall.Height, animateDuration);

        shrinkString = dani.CloseAnimation(shrinkString);

        this.animationShrinkVideo = mss.AddStoryBoard(shrinkString);

        shrinkString = dani.OpenAnimation("FullScreenUnshrinkVideo");
        shrinkString = dani.MoveCanvas(shrinkString, wrapper, 0, 0, animateDuration);
        shrinkString = dani.SizeCanvas(shrinkString, wrapper, fullScreenRect.Width, fullScreenRect.Height, animateDuration);
        shrinkString = dani.SizeCanvas(shrinkString, element, fullScreenRect.Width, fullScreenRect.Height, animateDuration);
        shrinkString = dani.CloseAnimation(shrinkString);

        this.animationUnshrinkVideo = mss.AddStoryBoard(shrinkString);
    },

    DestroyAnimation: function()
    {
        if (this.animationShrinkVideo)
        {
            mss.RemoveResource(this.animationShrinkVideo);
            this.animationShrinkVideo = null;
        }
        if (this.animationUnshrinkVideo)
        {
            mss.RemoveResource(this.animationUnshrinkVideo);
            this.animationUnshrinkVideo = null;
        }
    },

    EnterFullScreenMode: function()
    {
        mss.SetVisible("Frame", false);
        mss.SetVisible("Background", false);
        mss.SetVisible("Foreground", false);

        this.SaveRects();

        this.CreateAnimation();

        pl = mss.FindName("Player");
        if (pl)
        {
            this.saveClipPathGeometry = pl.Clip;

            var clippingGeometry = mss.CreateClipRect(0, 0, this.actualWidth, this.actualHeight);
            pl.Clip = clippingGeometry;
        }

        var fullScreenRect = new Rectangle(0, 0, this.actualWidth, this.actualHeight);

        var panel = mss.FindName(Media.Names.Main);

        if (panel)
        {
            fullScreenRect.SetCanvasRect(panel);
        }

        var clipRect = mss.FindName(Media.Names.MainClip);

        if (clipRect)
        {
            fullScreenRect.SetClipRect(clipRect);
        }


        clipRect = mss.FindName(Media.Names.SlideWindowClip);
        if (clipRect)
        {
            fullScreenRect.SetClipRect(clipRect);
        }

        mss.Animate(FullScreenBar.Names.Enter);

        mplayer.pipManager.eventList.addListener(PipManager.Events.Changed, Event.createDelegate(this, this.handlePipModeChange));
    },

    handlePipModeChange: function(mode)
    {
        this.DestroyAnimation();
        this.CreateAnimation();
    },

    LeaveFullScreenMode: function()
    {
        mss.StopAnimate("FullScreenShrinkVideo");
        mss.StopAnimate("FullScreenUnshrinkVideo");
        mss.SetVisible("Frame", true);
        mss.SetVisible("Background", true);
        mss.SetVisible("Foreground", true);
        mss.Animate(FullScreenBar.Names.Leave);
        this.RestoreRects();

        pl = mss.FindName("Player");
        if (pl && this.saveClipPathGeometry)
        {
            pl.Clip = this.saveClipPathGeometry;
        }


        this.DestroyAnimation();
    },


    handleFullScreenChange: function(fullScreen)
    {
        if (fullScreen)
        {
            this.actualWidth = mss.content.actualWidth;
            this.actualHeight = mss.content.actualHeight;

            this.EnterFullScreenMode();

            var fullScreenHeight = mss.content.actualHeight;
            var fullScreenWidth = mss.content.actualWidth;

            var fsPanel = mss.FindName(FullScreenBar.Names.Main);
            fsPanel.SetValue("Canvas.Left", 0);
            fsPanel.SetValue("Canvas.Top", 0);
            fsPanel.height = fullScreenHeight;
            fsPanel.width = fullScreenWidth;

            var screenBackground = mss.FindName("Screen_Background");

            if (screenBackground)
            {
                screenBackground.height = fullScreenHeight;
                screenBackground.width = fullScreenWidth;
            }

            var fsTop = mss.FindName(FullScreenBar.Names.Top);

            if (fsTop)
            {
                fsTop.SetValue("Canvas.Left", (fullScreenWidth - fsTop.width) / 2);
            }

            var fsBottom = mss.FindName(FullScreenBar.Names.Bottom);
            if (fsBottom)
            {
                fsBottom.SetValue("Canvas.Left", 0);
                fsBottom.SetValue("Canvas.Top", fullScreenHeight - fsBottom.height);
                fsBottom.width = fullScreenWidth;
            }

            var fsBottomBackground = mss.FindName(FullScreenBar.Names.BottomBackground);
            if (fsBottomBackground)
            {
                fsBottomBackground.width = fullScreenWidth;
            }

            fullScreenWidth -= 100;

            var fsTray = mss.FindName(FullScreenBar.Names.Tray);
            if (fsTray)
            {
                fsTray.width = fullScreenWidth;
            }

            var fsTrayBackground = mss.FindName(FullScreenBar.Names.TrayBackground);
            if (fsTrayBackground)
            {
                fsTrayBackground.width = fullScreenWidth;
            }




            var leftTrayWidth = 0;
            var centerTrayLeft = 0;
            var centerTrayWidth = 0;
            var rightTrayWidth = 0;
            var newCenterTrayWidth = 0;
            var centerTrayWidthDelta = 0;

            var trayLeft = mss.FindName(FullScreenBar.Names.TrayLeft);
            if (trayLeft)
            {
                leftTrayWidth = trayLeft.width;
                centerTrayLeft = trayLeft.GetValue("Canvas.Left") + leftTrayWidth;
            }

            var trayRight = mss.FindName(FullScreenBar.Names.TrayRight);
            if (trayRight)
            {
                rightTrayWidth = trayRight.width;
                trayRight.SetValue("Canvas.Left", fullScreenWidth - rightTrayWidth);
            }

            trayCenter = mss.FindName(FullScreenBar.Names.TrayCenter);
            if (trayCenter)
            {
                centerTrayWidth = trayCenter.width;
                trayCenter.SetValue("Canvas.Left", centerTrayLeft);
                newCenterTrayWidth = (fullScreenWidth - rightTrayWidth) - leftTrayWidth;
                trayCenter.width = newCenterTrayWidth;
                centerTrayWidthDelta = newCenterTrayWidth - centerTrayWidth;
            }

            var timeSliderWidth = fullScreenWidth;

            var timeGuide = mss.FindName(FullScreenBar.Names.TimeGuide);
            if (timeGuide)
            {
                timeSliderWidth = timeGuide.width + centerTrayWidthDelta;
                timeGuide.width = timeSliderWidth;
                var clippingGeometry = mss.CreateClipRect(0, 0, timeSliderWidth, timeGuide.height);
                timeGuide.Clip = clippingGeometry;
            }
            var timeGuideOverlay = mss.FindName(FullScreenBar.Names.TimeGuideOverlay);
            if (timeGuideOverlay)
            {
                timeGuideOverlay.width = timeSliderWidth;
            }

            timeGuideBackground = mss.FindName(FullScreenBar.Names.TimeGuideBackground);
            if (timeGuideBackground)
            {
                timeGuideBackground.width = timeSliderWidth;
            }

            var duration = mplayer.mediaplayer.GetDuration();
            var text = mss.FormatTimeMMSS(duration);

            var panel = mss.FindName(FullScreenBar.Names.DurationText);

            if (panel)
            {
                panel.SetValue("Canvas.Left", panel.GetValue("Canvas.Left") + centerTrayWidthDelta);
                panel.Text = text;
            }

            panel = mss.FindName(FullScreenBar.Names.TotalSlidesText);

            if (panel)
            {
                panel.Text = "" + Manifest.Slides.length;
            }

            panel = mss.FindName(FullScreenBar.Names.CurrentSlideText);

            if (panel)
            {
                panel.Text = "" + mplayer.CurrentSlide;
            }

            if (this.positionSlider != null)
            {
                this.positionSlider.SetRange(0, duration);
                this.positionSlider.Resize();
            }

            this.timerToken = mplayer.eventList.addListener(MediasitePlayer.Events.Timer, Event.createDelegate(this, this.handleTimer));
            this.slideChangedToken = mplayer.eventList.addListener(MediasitePlayer.Events.SlideChanged, Event.createDelegate(this, this.handleSlideChanged));

            mss.Animate(FullScreenBar.Names.Hide);
        }
        else
        {
            this.LeaveFullScreenMode();
            mplayer.eventList.removeListener(MediasitePlayer.Events.Timer, this.timerToken);
            mplayer.eventList.removeListener(MediasitePlayer.Events.SlideChanged, this.slideChangedToken);
        }
        mss.SetVisible(FullScreenBar.Names.Main, fullScreen);
    }

}


function dani() { }

dani.OpenAnimation = function(name)
{
    var ani = '<Storyboard x:Name="{0}" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">';
    return ani.replace("{0}", name);
}

dani.CloseAnimation = function(ani)
{
    ani += '</Storyboard>';
    return ani;
}

dani.MoveCanvas = function(ani, targetName, left, top, duration)
{
    ani += '<DoubleAnimation Storyboard.TargetName="{0}" Storyboard.TargetProperty="(Canvas.Left)" To="{1}" Duration="{2}" />';
    ani = ani.replace("{0}", targetName);
    ani = ani.replace("{1}", left);
    ani = ani.replace("{2}", duration);
    ani += '<DoubleAnimation Storyboard.TargetName="{0}" Storyboard.TargetProperty="(Canvas.Top)"  To="{1}" Duration="{2}" />';
    ani = ani.replace("{0}", targetName);
    ani = ani.replace("{1}", top);
    ani = ani.replace("{2}", duration);
    return ani;
}

dani.SizeCanvas = function(ani, targetName, width, height, duration)
{
    ani += '<DoubleAnimation Storyboard.TargetName="{0}" Storyboard.TargetProperty="(Height)" To="{1}" Duration="{2}" />';
    ani = ani.replace("{0}", targetName);
    ani = ani.replace("{1}", height);
    ani = ani.replace("{2}", duration);
    ani += '<DoubleAnimation Storyboard.TargetName="{0}" Storyboard.TargetProperty="(Width)"  To="{1}" Duration="{2}" />';
    ani = ani.replace("{0}", targetName);
    ani = ani.replace("{1}", width);
    ani = ani.replace("{2}", duration);
    return ani;
}

