
CurrentSlidePanel = function(container, containingWindow, id) {
    this.ID = id;
    this._imageCache$1 = new SfImage.ImageCache(container + '._imageCache$1');
}
CurrentSlidePanel.prototype = {
    _slideImageDiv$1: null,
    _slideImageLinkDiv$1: null,
    
    get_slideImageDiv: function CurrentSlidePanel$get_slideImageDiv() {
        return this._slideImageDiv$1;
    },
    set_slideImageDiv: function CurrentSlidePanel$set_slideImageDiv(value) {
        this._slideImageDiv$1 = value;
        return value;
    },
    
    _slideDescriptionDiv$1: null,
    _showNoImage$1: false,
    _imageCache$1: null,
    _toolbuttonController$1: null,
    _viewportManager$1: null,
    
    OnLoad: function CurrentSlidePanel$OnLoad() {
        this._slideImageDiv$1 = $(this.ID + 'SlideImage');
        this._slideDescriptionDiv$1 = $(this.ID + 'SlideDescription');      
        this._slideImageLinkDiv$1 = $(this.ID + 'ImageLink');
        
        if(LayoutOptions.Images['SlideDefault'])
        {
            this._setSlideImage$1(LayoutOptions.Images['SlideDefault'].ImageFilename);
            this._setSlideLink$1(LayoutOptions.Images['SlideDefault'].ImageUrl);
            this._setSlideDescription$1(Localization.CurrentSlideResource.SlideImage);          
        }
    },
    
    OnDataLoad: function()
    {
        this._registerEvents$1();
        this._toolbuttonController$1 = new CurrentSlide.CurrentSlideToolbuttonController(this);
        this._viewportManager$1 = new CurrentSlide.ViewportManager(this);    
        this._loadDefaultImage$1();  
    },
    
    GetDiv : function()
	{
		if (this._div == null)
		{
			this._div = $(this.ID);
		}
		return this._div;
	},
    
    turnOnSlideDescription: function CurrentSlidePanel$turnOnSlideDescription() {
        this._slideImageDiv$1.style.visibility = 'hidden';
        this._slideDescriptionDiv$1.style.visibility = 'visible';
    },
    
    turnOffSlideDescription: function CurrentSlidePanel$turnOffSlideDescription() {
        this._slideImageDiv$1.style.visibility = 'visible';
        this._slideDescriptionDiv$1.style.visibility = 'hidden';
    },
    
    showMagnifier: function CurrentSlidePanel$showMagnifier() {
        this._viewportManager$1.set_isShowing(true);
    },
    
    hideMagnifier: function CurrentSlidePanel$hideMagnifier() {
        this._viewportManager$1.set_isShowing(false);
    },
    
    _loadDefaultImage$1: function CurrentSlidePanel$_loadDefaultImage$1() {
        var status = Manifest.PlayStatus;
        switch (status) {
            case SfKernel.PresentationPlayStatus.Live:
            case SfKernel.PresentationPlayStatus.LivePaused:
                this._setCurrentCaptureImage$1();
                break;
            case SfKernel.PresentationPlayStatus.OnDemand:
                if(LayoutOptions.Images['SlideDefault'])
                {
                    this._setSlideImage$1(LayoutOptions.Images['SlideDefault'].ImageFilename);
                    this._setSlideLink$1(LayoutOptions.Images['SlideDefault'].ImageUrl);
                    this._setSlideDescription$1(Localization.CurrentSlideResource.SlideImage);
                }
                break;
            case SfKernel.PresentationPlayStatus.LiveEnded:
                if(!LayoutOptions.DoNotShowEndSlide && LayoutOptions.Images['SlideEnded'])
                {
                    this._setSlideImage$1(LayoutOptions.Images['SlideEnded'].ImageFilename);
                    this._setSlideLink$1(LayoutOptions.Images['SlideEnded'].ImageUrl);
                }
                break;
            case SfKernel.PresentationPlayStatus.ScheduledForLive:
            case SfKernel.PresentationPlayStatus.OpenForLive:
                if(LayoutOptions.Images['SlideNotStarted'])
                {
                    this._setSlideImage$1(LayoutOptions.Images['SlideNotStarted'].ImageFilename);
                    this._setSlideLink$1(LayoutOptions.Images['SlideNotStarted'].ImageUrl);
                }
                break;
            default:
                throw Error.invalidOperation('Unknown presentation status');
        }
    },
    
    _registerEvents$1: function CurrentSlidePanel$_registerEvents$1() {
        mPlayer.EventManager.Events.addHandler(SfKernel.EventType.Script, Function.createDelegate(this, this._onScriptEvent$1));
        mPlayer.EventManager.CommandEvents.addHandler(SfKernel.CommandEventId.Play, Function.createDelegate(this, this._onPlay$1));
        mPlayer.EventManager.Events.addHandler(SfKernel.EventType.LivePlaybackStarted, Function.createDelegate(this, this._onDataAvailable$1));
    },
    
    _setCurrentCaptureImage$1: function CurrentSlidePanel$_setCurrentCaptureImage$1() {
        var max = Manifest.Slides.length;
        if (max < 1) {
            if(LayoutOptions.Images['SlideDefault'])
            {
                this._setSlideImage$1(LayoutOptions.Images['SlideDefault'].ImageFilename);
                this._setSlideLink$1(LayoutOptions.Images['SlideDefault'].ImageUrl);
            }
            return;
        }
        mPlayer.CurrentFullSizeImage = mPlayer.GetImageLocation(max, SfKernel.SlideType.FullSize);
        mPlayer.CurrentSlideNumber = max;
        this._setSlideImage$1(mPlayer.GetImageLocation(max, SfKernel.SlideType.Normal));       
        this._setSlideLink$1(null);
        this._toolbuttonController$1.ensureClickIsInitialized();
    },
    
    _setSlideImage$1: function CurrentSlidePanel$_setSlideImage$1(src) {
        this._slideImageDiv$1.setAttribute('src', src);
        this._slideImageDiv$1.show();
    },
    
   _setSlideLink$1: function CurrentSlidePanel$_setSlideLink$1(href) {
   
        if(!href || href.length < 1)
        {
            this._slideImageLinkDiv$1.removeAttribute('href');           
        }
        else
        {
            this._slideImageLinkDiv$1.setAttribute('href', href);    
        }    
    },

    _onScriptEvent$1: function CurrentSlidePanel$_onScriptEvent$1(sender, args) {
        var commandType = args['Command'];
        switch (commandType) {
            case SfKernel.ScriptCmdType.ShowSlide:
                this._showSlide$1(args);
                break;
            case SfKernel.ScriptCmdType.EndPresentation:
                this._doEndPresentation$1();
                break;
        }
    },
    
    _onPlay$1: function CurrentSlidePanel$_onPlay$1(sender, args) {
        if (mPlayer.PresentationEnded) {
            this._doEndPresentation$1();
        }
    },
    
    _onDataAvailable$1: function CurrentSlidePanel$_onDataAvailable$1(sender, args) {
        this._setCurrentCaptureImage$1();
    },
            
    _showSlide$1: function CurrentSlidePanel$_showSlide$1(args) {
        var slideNumber = args['Index'];
        var currentImage = args['Image'];
        mPlayer.CurrentFullSizeImage = args['FullSizeImage'];
        if (this._showNoImage$1) {
            this._setSlideImage$1('');
            this._setSlideLink$1(null);
        }
        else {
            this._setSlideImage$1(currentImage);
            this._setSlideLink$1(null);
        }
        this._doSlideDescriptionStuff$1(slideNumber);
        if ((Manifest.PlayStatus == SfKernel.PresentationPlayStatus.OnDemand) && (slideNumber < Manifest.Slides.length)) {
            this._imageCache$1.AddImage(mPlayer.GetImageLocation(mPlayer.CurrentSlideNumber + 1, SfKernel.SlideType.Normal), true);
        }
        this._updateFullSizeWindow$1(currentImage);
        this._toolbuttonController$1.ensureClickIsInitialized();
    },
    
    _updateFullSizeWindow$1: function CurrentSlidePanel$_updateFullSizeWindow$1(currentImage) {
        if (!WindowHelper.IsOpen(mPlayer.PopupWindows.FullSize)) {
            return;
        }
        var fullSize = mPlayer.PopupWindows.FullSize.SlidePlayer;
        if (SfKernel.Util.IsNullOrUndefined(fullSize)) {
            return;
        }
        fullSize.UpdateIfNeeded(mPlayer.CurrentFullSizeImage, mPlayer.CurrentSlideNumber);
    },
    
    _doSlideDescriptionStuff$1: function CurrentSlidePanel$_doSlideDescriptionStuff$1(slideNumber) {
        if (Manifest.PlayStatus != SfKernel.PresentationPlayStatus.OnDemand) {
            this._setDefaultAltText$1(slideNumber);
            this._setDefaultSlideDescription$1(slideNumber);
        }
        else
        {            
            var slideTitle = Manifest.GetSlideTitle(slideNumber);
     
            if(slideTitle != null && slideTitle.length > 0)            
            {
                this._setAltText$1(slideTitle);
            }                          
            else
            {
                this._setDefaultAltText$1(slideNumber);
            }
            
            var slideDescription = Manifest.GetSlideDescription(slideNumber);
            
     
            if((slideDescription != null && slideDescription.length > 0) || (slideTitle != null && slideTitle.length > 0))
            {
                var slideDescriptionContent;
                if(slideTitle != null && slideTitle.length > 0)
                {
                    slideDescriptionContent = "<b>" + slideTitle + "</b><br/>";
                }
                if(slideDescription != null && slideDescription.length > 0)
                {
                    slideDescriptionContent += slideDescription;
                }
                this._setSlideDescription$1(slideDescriptionContent);
            }
            else
            {         
                this._setDefaultSlideDescription$1(slideNumber);
            }
      }
    },
    
    _doEndPresentation$1: function CurrentSlidePanel$_doEndPresentation$1() {
    if (!LayoutOptions.DoNotShowEndSlide && LayoutOptions.Images['SlideEnded'])
        {
            this._setSlideImage$1(LayoutOptions.Images['SlideEnded'].ImageFilename);
            this._setSlideLink$1(LayoutOptions.Images['SlideEnded'].ImageUrl);
            this._setAltText$1(Localization.CurrentSlideResource.PresentationHasEnded);
            this._setSlideDescription$1(Localization.CurrentSlideResource.PresentationHasEnded);
            this._toolbuttonController$1.resetClick();
        }
    },
    
    _setDefaultSlideDescription$1: function CurrentSlidePanel$_setDefaultSlideDescription$1(slideNumber) {
        this._setSlideDescription$1(String.format('Slide {0}', slideNumber));
    },
    
    _setSlideDescription$1: function CurrentSlidePanel$_setSlideDescription$1(text) {
        $(this._slideDescriptionDiv$1).innerHTML = SfKernel.EncodeHTML(text);
    },
    
    _setDefaultAltText$1: function CurrentSlidePanel$_setDefaultAltText$1(slideNumber) {
        this._setAltText$1(String.format('Slide {0}', slideNumber));
    },
    
    _setAltText$1: function CurrentSlidePanel$_setAltText$1(text) {
        this._slideImageDiv$1.setAttribute('alt', text);
        this._slideImageDiv$1.setAttribute('title', text);
        this._slideDescriptionDiv$1.setAttribute('title', text);
    }
   
}


