////////////////////////////////////////////////////////////////////////////////
// SpeakerInfoAnchor

SpeakerInfoAnchor = function(card, index) {
    this._card = card;
    this._index = index;
    this._element = $(this._card.ID + 'SpeakerInfoImage' + this._index);
    this._element.observe('mouseover', Function.createDelegate(this, function(sender, args) {
        this._element.setAttribute('src', this._card.ImageBase + '/presenterInfoOver.png');
    }));
    this._element.observe('mouseout', Function.createDelegate(this, function(sender, args) {
        this._element.setAttribute('src', this._card.ImageBase + '/presenterInfo.png');
    }));
    this._element.observe('mouseover', Function.createDelegate(this, function(sender, args) {
        $(this._card.ID + 'SpeakerInfoPopup' + this._index).style.display = 'block';
    }));
    $(this._card.ID + 'SpeakerInfoPopup' + this._index).observe('mouseout', Function.createDelegate(this, function(sender, args) {
        $(this._card.ID + 'SpeakerInfoPopup' + this._index).style.display = 'none';
    }));
    $(this._card.ID + 'SpeakerInfoPopup' + this._index).observe('mouseover', Function.createDelegate(this, function(sender, args) {
        $(this._card.ID + 'SpeakerInfoPopup' + this._index).style.display = 'block';
    }));
    $(this._card.ID + 'SpeakerInfoPopupInner' + this._index).observe('mouseout', Function.createDelegate(this, function(sender, args) {
        $(this._card.ID + 'SpeakerInfoPopup' + this._index).style.display = 'block';
    }));
}

SpeakerInfoAnchor.prototype = {
    _card: null,
    _index: 0,
    _element: null
}

////////////////////////////////////////////////////////////////////////////////
// PresentationCardPanel

PresentationCardPanel = function(container, containingWindow, id) {
    this.Container = container;
	this.ContainingWindow = containingWindow;
	this.ID = id;
    this._scrollDiv = $(this.ID + 'ScrollDiv');
    this._innerPadding = $(this.ID + 'InnerPadding');
    this._cardMore = $('PresentationCardAreaMore');
    this._presentersTextDiv = $(this.ID + 'PresentersText');
    
}
PresentationCardPanel.prototype= new Panel();
PresentationCardPanel.prototype.constructor=PresentationCardPanel;
PresentationCardPanel.prototype.baseClass=Panel.prototype.constructor;
PresentationCardPanel.prototype._scrollDiv=null;
PresentationCardPanel.prototype._innerPadding=null;
PresentationCardPanel.prototype._cardMore=null;
PresentationCardPanel.prototype._presentersTextDiv=null;
PresentationCardPanel.prototype._currentDimensions=null;
PresentationCardPanel.prototype._mouseoverDimensions=null;
PresentationCardPanel.prototype._isScrolling=false;
PresentationCardPanel.prototype._zIndexPrevious=0;

PresentationCardPanel.prototype.create_BoundsInt = function() { 
        return {}; 
    }
PresentationCardPanel.prototype.get_scrollDiv=function() {
        return this._scrollDiv;
    }
PresentationCardPanel.prototype.set_scrollDiv=function(value) {
        this._scrollDiv = value;
        return value;
    }

PresentationCardPanel.prototype.get_currentDimensions=function() {
        return this._currentDimensions;
    }
PresentationCardPanel.prototype.set_currentDimensions=function(value) {
        this._currentDimensions = value;
        return value;
    }

PresentationCardPanel.prototype.get_mouseoverDimensions=function() {
        return this._mouseoverDimensions;
    }
PresentationCardPanel.prototype.set_mouseoverDimensions=function(value) {
        this._mouseoverDimensions = value;
        return value;
    }    
          
PresentationCardPanel.prototype.OnLoad=function() 
{        
        this._setPresentationCardTextItem($(this.ID + 'Title'), Localization.PresentationCardResource.DefaultTitle);

        if(!LayoutOptions.HideDateTime)
        {   
            this._setPresentationCardTextItem($(this.ID + 'AirDateText'), "01/01/2000");       
            this._setPresentationCardTextItem($(this.ID + 'AirTimeText'), "12:00");
        }        
        this._setPresentationCardTextItem($(this.ID + 'DescriptionText'), Localization.PresentationCardResource.DefaultDescription);  
        this._setPresentationCardTextItem($(this.ID + 'DurationLabel'), Localization.PresentationCardResource.Duration);
        this._setPresentationCardTextItem($(this.ID + 'DurationText'), "00:00:00");
        this._setPresentationCardTextItem($(this.ID + 'More'), Localization.PresentationCardResource.More);
        this._initializeZooming();
}

