////////////////////////////////////////////////////////////////////////////////
// SpeakerInfoAnchor

SpeakerInfoAnchor = function(card, index) {
    this._card = card;
    this._index = index;
    this._element = $(this._card.ID + 'SpeakerInfoImage' + this._index);
    new SfUI.Tooltip.TooltipEnabled(this._card.get_scrollDiv(), this._element, $(this._card.ID + 'SpeakerInfoPopup' + this._index));
    this._element.observe('mouseover', Function.createDelegate(this, function(sender, args) {
        this._element.setAttribute('src', this._card.ImageBase + '/presenterInfoOver.gif');
    }));
    this._element.observe('mouseout', Function.createDelegate(this, function(sender, args) {
        this._element.setAttribute('src', this._card.ImageBase + '/presenterInfo.gif');
    }));
}
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'), SfKernel.EncodeHTML(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);
            }
        }
    }
    
PresentationCardPanel.prototype._initializeSpeakers=function() {
        if(Manifest.Presenters.length < 1)
        {
            return;
        }
        
        this._addAllSpeakerNamesEtc();
        this._addSpeakerInfoPopups();
        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._presentersTextDiv.appendChild(document.createTextNode(', '));
        }
        this._addSpeakerNameEtc(len, Manifest.Presenters[len - 1]);
    }
    
PresentationCardPanel.prototype._addSpeakerNameEtc=function(index, presenter) {
        if (presenter.ImageUrl) 
        {
            var imageElement = $(document.createElement('img'));
            imageElement.setAttribute('id', this.ID + 'SpeakerInfoImage' + index);
            imageElement.setAttribute('src', this.ImageBase + '/presenterInfo.gif');
            imageElement.className = 'cardPresenterInfoImage';
            this._presentersTextDiv.appendChild(imageElement);
        }

        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(document.createTextNode(presenter.Name));
        }
        else 
        {
            this._presentersTextDiv.appendChild(document.createTextNode(presenter.Name));
        }
    }
    
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(index, presenter)
    {
        var element = $(document.createElement('div'));
        this._presentersTextDiv.appendChild(element);
        element.setAttribute('id', this.ID + 'SpeakerInfoPopup' + index);
        element.className = 'speakerInfoPopup';
        element.setStyle({ display: 'none', position: 'absolute' });
        var imageContainer = $(document.createElement('div'));
        element.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() {
    }



