/* ON PAGE TRANSCRIPT */

EVERYZING.transcriptMod_ares_fullTranscriptText = "";

EVERYZING.transcriptMod_ares_toggleTranscript = function(tClipLength) {
    var tObjEl = document.getElementById('ez-fullTranscript');
    var tBtnEl = document.getElementById('ez-transcript-btn');
	
    if (tBtnEl.className == "ez-transcript-btn ez-collapsed"){
        tObjEl.innerHTML = EVERYZING.transcriptMod_ares_fullTranscriptText;
        tObjEl.className = "ez-full";
		tBtnEl.className = "ez-transcript-btn ez-expanded";
    }else{
	    EVERYZING.transcriptMod_ares_fullTranscriptText = tObjEl.innerHTML;
	    jQuery(tObjEl).truncateText(tClipLength, '... "');
        tObjEl.className = "ez-clipped";
		tBtnEl.className = "ez-transcript-btn ez-collapsed";
    }
};



/* POP-UP TRANSCRIPT */

EVERYZING.transcriptMod_openFullTranscript = function(){
    var pWidth = 520; // width of popup
    var pHeight = 520; // height of popup
    var leftPos = screen.width - pWidth - 100; // 100px from right of screen
    var topPos = (screen.height - pHeight)/2; // vertically centered
    
    window.open(location.href.replace("/m/", "/transcript/"), "Transcript", "left=" + leftPos + ",top=" + topPos + ",width=" + pWidth + ",height=" + pHeight + ",resizable,scrollbars");
};

EVERYZING.transcriptMod_ares_showAllSnippets = function(){
    jQuery("#snippetsTranscriptPane .ez-transcriptMod-ares-snippetItem").each(function(){
        var snippetItem = jQuery(this);
        snippetItem.show();
		
        /* highlight keywords in the snippetItem */
        snippetItem.find("b").each(function(){      
            var wordElement = jQuery(this);
            wordElement.addClass("kwHighlight");
        });
	});
	
    /* Show snippets in flash player */
    if (typeof(keywordEl) == 'undefined' || keywordEl == null){
        if (typeof playerInst0 != 'undefined') {
            playerInst0.showHideSnippetArrow(true, '');
        }
    }
};


/* KEYWORD CLICK - PLAYER SIDEBAR */
EVERYZING.transcriptMod_ares_keywordClick = function(keywordEl, lckeyword){	
    var transcriptComponent = jQuery(".ez-transcriptMod-ares.snippets");
    var transcriptTabPanes = jQuery(".transcript-content", transcriptComponent);
    var keywordContainer = jQuery(".ez-transcriptMod-ares-keywords");
    
    var keywordFound = false;
    var keywordElement = jQuery(keywordEl);
    var keywordText = keywordElement.text();
    var keyword = new RegExp(keywordText, 'gi');
    var snippetShowingCounter = 0;
    
    /* Highlight the keyword */
    keywordContainer.find(".kwHeaderHighlight").removeClass("kwHeaderHighlight");
    keywordElement.addClass("kwHeaderHighlight");
    
    /* Show matching snippetItems */
    transcriptTabPanes.children("#snippetsTranscriptPane").find(".ez-transcriptMod-ares-snippetItem").each(function(){
        var snippetItem = jQuery(this);
        
        snippetItem.hide();
		
        /* highlight keywords in the snippetItem */
        snippetItem.find("b").each(function(){		
            var wordElement = jQuery(this);
            
            if (keywordElement.attr("matchId") == wordElement.attr("matchId")){
	            if (snippetItem.css('display') == 'none') {
	                snippetItem.show();
	                snippetShowingCounter++;
	                keywordFound = true;
	            }
                wordElement.addClass("kwHighlight");
            }else{
                wordElement.removeClass("kwHighlight");
            }
        });
    });
    
    if (!keywordFound) {
        transcriptTabPanes.children("#notFoundTranscript").show().siblings().hide();
    } else {
        // Here, we'll update the count span to show the number of results being displayed...
        transcriptComponent.find(".number-results").html("("+snippetShowingCounter+")");
        snippetShowingCounter = 0;
    };
    
    /* Show snippet in flash player */
    if (typeof playerInst0 != 'undefined') {
        playerInst0.showHideSnippetArrow(true, lckeyword);
    }
    
};