PresentationCardPanel.prototype.OnDataLoad=function() 
{
        this._initializeItems();       
}
  
PresentationCardPanel.prototype._initializeItems=function() 
    {
        this._setPresentationCardTextItem($(this.ID + 'Title'), Manifest.Title);
        
        if(!LayoutOptions.HideDateTime)
        {
            this._setPresentationCardTextItem($(this.ID + 'AirDateText'), Manifest.AirDate);
            this._setPresentationCardTextItem($(this.ID + 'AirTimeText'), Manifest.AirTime);
        }
        
        if(Manifest.Duration < 1)
        {
            this._setPresentationCardTextItem($(this.ID + 'DurationLabel'), '');
            this._setPresentationCardTextItem($(this.ID + 'DurationText'), '');          
        }
        else
        {
            this._setPresentationCardTextItem($(this.ID + 'DurationText'), SfKernel.GetDisplayDuration(Manifest.Duration, true));        
        }

        
        if(Manifest.Description == null || Manifest.Description.length < 1)
        {
            this._setPresentationCardTextItem($(this.ID + 'DescriptionText'), '');  
        }
        else
        {
            this._setPresentationCardTextItem($(this.ID + 'DescriptionText'), Manifest.Description);  
        }
        
        this._initializeSpeakers();
    }
    
PresentationCardPanel.prototype._setPresentationCardTextItem=function(element, text) 
    {
        if(text != null)
        {
            element.innerHTML=SfKernel.EncodeHTML(text);
        }
        else
        {
            element.innerHTML="";
        }
    }
    
PresentationCardPanel.prototype._initializeZooming=function() {
        this._currentDimensions = this.create_BoundsInt();
        this._currentDimensions.Top = window.parseInt(this.GetDiv().style.top);
        this._currentDimensions.Left = window.parseInt(this.GetDiv().style.left);
        this._currentDimensions.Width = window.parseInt(this.GetDiv().style.width);
        this._currentDimensions.Height = window.parseInt(this.GetDiv().style.height);
        this._mouseoverDimensions = this.create_BoundsInt();
        this._mouseoverDimensions.Width = window.parseInt(this.Mouseover_Width);
        this._mouseoverDimensions.Height = window.parseInt(this.Mouseover_Height);
        this._cardMore.observe('click', Function.createDelegate(this, this._toggleScrolling));
        this._cardMore.observe('mouseover', Function.createDelegate(this, this._moreMouseover));
        this._cardMore.observe('mouseout', Function.createDelegate(this, this._moreMouseout));
        var strZIndex = this.GetDiv();
        
        strZIndex=strZIndex.style.zIndex;
        if (!strZIndex) {
            this._zIndexPrevious = 0;
        }
        else {
            this._zIndexPrevious = window.parseInt(strZIndex);
        }        
    }
    
    PresentationCardPanel.prototype._moreMouseover=function(sender, args) {
        // more button mouseover
        // change css class to mouseover version
    }
    
    PresentationCardPanel.prototype._moreMouseout=function(sender, args) {
        // more button mouseout
        // change css class to normal version
    }
    
    PresentationCardPanel.prototype._enableScrolling=function() {
        this._scrollDiv.style.overflowY = 'scroll';
        this._scrollDiv.style.overflowX = 'hidden';
    }
    
    PresentationCardPanel.prototype._disableScrolling=function() {
        this._scrollDiv.style.overflow = 'hidden';
        this._scrollDiv.style.overflowY = 'hidden';
        this._scrollDiv.style.overflowX = 'hidden';
    }
    
    PresentationCardPanel.prototype._toggleScrolling=function(sender, args) {
        if (this._scrollDiv.style.overflow == 'scroll' || this._scrollDiv.style.overflowY == 'scroll' ) {
            this._disableScrolling();
        }
        else {
            this._enableScrolling();
        }
    }

    PresentationCardPanel.prototype._initializeSpeakerPopups = function() {

        var len = Manifest.Presenters.length;
        for (var i = 0; i < len; ++i) {
            if (Manifest.Presenters[i].ImageUrl.length > 0) {
                new SpeakerInfoAnchor(this, i + 1);
            }
        }

        if (LayoutOptions) {
            var isCompact = (LayoutOptions.VideoWidth == '400' && LayoutOptions.SlideWidth == '360');
            if (LayoutOptions.DefaultPosition == 3 || LayoutOptions.DefaultPosition == 4 || isCompact) {
                var presenterPopupElements = $$('.speakerInfoPopupContainer');
                var presenterPopupInnerElements = $$('.speakerInfoPopup');
                var presenterPopupArrowElements = $$('.speakerInfoPopupArrow');
                for (var j = 0; j < presenterPopupElements.length; j++) {
                    $(presenterPopupElements[j]).className = 'speakerInfoPopupContainerDown';
                }
                for (var k = 0; k < presenterPopupInnerElements.length; k++) {
                    $(presenterPopupInnerElements[k]).className = 'speakerInfoPopupDown';
                }
                for (var l = 0; l < presenterPopupArrowElements.length; l++) {
                    $(presenterPopupArrowElements[l]).className = 'speakerInfoPopupArrowDown';
                }
            }
        }

    }
    
