/*
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=='undefined'){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\" nonfix=\"true\" >";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;
/* End swfObject */

/* addLoadEvent function */
//if(!window.addLoadEvent){window.addLoadEvent=function(func){var oldonload=window.onload;if(typeof window.onload!='function'){window.onload=func;}else{window.onload=function(){if(oldonload){oldonload();}func();}}}}
/* End addLoadEvent */


/* VideoPageControl */
if(!window.BET){window.BET = {};}
if(BET.VideoPageControl == null){   // only create it once
    BET.VideoPageControl = function(config){
        if(config == null){ config = { }; }
        if(config.index == null){ config.index = 0; }
        if(config.defaultWidth == null || config.defaultHeight == null){
            config.defaultWidth = 426;
            config.defaultHeight = 390;        
        }
        if(config.swf == null){ 
            // config.swf = 'http://www.bet.com/static/stage/embeddedflux/embeddedPlayer.swf';
            config.swf = 'http://www.bet.com/static/video/viral/embeddedplayer.swf';
        }
        if(config.enableCoAd == null){ config.enableCoAd = true; }
        var _private = {
            index: config.index,
            playerCount: 0,
            players: new Array(),
            playerLookup: new Array(),
            coAds: new Array(),
            nextPlayerIndex: function(){
                       
                return this.playerCount++;
			},
            defaultWidth: config.defaultWidth,
            defaultHeight: config.defaultHeight,
            swf: config.swf
        }
        return {
            writePlayerHtml: function(settings){
                if(settings == null){ settings = {}; }
                var playerIndex = 0;// _private.nextPlayerIndex();
                var vpID = '_vp' + _private.index + '_' + playerIndex;
                //var width = (settings.width == null ? _private.defaultWidth : settings.width);
                //var height = (settings.height == null ? _private.defaultHeight : settings.height);
                var width;
                var height;
                if(settings.width == null || settings.height == null){
                    switch(settings.playerID){
                        case '106':
                            width = 376;
                            height = 315;
                            break;
                        default:
                            width = parseInt(_private.defaultWidth, 10);
                            height = parseInt(_private.defaultHeight, 10);
                            break;
                    }
                }else{
                    width = settings.width;
                    height = settings.height;
                }
                var playerType;
                switch(settings.playerType){
                    case 'sony':
                    case 'Sony':
                        playerType = 'Sony';
                        break;
                    case 'MTV':
                    case 'mtv':
                        playerType = 'MTV';
                        break;
                     case 'Federated':
                        playerType = 'Federated';
                        break;
                    default:
                       playerType = 'default';
                       break; 
                }
                
                var playerID = settings.playerID;
                var videoID = settings.videoID;
                var remoteVideoID = settings.remoteVideoID;
                 if(settings.playerType == 'Federated')
                {                    
                    var playerHolderDivID = settings.playerHolderDivID;        
                    var playerType = settings.playerType;                
                    //var videoID = settings.videoID;
                    var type = settings.type;
                    var allowFullScreen = settings.allowFullScreen;
                    var allowScriptAccess = settings.allowScriptAccess;
                    var id = settings.id;
                    playID = settings.id;
                    var flashVars=settings.flashVars;                    
                                
                    if(videoID == null){
                        return;
                    }  
                    
                    var playerConfig = { index: playerIndex, id: vpID, playerType: playerType, videoID: videoID, width: width, height: height, playerHolderDivID: playerHolderDivID, allowFullScreen: allowFullScreen, allowScriptAccess: allowScriptAccess, flashVars:flashVars, videoComplete: settings.videoComplete, playlistComplete: settings.playlistComplete };
                    
                    var player = new BET.VideoPlayerControl(playerConfig);  
                    
                     _private.players[playerIndex] = player;
                    _private.playerLookup[vpID] = player;              
                    player.writeHtml(); 
                
                }
                else
                {
					if(videoID == null){
						return;
					}					
					var playerHolderDivID = settings.playerHolderDivID;
					var swf = (settings.swf == null ? _private.swf : settings.swf);
					var dartOrdID = settings.dartOrdID;     // can be null					
					var playerConfig = { index: playerIndex, id: vpID, playerType: playerType, playerID: playerID, videoID: videoID, remoteVideoID: remoteVideoID, swf: swf, width: width, height: height, dartOrdID: dartOrdID, playerHolderDivID: playerHolderDivID, videoComplete: settings.videoComplete };
					var player = new BET.VideoPlayerControl(playerConfig);
					_private.players[playerIndex] = player;
					_private.playerLookup[vpID] = player;
					player.writeHtml();
					// coAd stuff
					var coAdConfig = null;
					if(settings.coAdDivID == null){
						if(settings.createCoAdDiv){
							// create a coAd
							coAdConfig = { };
						}
					}else{
						coAdConfig = { coAdDivID: settings.coAdDivID };
					}
					if(coAdConfig != null){
						var coAdID = '_coAd' + _private.index + '_' + playerIndex;
						coAdConfig.id = coAdID;
						var coAd = new BET.VideoPlayerCoAdControl(coAdConfig);
						_private.coAds[playerIndex] = coAd;
						coAd.writeHtml();
					}
                }
            },
            handleCoAd: function(playerIndex, adUrl, clickUrl){
                var coAd = _private.coAds[playerIndex];
                if(coAd != null){
                    coAd.showCoAd(adUrl, clickUrl);
                }
            },
            onAdComplete: function(playerIndex){
                //alert('onAdComplete: ' + playerIndex);
            },
            onVideoComplete: function(playerIndex){
                var player = _private.players[playerIndex];
			    if(player != null) {
				    if((typeof(player.videoComplete) != 'undefined') && (player.videoComplete != null)){
					    player.videoComplete(playerIndex);
				    }
			    }			
            },
            onPlaylistComplete: function(playerIndex){
                //alert('onPlaylistComplete: ' + playerIndex);
                var player = _private.players[playerIndex];
			    if(player != null) {
				    if((typeof(player.playlistComplete) != 'undefined') && (player.playlistComplete != null)){
					    player.playlistComplete(playerIndex);
				    }
			    }			
            },
            registerPlayer: function(key, settings){
				if(this.registeredPlayers == null){ this.registeredPlayers = new Array(); }
				this.registeredPlayers[key] = settings;
            },
            getRegisterdPlayerSettings: function(key){
				if(this.registeredPlayers == null){ return null; }
				return this.registeredPlayers[key];
            },
            insertRegisteredPlayer: function(key, div){
				if(this.registeredPlayers == null){ return; }
				var settings = this.registeredPlayers[key];
				if(!settings){ return; }
				if(div != null && settings.playerHolderDivID == null){ settings.playerHolderDivID = div.id; }
				this.writePlayerHtml(settings, div);
            }
        }
    }
    BET.VideoPlayerControl = function(config){		
        if(config == null){ return; }
        var _private = {
            index: config.index,
            id: config.id,
            width: config.width,
            height: config.height,
            //mgid: config.mgid,            
            allowFullScreen: config.allowFullScreen,
            allowScriptAccess: config.allowScriptAccess,
            flashVars: config.flashVars,
            swf: config.swf,
            div: null,
            playerType: config.playerType,
            playerID: config.playerID,
            videoID: config.videoID,
            remoteVideoID: config.remoteVideoID,
            dartOrdID: config.dartOrdID,
            playerHolderDivID: config.playerHolderDivID,
            videoComplete: config.videoComplete,
            playlistComplete: config.playlistComplete
        }           
	    var fixFlashDOMBug = function(flashObjID) {
		    var code = 'if(typeof ' + flashObjID + ' == \'undefined\'){ ' +
			    'var obj = document.getElementById(\'' + flashObjID + '\'); ' +
			    'if(obj){ ' +
			    '	' + flashObjID + ' = obj; ' +
			    '}else{ ' +
			    '	' + flashObjID + ' = { SetReturnValue: function(){ } }; ' +
			    '} ' +
		    '}; ';
		    eval(code);		
	    }	
        return {
            writeHtml: function(){
                var elID = '_playerDiv_' + _private.id;          
                if(_private.playerHolderDivID) {
                    var playerDiv = document.createElement('div');
                    playerDiv.setAttribute('id', elID);
                    playerDiv.setAttribute('class', 'videoPlayer');
                    var ref = document.getElementById(_private.playerHolderDivID);
                    if(ref == undefined){ return; }
                    ref.appendChild(playerDiv);     
                }else{
                    document.write('<div id="' + elID + '" class="videoPlayer"></div>');
                }
	            _private.div = document.getElementById(elID);
	            if(_private.div != null){
	                switch(_private.playerType){
	                    case 'Sony':
	                        var config = new Array();
                            config["videoId"] = _private.remoteVideoID;
                            config["videoRef"] = null;
                            config["lineupId"] = null;
                            config["playerTag"] = null;
                            config["autoStart"] = false;
                            config["preloadBackColor"] = "#FFFFFF";
                            config["width"] = _private.width;
                            config["height"] = _private.height;
                            config["playerId"] = "AFG16ENdXyqo38oOOiAXPJseNPmFl9yjt";
	                        _private.div.innerHTML = getExperienceHtml(config, 8).html;
	                        break;
	                    case 'MTV':
	                        _private.div.innerHTML = '<embed src="http://www.mtv.com/player/embed/" width="' + _private.width + '" height="' + _private.height + '" type="application/x-shockwave-flash" FlashVars="CONFIG_URL=http://www.mtv.com/player/embed/configuration.jhtml%3F%26vid%3D' + parseInt(_private.remoteVideoID, 10) + '&allowFullScreen=true" allowFullScreen="true" base="." allowScriptAccess="always" ></embed>';
	                        break;
	                     case 'Federated':
                            var mgid='mgid:media:video:bet.com:'+_private.videoID;
                            
                            var url='http://media.mtvnservices.com/'+mgid;
                            
                            if(PC.appEnvironment=='Development')
                            {
                                url='http://media.mtvnservices-d.mtvi.com/'+ mgid;
                            }
                            else if(PC.appEnvironment=='Staging')
                            {
                                url='http://media.mtvnservices-q.mtvi.com/'+mgid;
                            }
                            else if(PC.appEnvironment=='Production')
                            {
                                url='http://media.mtvnservices.com/'+mgid;
                            }                             
                            if(!_private.allowScriptAccess){_private.allowScriptAccess='always';}
                            
                            var so = new SWFObject(url, _private.id, _private.width, _private.height, '9.0.0', '#000000');
                            so.addParam('wmode', 'opaque');
                            so.addParam('allowScriptAccess', 'always');
                            so.addParam("allowFullscreen", "true");
                            so.addParam("flashVars", _private.flashVars);
                            so.write(elID);               
                            fixFlashDOMBug(_private.id);                   
                            break;
	                    default:
							
							if(_private.playerID == 'Article'){
								// we need to specify a different swf.
							
								_private.swf = 'http://www.bet.com/Assets/BET/Published/application/x-shockwave-flash/0e11021c-da2f-83e4-64aa-fed3ac727af4-embeddedPlayer.swf';
							}
	                    
	                        // standard player
		                    var so = new SWFObject(_private.swf, _private.id, _private.width, _private.height, '8,0,0,0', '#333333');
		                    so.addVariable('playerindex', _private.index); 
		                    so.addVariable('playerid', _private.playerID); 
		                    so.addVariable('videoid', _private.videoID);
			    //so.addVariable('nofix','true');
			    so.addVariable('nonfix','true');
		                    if(_private != null){
		                        so.addVariable('dartOrd', _private.dartOrdID);
		                    }
		                    so.addParam('wmode', 'opaque');
		                    so.addParam('allowScriptAccess', 'always');	
			    //so.addParam('nofix','true');	
			    //so.addParam('nonfix','true');				
		                    so.write(elID);	
				            fixFlashDOMBug(_private.id);
				            break;
				    }
	            }
            },
		    videoComplete: _private.videoComplete,
		    playlistComplete: _private.playlistComplete	
        }
    }
    BET.VideoPlayerCoAdControl = function(config){
        if(config == null){
            return;
        }
        var _private = {
            index: config.index,
            id: config.id,
            coAdDivID: config.coAdDivID,
            div: null
        }
        return {
            writeHtml: function(){
                if(_private.coAdDivID == null){
                    _private.coAdDivID = '_coAdDiv_' + _private.id;
                    document.write('<div id="' + _private.coAdDivID + '" class="coAdDiv"></div>');
                }            
	            _private.div = document.getElementById(_private.coAdDivID);
            },
            getCoAdDiv: function(){
                if(_private.div == null){
                    _private.div = document.getElementById(_private.coAdDivID);
                }
                return _private.div;
            },
            showCoAd: function(adUrl, clickUrl){
                var coAdDiv = this.getCoAdDiv();
                if(coAdDiv == null){   // coAd div not yet ready
                    var me = this;
                    setTimeout(function(){
                        me.showCoAd(adUrl, clickUrl);
                    }, 200);
                }else{
                    if(adUrl.indexOf('http:') != 0){
                        if(adUrl.substr(0, 1) != '/'){ adUrl = '/' + adUrl; }
                        adUrl = 'http://www.bet.com' + adUrl;
                    }          
                    _private.div = document.getElementById(_private.coAdDivID);
                    if(_private.div == null){ return; }
                    var html = '<a href="' + clickUrl + '"><img src="' + adUrl + '" /></a>';
                    _private.div.innerHTML = html;
                }
            }
        }
    }

    // create singleton
    if(!window.VPC){window.VPC = new BET.VideoPageControl({});}

    // flash calls this method when playing an ad
    window.handleCoAd = function(playerIndex, adUrl, clickUrl){
	    VPC.handleCoAd(playerIndex, adUrl, clickUrl);
    }
    window.onAdComplete = function(playerIndex){
	    VPC.onAdComplete(playerIndex);
    }
    window.onVideoComplete = function(playerIndex){
	    VPC.onVideoComplete(playerIndex);
    }
    window.onPlaylistComplete = function(playerIndex){
	    VPC.onPlaylistComplete(playerIndex);
    }
    window.getDartSubString = function(subID){
	    var size = subID.length;
	    var i = subID.lastIndexOf('/');	
	    var dot = subID.lastIndexOf('.');
	    if(size == i+1){
		    dot = i;
		    i = subID.lastIndex('/', dot-1);
	    }	
	    if (i == -1){
		    subID = 'default';
	    }else if (dot>i && i+1!=size){
		    subID = subID.substr(i+1, dot-(i+1));
	    }else{
		    subID = subID.substr(i+1);
	    }
	    return subID;	
    }
    window.formDartString = function(playerID, indexID){
	    var subID = location.pathname;
	    subID = getDartSubString(subID);
	    var dartsubstr = ';c=' + subID + ';plid=' + playerID + ';ind=' + indexID;
	    return dartsubstr;
    }
}