Type.registerNamespace('CurrentSlide');

CurrentSlide.IToolbuttonController = function() { };
CurrentSlide.IToolbuttonController.prototype = {
    selectButton : null
}
CurrentSlide.IToolbuttonController.registerInterface('CurrentSlide.IToolbuttonController');


CurrentSlide.$create_ToolbuttonClassInfo = function CurrentSlide_ToolbuttonClassInfo(normal, over, disabled, checkedClass) {
    var $o = { };
    $o.normal = normal;
    $o.over = over;
    $o.disabled = disabled;
    $o.checked = checkedClass;
    return $o;
}

CurrentSlide.CurrentSlideToolbuttonController = function CurrentSlide_CurrentSlideToolbuttonController(parentArea) {
    this._parentArea = parentArea;
    this._viewportToolbutton = new CurrentSlide.Toolbutton(this, $(this._parentArea.ID + 'ViewportToolbutton'), CurrentSlide.$create_ToolbuttonClassInfo('CurrentSlideAreaViewportToolbuttonNormal', 'CurrentSlideAreaViewportToolbuttonOver', 'CurrentSlideAreaViewportToolbuttonDisabled', 'CurrentSlideAreaViewportToolbuttonChecked'), Localization.CurrentSlideResource.ShowSlideMagnifier, true);
    this._fullSizeToolbutton = new CurrentSlide.Toolbutton(this, $(this._parentArea.ID + 'FullSizeToolbutton'), CurrentSlide.$create_ToolbuttonClassInfo('CurrentSlideAreaFullSizeToolbuttonNormal', 'CurrentSlideAreaFullSizeToolbuttonOver', 'CurrentSlideAreaFullSizeToolbuttonDisabled', 'CurrentSlideAreaFullSizeToolbuttonChecked'), Localization.CurrentSlideResource.ShowFullSize, true);
    this._slideDescriptionsShowing = new MediasitePlayerCookie().GetBoolValue("ShowSlideDescriptions");
    
    if(this._slideDescriptionsShowing)
    {
            this._parentArea.turnOnSlideDescription();
            this._viewportToolbutton.set_isDisabled(true);
            this._fullSizeToolbutton.set_isDisabled(true);    
    }
}
CurrentSlide.CurrentSlideToolbuttonController.prototype = {
    _parentArea: null,
    _viewportToolbutton: null,
    _fullSizeToolbutton: null,
    _isClickInitialized: false,
    _slideDescriptionsShowing: false,
    
    selectButton: function CurrentSlide_CurrentSlideToolbuttonController$selectButton(button) {
        if (button === this._fullSizeToolbutton) {
            this._onFullSizeClicked();
        }
        else if (button === this._viewportToolbutton) {
            this._onViewportClicked();
        }
        else {
            Error.invalidOperation('Unknown button clicked');
        }
    },
    
    ensureClickIsInitialized: function CurrentSlide_CurrentSlideToolbuttonController$ensureClickIsInitialized() {
        if (this._isClickInitialized) {
            return;
        }
        if (this._fullSizeToolbutton) {
            this._fullSizeToolbutton.set_isDisabled(false);
            this._fullSizeToolbutton.set_tooltip(Localization.CurrentSlideResource.ShowFullSize);
        }
        if (this._viewportToolbutton) {
            this._viewportToolbutton.set_isDisabled(false);
            this._viewportToolbutton.set_tooltip(Localization.CurrentSlideResource.ShowSlideMagnifier);
        }
        this._isClickInitialized = true;
    },
    
    resetClick: function CurrentSlide_CurrentSlideToolbuttonController$resetClick() {
        if (this._fullSizeToolbutton) {
            this._fullSizeToolbutton.set_isDisabled(true);
        }
        if (this._viewportToolbutton) {
            if (this._viewportToolbutton.get_isChecked()) {
                this._hideMagnifier();
            }
            this._viewportToolbutton.set_isDisabled(true);
        }
        this._isClickInitialized = false;
    },
    
    _onFullSizeClicked: function CurrentSlide_CurrentSlideToolbuttonController$_onFullSizeClicked() {
        this._openFullSizeWindow();
    },
        
    ToggleSlideDescriptions: function(){
        
        if(this._slideDescriptionsShowing)
        {
            this._parentArea.turnOffSlideDescription();
            if (mPlayer.CurrentSlideNumber > 0 && !mPlayer.PresentationEnded) 
            {
                this._viewportToolbutton.set_isDisabled(false);
                this._fullSizeToolbutton.set_isDisabled(false);
                this._slideDescriptionsShowing = false;
            }
        }    
        else
        {
            this._parentArea.turnOnSlideDescription();
            this._viewportToolbutton.set_isDisabled(true);
            this._fullSizeToolbutton.set_isDisabled(true);
            this._slideDescriptionsShowing = true;
        }
        
        new MediasitePlayerCookie().SetValue("ShowSlideDescriptions", this._slideDescriptionsShowing);
    },
    
    _onViewportClicked: function CurrentSlide_CurrentSlideToolbuttonController$_onViewportClicked() {
        if (this._viewportToolbutton.get_isChecked()) {
            this._hideMagnifier();
        }
        else {
            this._showMagnifier();
        }
    },
    
    _showMagnifier: function CurrentSlide_CurrentSlideToolbuttonController$_showMagnifier() {
        this._viewportToolbutton.set_tooltip(Localization.CurrentSlideResource.HideSlideMagnifier);
        this._parentArea.showMagnifier();
        this._viewportToolbutton.set_isChecked(true);
    },
    
    _hideMagnifier: function CurrentSlide_CurrentSlideToolbuttonController$_hideMagnifier() {
        this._viewportToolbutton.set_tooltip(Localization.CurrentSlideResource.ShowSlideMagnifier);
        this._parentArea.hideMagnifier();
        this._viewportToolbutton.set_isChecked(false);
    },
    
    _openFullSizeWindow: function CurrentSlide_CurrentSlideToolbuttonController$_openFullSizeWindow() {
        if (WindowHelper.IsOpen(mPlayer.PopupWindows.FullSize)) {
            return;
        }
        mPlayer.PopupWindows.FullSize = WindowHelper.CreateNamedPopup(WindowHelper.PopupNames.FullSize, 'FullSizeWindow', mPlayer.DefaultPopupWindowWidth, mPlayer.DefaultPopupWindowHeight, true, true);
    }
}

