/* title:         jquery.transcriptManager.js
 * description:   jQuery-based Transcript Manager.
 * version:       0.0.1
 * author:        tparent@everyzing.com
 * date:          12.11.2007
 * 
 * long desc: Transcript Manager takes the full transcript, broken into Snippets
 *     (logical pieces, usually denoted by a change in voice), as well as any
 *     applicable search and/or keyword terms. It should take the transcript and
 *     break it into an array, where the index of each item corresponds to the
 *     index of the appropriate snippet timestamp (more on THAT later).
 *     
 *     Having broken the transcript into an array, we can check each line for the
 *     existence or absence of a key or search term. If we have them, we create
 *     sub-snippets containing a wrapper around the appropriate search term. When
 *     the user clicks on the search/keyword term, we replace the transcript box with
 *     the found data.
 */

/* title:         jquery.playerManager.js
 * description:   jQuery-based Player Manager.
 * version:       0.0.1
 * author:        tparent@everyzing.com
 * date:          1.4.2008
 * 
 * long desc: jquery.playerManager.js will gradually grow to take over as the de
 * 	   facto controller for the player component of the page. for now, it will handle
 * 	   toggling the snippet/full tabs and controlling the visual components controlling
 *     the player.
 *     
 * 	   NOTE: Currently, the player core functionality is contained in Player.js, PlayerManager.js
 *           and/or PlayerUtil.js (among others).
 * 
 */

jQuery.noConflict();
jQuery(document).ready(function(){

            keywordsComponent = jQuery(".ez-transcriptMod-keywords");
            transcriptComponent = jQuery(".ez-transcriptMod-snippets");
            transcriptTabs = jQuery(".transcript-nav li", transcriptComponent);
            transcriptTabPanes = jQuery(".transcript-content", transcriptComponent);
            
            transcriptTabs.children("#snippets").addClass("selected").siblings().removeClass("selected");
            transcriptTabPanes.children("#snippetsTranscriptTab").show().siblings().hide();

            searchTermSnippets = transcriptTabPanes.find("#snippetsTranscript p span[@eztype=st]");
            if(searchTermSnippets.length > 0) {
				jQuery("#snippetsTranscript p", transcriptTabPanes).hide()
            	jQuery("#snippetsTranscript p span[@eztype=st]").parent().show();
            }
            
            transcriptTabs.each(function(){
            	jQuery(this).bind("click", function(){
	            	var toggleThis = "#"+jQuery(this).attr("id")+"TranscriptTab";
	            	if(window.console)console.log(toggleThis);
	            	jQuery(this).addClass("selected").siblings().removeClass("selected");
	            	transcriptTabPanes.children(toggleThis).show().siblings().hide();
            	});
            });
            
            keywordsComponent.children("a").bind("click", function(){
            	keywordFound = false;
				keywordArray = jQuery(this).text().split('"');
            	thisKeyword = new RegExp(keywordArray[1], 'gi');

            	transcriptTabs.parent().children("#snippets").addClass("selected").siblings().removeClass("selected");

            	//transcriptTabPanes.children("#snippetsTranscript").show().siblings().hide();

        		transcriptTabPanes.find("#snippetsTranscript").find("p").hide();
        		transcriptTabPanes.find("#snippetsTranscript").find("p").each(function(){
        			thisPassage = jQuery(this);
        			thisText = thisPassage.text().replace(/\s+/g, ' ');
        			var myMatches = thisText.match(thisKeyword);
        			if (myMatches) {
        				thisPassage.show();
        				keywordFound=true;
						jQuery("#notFoundTranscript", transcriptTabPanes).hide();
        			}
        		});
        		if (!keywordFound){
					jQuery("#notFoundTranscript", transcriptTabPanes).show();
        		};
            	
            });


});