/* MTVN Player API Stuff */
function mtvnPlayerLoaded(playerID){

    var player = document.getElementById(playerID);
    if(player){
        // get the player index from the playerID
        var tokens = playerID.split("_");
        var playerIndex = parseInt(tokens[tokens.length - 1], 10);
        
        if(playerIndex != null && playerIndex >= 0){
            player.addEventListener('NO_AD', 'setNoCoAd');
            player.addEventListener('AD_PACKAGE_LOADED', 'reloadCoAd');
            player.addEventListener('MEDIA_ENDED', 'mtvnOnMediaEnded_' + playerIndex);

            //player.addEventListener('MEDIA_ENDED', 'mtvnOnMediaEnded_' + playerIndex);   
            //        player.addEventListener('STATE_CHANGE', 'mtvnOnStateChange');
            player.addEventListener('PLAYLIST_COMPLETE','mtvnOnPlaylistComplete_' + playerIndex); 
        }
 
   }
}
function mtvnSetCoad(adObject){
    return; 
}
function resetCoAd()
{
    if(window.PC){
    // alert("CoAd reset");
     PC.coAd = true;
    }
}
function setNoCoAd()
{

    if(window.PC){
        if(PC.coAd){
             PC.reloadCoAd(300, 250, 3);
        }
    }
}
function reloadCoAd()
{	
    if(window.PC){
        if(PC.coAd)
        {
            PC.reloadCoAd(300, 250, 3);
        }
    }
}
// pass thru event handlers.  need multiple because mtv player does not pass the playerID.
function mtvnOnMediaEnded_0(){ onVideoComplete(0); }
function mtvnOnMediaEnded_1(){ onVideoComplete(1); }
function mtvnOnMediaEnded_2(){ onVideoComplete(2); }
function mtvnOnMediaEnded_3(){ onVideoComplete(3); }
function mtvnOnMediaEnded_4(){ onVideoComplete(4); }