PresentationCardPanel.prototype._initializeSpeakers=function() {
        if(Manifest.Presenters.length < 1)
        {
            return;
        }
        
        this._addAllSpeakerNamesEtc();
        this._initializeSpeakerPopups();
    }

    PresentationCardPanel.prototype._addAllSpeakerNamesEtc = function() {
        var len = Manifest.Presenters.length;
        if (!len) {
            return;
        }
        for (var i = 1; i < len; ++i) {
            this._addSpeakerNameEtc(i, Manifest.Presenters[i - 1]);
        }
        this._addSpeakerNameEtc(len, Manifest.Presenters[len - 1]);
    }

    PresentationCardPanel.prototype._addSpeakerNameEtc = function(index, presenter) {
        var speakerElement = $(document.createElement('div'));
        speakerElement.setAttribute('id', this.ID + 'SpeakerInfoElement' + index);
        if (presenter.ImageUrl) {
            var imageElement = $(document.createElement('img'));
            imageElement.setAttribute('id', this.ID + 'SpeakerInfoImage' + index);
            imageElement.setAttribute('src', this.ImageBase + '/presenterInfo.png');
            imageElement.className = 'cardPresenterInfoImage';
            this._addSpeakerInfoPopup(speakerElement, index, presenter);
            speakerElement.appendChild(imageElement);
        }

        if (presenter.BioUrl.length > 0) {
            var a = $(document.createElement('a'));
            speakerElement.appendChild(a);
            a.setAttribute('href', presenter.BioUrl);
            a.setAttribute('target', '_blank');
            a.appendChild(document.createTextNode(presenter.Name));
        }
        else {
            speakerElement.appendChild(document.createTextNode(presenter.Name));
        }
        this._presentersTextDiv.appendChild(speakerElement);
    }
    
    PresentationCardPanel.prototype._addSpeakerInfoPopups=function() {
        var len = Manifest.Presenters.length;
        for (var i = 0; i < len; ++i) {
            this._addSpeakerInfoPopup(i + 1, Manifest.Presenters[i]);
        }
    }

    PresentationCardPanel.prototype._addSpeakerInfoPopup = function(speakerElement, index, presenter) {
    var element = $(document.createElement('div'));
        speakerElement.appendChild(element);
        element.setAttribute('id', this.ID + 'SpeakerInfoPopup' + index);
        element.setStyle({ display: 'none', position: 'absolute' });
        element.className = 'speakerInfoPopupContainer';

        var arrowElement = $(document.createElement('div'));
        arrowElement.setAttribute('id', this.ID + 'SpeakerInfoPopupArrow' + index);
        arrowElement.className = 'speakerInfoPopupArrow';
        element.appendChild(arrowElement);

        var innerElement = $(document.createElement('div'));
        innerElement.setAttribute('id', this.ID + 'SpeakerInfoPopupInner' + index);
        innerElement.className = 'speakerInfoPopup';
        element.appendChild(innerElement);

        var imageContainer = $(document.createElement('div'));
        innerElement.appendChild(imageContainer);
        imageContainer.className = 'speakerInfoPopupImageContainer';

        if (presenter.ImageUrl.length > 0) {
            var imageElement = $(document.createElement('img'));
            imageElement.setAttribute('src', this._getSpeakerImageSrc(presenter));
            imageElement.className = 'speakerInfoPopupImage';
            imageElement.style.display = 'block';

            if (presenter.BioUrl.length > 0) {
                var a = $(document.createElement('a'));
                this._presentersTextDiv.appendChild(a);
                a.setAttribute('href', presenter.BioUrl);
                a.setAttribute('target', '_blank');
                a.appendChild(imageElement);
                imageContainer.appendChild(a);
            }
            else {
                imageContainer.appendChild(imageElement);
            }
        }
    }
    
PresentationCardPanel.prototype._getSpeakerImageSrc=function(presenter) {
        return presenter.ImageUrl;
    }
    
PresentationCardPanel.prototype.OnUnLoad=function() {
    }