CurrentSlide.Toolbutton = function CurrentSlide_Toolbutton(controller, element, classInfo, tooltip, isDisabled) {
    this._controller = controller;
    this._element = element;
    this._classInfo = classInfo;
    this.set_tooltip(tooltip);
    this.set_isDisabled(isDisabled);
}
CurrentSlide.Toolbutton.prototype = {
    _controller: null,
    _element: null,
    _isChecked: false,
    _isDisabled: false,
    _classInfo: null,
    _tooltip: null,
    
    get_tooltip: function CurrentSlide_Toolbutton$get_tooltip() {
        return this._tooltip;
    },
    set_tooltip: function CurrentSlide_Toolbutton$set_tooltip(value) {
        this._tooltip = value;
        SfKernel.Util.SetToolTip(this._element, this._tooltip);
        return value;
    },
    
    get_isChecked: function CurrentSlide_Toolbutton$get_isChecked() {
        return this._isChecked;
    },
    set_isChecked: function CurrentSlide_Toolbutton$set_isChecked(value) {
        this._isChecked = value;
        this._updateImage();
        return value;
    },
    
    get_isDisabled: function CurrentSlide_Toolbutton$get_isDisabled() {
        return this._isDisabled;
    },
    set_isDisabled: function CurrentSlide_Toolbutton$set_isDisabled(value) {
        this._isDisabled = value;
        if (this._isDisabled) {
            this._element.stopObserving();
        }
        else {
            this._element.observe('mouseover', Function.createDelegate(this, this._onMouseOver));
            this._element.observe('mouseout', Function.createDelegate(this, this._onMouseOut));
            this._element.observe('click', Function.createDelegate(this, this._onClick));
        }
        this._updateImage();
        return value;
    },
    
    _onClick: function CurrentSlide_Toolbutton$_onClick(sender, args) {
        this._controller.selectButton(this);
    },
    
    _onMouseOver: function CurrentSlide_Toolbutton$_onMouseOver(sender, args) {
        if (this._isDisabled) {
            return;
        }
        SfKernel.Util.SetCursor(this._element, SfKernel.CursorType.Hand);
        if (!this.get_isChecked()) {
            this._element.className = this._classInfo.over;
        }
    },
    
    _onMouseOut: function CurrentSlide_Toolbutton$_onMouseOut(sender, args) {
        this._updateImage();
        SfKernel.Util.SetCursor(this._element, SfKernel.CursorType.Default);
    },
    
    _updateImage: function CurrentSlide_Toolbutton$_updateImage() {
        if (this._isDisabled) {
            this._element.className = this._classInfo.disabled;
            return;
        }
        if (this._isChecked) {
            this._element.className = this._classInfo.checked;
        }
        else {
            this._element.className = this._classInfo.normal;
        }
    }
}