function mtvnOnPlaylistComplete_0(){ onPlaylistComplete(0); }

//function mtvnOnStateChange(state){
//    alert(state);
//}
function resizePlayer(w,h){
    var videoPlayer;
    if(navigator.appName.indexOf("Microsoft") != -1)
    {
        videoPlayer = window[playerID];
    }           
    else
    {
        videoPlayer = document[playerID];
    }
    videoPlayer.style.width = w + 'px';     
    videoPlayer.style.height = h + 'px';
}

/* end MTVN stuff */

/* BrightCove */

if(window.BrightCove == null){

    window.BrightCove = true;
    
    
    // #############################################
    // function returns the query string part of url
    // everything followed by the '?'
    function getQueryString() {
        var urlStr = document.location.href;
        var i = urlStr.indexOf("?");
        if (i != -1) {
            return urlStr.substring(i, urlStr.length - 1);
        }
        return null;
    }
     
     
    // #############################################
    // function parses the query string and returns each
    // parameter and value seperated by '&'
    function getParameter(name, defaultValue) {
        if (defaultValue == null) {
            defaultValue = "";
        }
     
        var url = document.location.href;
        var i = url.indexOf(name + "=");
        if (i != -1) {
            var valuestart = i+name.length+1;
            var valueend = url.length;
     
            i = url.indexOf("&", valuestart)
            if (i != -1) {
                valueend = i;
            }
     
            return unescape(url.substring(valuestart, valueend));
        }
        return defaultValue;
    }
    
    // Visual basic helper required to detect Flash Player ActiveX control version information
    if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	    document.write('<script language=\"VBScript\"\>\n');
	    document.write('Function VBGetSwfVer(i)\n');
	    document.write('  on error resume next\n');
	    document.write('  Dim swControl, swVersion\n');
	    document.write('  swVersion = 0  \n');
	    document.write('  set swControl = CreateObject("ShockwaveFlash.ShockwaveFlash." + CStr(i))\n');
	    document.write('  if (IsObject(swControl)) then\n');
	    document.write('    swVersion = swControl.GetVariable("$version")\n');
	    document.write('  end if\n');
	    document.write('  VBGetSwfVer = swVersion\n');
	    document.write('End Function\n');
	    document.write('</script\>\n');
    }
    // Hook for Internet Explorer.
    if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	    document.write('<script language=\"VBScript\"\>\n');
	    document.write('On Error Resume Next\n');
	    document.write('Sub flashObj_FSCommand(ByVal command, ByVal args)\n');
	    document.write('	Call onFSCommand(command, args)\n');
	    document.write('End Sub\n');
	    document.write('</script\>\n');
    }
    /*
    var chunks = {}
    function chunkCall(id, total, index, chunk) {
      if (chunks[id] == undefined) chunks[id] = [];
      chunks[id][index] = chunk;
      if (index == total) {
        eval(chunks[id].join(""));
        delete chunks[id];
      }
    }
    */
    //Flash Detection
    var isIE  = (navigator.appVersion.indexOf("MSIE") != -1 && /opera/i.test(navigator.userAgent) == false) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
    // JavaScript helper required to detect Flash Player PlugIn version information
    function jsGetSwfVer(i){
	    if (navigator.plugins != null && navigator.plugins.length > 0) {
		    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			    var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		    var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			    descArray = flashDescription.split(" ");
			    tempArrayMajor = descArray[2].split(".");
			    versionMajor = tempArrayMajor[0];
			    versionMinor = tempArrayMajor[1];
			    if ( descArray[3] != "" ) {
				    tempArrayMinor = descArray[3].split("r");
			    } else {
				    tempArrayMinor = descArray[4].split("r");
			    }
      		    versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
                flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	    } else {
			    flashVer = -1;
		    }
	    }
	    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	    else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	    else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	    else {		
		    flashVer = -1;
	    }
	    return flashVer;
    } 
    // If called with no parameters this function returns a floating point value 
    // which should be the version of the Flash Player or 0.0 
    // ex: Flash Player 7r14 returns 7.14
    // If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
    function detectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
    {
 	    reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	    for (i=25;i>0;i--) {
		    if (isIE && isWin && !isOpera) {
			    versionStr = VBGetSwfVer(i);
		    } else {
			    versionStr = jsGetSwfVer(i);		
		    }
		    if (versionStr == -1 ) { 
			    return false;
		    } else if (versionStr != 0) {
			    if(isIE && isWin && !isOpera) {
				    tempArray         = versionStr.split(" ");
				    tempString        = tempArray[1];
				    versionArray      = tempString .split(",");				
			    } else {
				    versionArray      = versionStr.split(".");
			    }
			    versionMajor      = versionArray[0];
			    versionMinor      = versionArray[1];
			    versionRevision   = versionArray[2];
    			
			    versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			    versionNum        = parseFloat(versionString);
    		    if ( versionMajor > reqMajorVer ) {
				    return true;
			    } else {
				    return ((versionMajor == reqMajorVer && versionMinor >= reqMinorVer) ? true : false );	
			    }
		    }
	    }	
	    return (reqVer ? false : 0.0);
    }
    
    

    var playerIndex;
    var flashId;
    function createExperience(config, flashVersion) {
        var result = getExperienceHtml(config, flashVersion);
        document.write(result.html);
        return result.flashId;
    };
    function getExperienceHtml(config, flashVersion) {
       // default version to 7 for backwards compatability
       if (flashVersion == undefined) var flashVersion = 7;
       // Config parameters to pass into the SWF file.
       var servicesURL = "http://services.brightcove.com/services";
       var viewerSecureGatewayURL = "https://console.brightcove.com/services/amfgateway";
       var cdnURL = "http://admin.brightcove.com";   
       var bgcolor = config["preloadBackColor"];
       var externalAds = (typeof(playAd) != "undefined");
       var sendReports = (typeof(reportEvent) != "undefined");
       
       var width = config["width"];
       var height = config["height"];
       if (width == null) {
            width = "100%";    
       }
       if (height == null) {
            height = "100%";    
       }
      //specify version required Flash version
      if (config["requireFlash8"] || flashVersion == 8){
            requiredMajorVersion = 8;
      } else{
	        //mac requires flash 8
	        requiredMajorVersion = 7;
	        var isMac = navigator.appVersion.toLowerCase().indexOf("mac") > 0;
	        if (isMac) requiredMajorVersion = 8;
      }
      var requiredMinorVersion = 0;
      var requiredRevision = 0;
      var hasRightVersion = detectFlashVer(requiredMajorVersion,requiredMinorVersion,requiredRevision);
          
      if(hasRightVersion) {     
	    var pid = getParameter("bcpid");
	    if(pid.length < 1  || (pid == config["playerId"]))  {
		    var titleParam = getParameter("bctid");
		    if (titleParam.length > 0) {
		      config["videoId"] = titleParam;
		      config["autoStart"] = true;
		      config["fromLink"] = true;
		    }
		    var lineupParam = getParameter("bclid");
		    if (lineupParam.length > 0) {
		      config["lineupId"] = lineupParam;
		    }
	    }
      
        if (playerIndex == undefined){
		    playerIndex = 0;
	    }else{
		    playerIndex++;
	    }	
     
        if (config["flashId"] == undefined) {
          flashId = "flashObj" + playerIndex;
        } else {
          flashId = escapeValue(config["flashId"]) + playerIndex;
        }
     
        var configItems = "";
        for (var i in config) {
           if (i == "flashId") continue;
           if (typeof(config[i]) == "function" || typeof(config[i]) == "object") continue;
           
           configItems += "&" + i + "=" + escapeValue(config[i]);
        }
        
        var html = '';
        // Hook for Internet Explorer.
        if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	    html += '<script language=\"VBScript\"\>\n';
	    html += 'On Error Resume Next\n';
	    html += 'Sub ' + flashId + '_FSCommand(ByVal command, ByVal args)\n';
	    html += '	Call onFSCommand(command, args)\n';
	    html += 'End Sub\n';
	    html += '</script\>\n';
        }
     
        var swfFile = "federated.swf";
        if (flashVersion == 8) {
          swfFile = "federated_f8.swf";
        }
     
        var file = cdnURL + "/viewer/" + swfFile + "?flashId="+flashId+
             "&servicesURL="+escapeValue(servicesURL)+
             "&viewerSecureGatewayURL="+escapeValue(viewerSecureGatewayURL)+
             "&cdnURL="+escapeValue(cdnURL)+
             configItems+
             "&externalAds="+escapeValue(externalAds)+
             "&sendReports="+escapeValue(sendReports)+
             "&buildNumber=" + 680 +
             "&ranNum=" + Math.floor(Math.random()*1000000);   
     
        if (!detectFlashVer(8,0,0)) {
          file += "&domain=" + getDomain();
        }
        
        wmode = config["wmode"];
	    if (wmode == null) wmode = "window";  	
        version = "7,0,0,0"; // why write 7 always??
        quality = "high";
        html += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=" + version + "\" id=\""+flashId+"\" width=\""+width+"\" height=\""+height+"\">";
        html += "  <param name=\"allowScriptAccess\" value=\"always\"/>";
        html += "  <param name=\"allowFullScreen\" value=\"true\"/>";
        html += "  <param name=\"movie\" value=\""+file+"\"/>";
        html += "  <param name=\"wmode\" value=\""+wmode+"\"/>";
        html += "  <param name=\"quality\" value=\""+quality+"\"/>";
        html += "  <param name=\"bgcolor\" value=\"" + bgcolor + "\"/>";
        html += "  <param name=\"base\" value=\""+cdnURL+"/viewer/\"/>";
        html += "  <param name=\"SeamlessTabbing\" value=\"false\"/>";
        html += "  <embed src=\""+file+"\" base=\""+cdnURL+"/viewer/\" quality=\""+quality+"\" bgcolor=\""+bgcolor+"\" allowScriptAccess=\"always\" name=\""+flashId+"\" width=\""+width+"\" height=\""+height+"\" wmode=\""+wmode+"\" seamlesstabbing=\"false\" type=\"application/x-shockwave-flash\" swLiveConnect=\"true\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></embed>";
        html += "</object>"; 
        
      } else {  // flash is too old or we can't detect the plugin  
        html += "<table width='" + width + "' height='" + height + "' border='0' bgcolor='"+bgcolor+"'>";
        html += "<tr><td align='center' valign='middle'>";
        html += "<a href='http://www.adobe.com/go/getflash/' target='_blank'><img src='"+cdnURL+"/viewer/upgrade_flash_player.gif' alt='Get Flash Player' width='314' height='200' border='0'></a>";
        html += "</td></tr></table>";      
       }
     
       return { flashId: flashId, html: html };
    }
     
    function escapeValue(str) {
      return encodeURIComponent(str);
    }
     
    function getDomain() {
      var domain = window.location.href;
      if (domain.substring(0, 7) == "http://") {
        domain = domain.substring(7, domain.length);
      }
      var i = domain.indexOf("/");
      if (i != -1) {
        domain = domain.substring(0, i);
      }
      i = domain.indexOf(":");
      if (i != -1) {
        domain = domain.substring(0, i);
      }
      return domain;
    }
    var ID_DELIM = "|||";
     
    function onFSCommand(command, args) {
      if (command == "eval"){
        eval(args);
        return;
      }
      if (this[command] == null) return;
      var obj = convertToObject(unescape(args));
      if (obj != null) {
        var callback = obj.callback;
        var flashId = obj.flashId;
        if (obj.flashId != null && callback != null) {
          callback = obj.flashId + ID_DELIM + callback;
        }
        if (obj.args == null) {
          eval(command + "(callback);");
        } else {
          eval(command + "(obj.args, callback);");
        }
      } else {
        eval(command + "();");
      }
    }
     
    var flashCallback;
    var flashCallbacks = [];
    function setAPICallback(id, callback) {
      flashCallback = callback;
      flashCallbacks[id] = callback;
    }
     
    function callFlash() {
      var method = arguments[0];
      var params = [];
      for (var i = 1; i < arguments.length; i++) {
        params.push(arguments[i]);
      }
      callbackFlash(flashCallback, {method:method, params:params});
    }
     
    function callFlashInstance() {
      var flashId = arguments[0];
      var method = arguments[1];
      var params = [];
      for (var i = 2; i < arguments.length; i++) {
        params.push(arguments[i]);
      }
      var callback = flashCallbacks[flashId];
      callbackFlash(callback, {method:method, params:params});
    }
     
    function callbackFlash(callback, returnValue) {
      var flashId = "flashObj";
     
      var arry = callback.split(ID_DELIM);
      
      if (arry.length > 1) {
        if (arry[0].length > 0) {
          flashId = arry[0];
        }
        callback = arry[1];
      }
     
      var fo = document[flashId];
      if (fo == null) fo = document.embeds[flashId];
      if (fo == null) fo = document.getElementById(flashId);
     
      if (fo[callback] != null) {
        return fo[callback](convertToXML(returnValue, "js2flash"));
      } else {
        try {
          fo.SetVariable(callback, convertToXML(returnValue, "js2flash"));
        } catch (e) {}
      }
    }
     
     
    function convertToXML(obj, rootName) {
	    if (obj instanceof Function) return "";
  	    var type = getType(obj);
  	    var xml = "<"+type.name+rootName+">";
      
	    if(type.sub) {
  		    for (var i in obj) {
 		      xml += convertToXML(obj[i], i);
    	    }
	    }
	    else if (type.name == "str") {
		    obj = replaceEntities(obj);
		    xml += obj;
	    } 
	    else {
		      xml += obj;
	    }
	    xml += "</"+type.name+rootName+">";
	    return xml;
    }
     
    function replaceEntities(obj) {
	    obj = obj.replace("&", "&amp;");
	    obj = obj.replace("<", "&lt;");
	    obj = obj.replace(">", "&gt;");	
	    return obj;
    }
     
    var s_xml_types = new Array();	
    s_xml_types.push({name:"str",type:String,sub:false});
    s_xml_types.push({name:"boo",type:Boolean,sub:false});
    s_xml_types.push({name:"num", type:Number,sub:false});
    //s_xml_types.push({name:"date", type:Date,sub:false});
    s_xml_types.push({name:"arr", type:Array,sub:true});
    //s_xml_types.push({name:"cda", type:CData, sub:false});
    s_xml_types.push({name:"obj", type:Object,sub:true});
     
    function getType(obj) {
            switch (typeof(obj)) {
		    case "boolean":
			    return {name:"boo",type:Boolean,sub:false};
		    case "string":
			    return {name:"str",type:String,sub:false};
		    case "number":
			    return {name:"num",type:Number,sub:false};
	    }
	    for (var i = 0; i < s_xml_types.length; i++) {
	      if (obj instanceof s_xml_types[i].type) {
	        return s_xml_types[i];
	      }
	    }
	    return {name:"obj", type:Object,sub:true};
    }
    function getTypeClass(name) {
      if (name == null) return null;
     
      name = name.toLowerCase();
	    for (var i = 0; i < s_xml_types.length; i++) {
	      if (name == s_xml_types[i].name) {
	        return s_xml_types[i].type;
	      }
	    }
	    return null;
    }
     
    function convertToObject(node) {
    //  try {
        if (node == null) {
          return;
        }
        
        if (node.substring != null) {
          node = parseXML(node);
        }
    	  
	      if (node == null || node.childNodes == null || node.childNodes.length == 0) {
	        return null;
	      }
     
	      var type = getTypeClass(node.nodeName.substring(0,3));
	      if (type == null) {
	        type = Object;
	      }
     
		    if (node.firstChild.nodeType == 3 || node.firstChild.nodeType == 4) {
			    return getObjectForNode(type, node);
     
		    } else {
    		
  		    var obj = new type();
	  	    var children = node.childNodes;
		      for (var i = 0; i < children.length; i++) {
		        var name = children[i].nodeName;
		        name = name.substring(3, name.length);
			      obj[name] = convertToObject(children[i]);
	  	    }
		      return obj;
		    }
    //	} catch (e) {
    //    alert("Error creating object:" + e.message);
    //	  return null;
    //	}
    }
     
    function getObjectForNode(type, node) {
	    if (type == Boolean) {
		    if (node.firstChild.nodeValue == "true") {
			    return new Boolean(1);
		    }
		    else {
			    return new Boolean(0);
		    }
	    }
	    else {
		    return new type(node.firstChild.nodeValue);
	    }
    }
     
    function parseXML(str) {
      if (window.ActiveXObject) {
        var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
        try {
          xmldoc.setProperty("SelectionLanguage", "XPath");
        } catch (e) {} // i.e. 5 doesn't like setting the selection language
        xmldoc.async = false;
     
        xmldoc.loadXML(str);
        return xmldoc.documentElement;  
      } else if (DOMParser) {
     
        var parser = new DOMParser();
        var doc = parser.parseFromString(str, "text/xml");
        
        return doc.firstChild;
        
      } else {
        return makeXMLNode(str);
      }
    }
     
     
    function makeXMLNode(str) {
      var node = {};
      var nodeName = node.nodeName = getNodeName(str);
      node.nodeType = 1;
      node.childNodes = [];
      node.firstChild = null;
      var startTagEndIndex = nodeName.length + 2;
      var endTagIndex = str.lastIndexOf("</" + nodeName);
      var nodeData = str.substring(startTagEndIndex, endTagIndex);
      if (nodeData.substring(0, 9) == "<![CDATA[") {
        var child = {};
        child.nodeName = null;
        child.nodeType = 4;
        child.nodeValue = getCDATA(nodeName, str.substring(startTagEndIndex, str.length));
        node.childNodes = [child];
      } else if (nodeData.indexOf("<") > -1) {
        node.childNodes = getChildNodes(nodeData);
      } else if (nodeData.length == 0) {
        //do nothing, we want 0 children here
      } else {
        var child = {};
        child.nodeName = null;
        child.nodeType = 3;
        child.nodeValue = getNodeValue(nodeName, nodeData);
        node.childNodes = [child];
      }
      if (node.childNodes.length > 0) {
        node.firstChild = node.childNodes[0];
      }
      return node;
    }
     
    function getNodeName(str) {
      return str.substring(str.indexOf("<")+1, str.indexOf(">"));
    }
     
    function getChildNodes(nodeData) {
      var childNodes = [];
      var nodeName;
      var nextIndex;
      var endIndex;
      var dataLength;
      var nameLength;
      var startNodesArray;
      var endNodesArray;
      var startNodesLength;
      var endNodesLength;
      var endNodes;
      var startNodes;
      var endNode;
      var i;
      var j;
      while (nodeData.length > 0) {
        nodeName = getNodeName(nodeData);
        nameLength = nodeName.length;
        nextIndex = nodeData.indexOf("<"+nodeName, nameLength);
        endIndex = nodeData.indexOf("</"+nodeName, nameLength);
        if (endIndex < 0) return childNodes;
        if (nextIndex < 0 || endIndex < nextIndex) {
          dataLength = endIndex+nodeName.length+3;
          childData = nodeData.substr(0, dataLength);
          nodeData = nodeData.substr(dataLength);
          childNodes.push(makeXMLNode(childData));
        } else {
          endNodes = 0;
          startNodes = 0;
          startNodesArray = nodeData.split("<" + nodeName + ">");
          startNodesLength = startNodesArray.length;
          endNode = "</" + nodeName + ">";
          for (i = 0; i < startNodesLength; i++) {
            startNodes++;
            startNodesStr = startNodesArray[i];
            if (startNodesStr.indexOf(endNode) > -1) {
              endNodesArray = startNodesStr.split("</" + nodeName + ">");
              endNodesLength = endNodesArray.length;
              for (j = 0; j < endNodesLength; j++) {
                if (++endNodes == startNodes) {
                  childData = startNodesArray.slice(0, startNodes).join("");
                  dataLength = childData.length;
                  nodeData = nodeData.substr(dataLength);
                  childNodes.push(makeXMLNode(childData));
                  return childNodes;
                }
              }
            }
          }
          childNodes.push(makeXMLNode(nodeData));
          nodeData = "";
        }
      }
      return childNodes;
    }
     
    function getCDATA(nodeName, nodeData) {
      var endCDATA = nodeData.indexOf("]]>", 9);
      if (endCDATA < 0) {
        return null;
      } else {
        return getNodeValue(nodeName, nodeData.substring(9, endCDATA));
      }
    }
     
    function getNodeValue(nodeName, nodeValue) {
      switch (nodeName.substr(0, 3)) {
        case "boo":
          return (nodeValue=="true");
        case "num":
          return Number(nodeValue);
        case "str":
          return String(nodeValue);
        default:
          return nodeValue;
      }
    }
     
    function CData(str) {
      this.data = str;
    }
     
    CData.prototype.toString = function() {
      return "<![CDATA[" + this.data + "]]>";
    }

}
/* end BrightCove */