// Dynamically add the CSS for flyout menus. If JS is not loaded, the superfish.css isn't loaded either. This allows the flyout menus to work without JS enabled.
(function () {
	var head = document.getElementsByTagName("head")[0];
	if (head) {
		var scriptStyles = document.createElement("link");
		scriptStyles.rel = "stylesheet";
		scriptStyles.type = "text/css";
		scriptStyles.href = "css/superfish.css";
		scriptStyles.charset = "utf-8";
		scriptStyles.media = "screen";
		head.appendChild(scriptStyles);
	}
}());

function deletePlayer(theWrapper, thePlaceholder, thePlayerId) { 
        swfobject.removeSWF(thePlayerId);
        var tmp=document.getElementById(theWrapper);
        if (tmp) { tmp.innerHTML = "<div id=" + thePlaceholder + "></div>"; }
}


function createPlayer(thePlaceholder, thePlayerId, theFile, captionFile) {
        var flashvars = {
                file:theFile, 
                streamer:"rtmpt://video.csus.edu/pa/",
                autostart:"true",
							
                'plugins':'captions-1,viral-1,gapro-1',
                'gapro.accountid' : 'UA-798015-1' 
        }
        
        if (captionFile) {
            
            flashvars['captions'] = captionFile;
        }
        var params = {
                allowfullscreen:"true", 
                allowscriptaccess:"always"
        }
        var attributes = {
                id:thePlayerId,  
                name:thePlayerId
        }
        swfobject.embedSWF("http://www.csus.edu/video/swf/player.swf", thePlaceholder, "640", "379", "9.0.115", false, flashvars, params, attributes);
}


function initPlayer(theFile, captionFile) { 
        deletePlayer('VideoContainer', 'player', 'mpl'); 
        createPlayer('player', 'mpl', theFile, captionFile);
}



$(document).ready(function(){ 

  // Add classes to flyout menus that allow them to work. 
	//For more info, see http://users.tpg.com.au/j_birch/plugins/superfish/
	$("ul.sf-menu").superfish(	{ 
		delay:       100,  
		dropShadows: false
	}); 

  // Accessibility features. Optional, but recommended. They should have no impact on design.
	$('#search').attr('role', 'search');
	$('#main_content').attr('role', 'main');
	$('.navigation').attr('role', 'navigation');
	$('.banner').attr('role', 'banner');
	$('.footer').attr('role', 'contentinfo'); 
    
  $('.tabs').tabs();
    
   $('.collection li').each(function() {
   
       $(this).click(function() {
        captionFile = $(this).attr('captions');
        transcript = $(this).attr('transcript');
        $('.collection li').removeClass('selected');
       	initPlayer($(this).attr('rel'), captionFile);
        $('.CaptionContainer').empty().html($(this).find('.hidden').html());
		$(this).addClass('selected');
       });
   });
            
	
}); 