CurrentSlide.ViewportManager = function CurrentSlide_ViewportManager(parentArea) {
    this._parentArea = parentArea;
    this._initialize();
}
CurrentSlide.ViewportManager.prototype = {
    _parentArea: null,
    _viewportElement: null,
    _viewportImage: null,
    _magnifier: null,
    _isShowing: false,
    
    get_isShowing: function CurrentSlide_ViewportManager$get_isShowing() {
        return this._isShowing;
    },
    set_isShowing: function CurrentSlide_ViewportManager$set_isShowing(value) {
        this._isShowing = value;
        if (value) {
            this._viewportImage.setAttribute('src', mPlayer.CurrentFullSizeImage);
            this._magnifier.Enable();
        }
        else {
            this._magnifier.Disable();
        }
        return value;
    },
    
    _initialize: function CurrentSlide_ViewportManager$_initialize() {
        this._createViewportElement();
        mPlayer.EventManager.Events.addHandler(SfKernel.EventType.Script, Function.createDelegate(this, this._onScriptEvent));
        mPlayer.EventManager.Events.addHandler(SfKernel.EventType.PlayingFromBeginning, Function.createDelegate(this, this._onPlayingFromBeginning));
        this._magnifier = new SfUI.Magnifier(this._parentArea.get_slideImageDiv(), this._viewportElement);
    },
    
    _createViewportElement: function CurrentSlide_ViewportManager$_createViewportElement() {
        this._viewportElement = $(document.createElement('div'));
        this._viewportElement.setStyle({ overflow: 'hidden', position: 'absolute', display: 'none', border: '1px solid #666', zIndex: '4', cursor: 'crosshair',
                                         width: this._parentArea.ViewportWidth + 'px', 
                                         height: this._parentArea.ViewportHeight + 'px'});
        this._viewportElement.setAttribute('id','currentSlideMagnifierDiv');
        this._viewportImage = $(document.createElement('img'));
        this._viewportImage.setAttribute('id','currentSlideMagnifierImage');
        this._viewportElement.appendChild(this._viewportImage);

        this._parentArea.GetDiv().parentNode.appendChild(this._viewportElement); 
        //this._parentArea.GetDiv().appendChild(this._viewportElement); 
    },
    
    _onScriptEvent: function CurrentSlide_ViewportManager$_onScriptEvent(sender, args) {
        var command = args['Command'];
        switch (command) {
            case SfKernel.ScriptCmdType.ShowSlide:
                this._onShowSlide(args);
                break;
            case SfKernel.ScriptCmdType.EndPresentation:
                this._onEndPresentation(args);
                break;
        }
    },
    
    _onShowSlide: function CurrentSlide_ViewportManager$_onShowSlide(args) {
        if (!this._isShowing) {
            return;
        }
        this._viewportImage.setAttribute('src', args['FullSizeImage']);
    },
    
    _onEndPresentation: function CurrentSlide_ViewportManager$_onEndPresentation(args) {
        this.set_isShowing(false);
    },
    
    _onPlayingFromBeginning: function CurrentSlide_ViewportManager$_onPlayingFromBeginning(sender, args) {
        this.set_isShowing(false);
        if(LayoutOptions.Images['SlideDefault'])
        {
            this._parentArea._setSlideImage$1(LayoutOptions.Images['SlideDefault'].ImageFilename);
            this._parentArea._setSlideLink$1(LayoutOptions.Images['SlideDefault'].ImageUrl);
        }
    }
}

CurrentSlide.CurrentSlideToolbuttonController.registerClass('CurrentSlide.CurrentSlideToolbuttonController', null, CurrentSlide.IToolbuttonController);
CurrentSlide.Toolbutton.registerClass('CurrentSlide.Toolbutton');
CurrentSlide.ViewportManager.registerClass('CurrentSlide.ViewportManager');


