function inheritAll() {
	for (var i = 1; i < arguments.length; i++) {
		for (x in arguments[i].prototype) {
			arguments[0].prototype[x] = arguments[i].prototype[x];
		}
	}
}

function XMPPlaylistManager() {
	if (XMPPlaylistManager.caller != XMPPlaylistManager.getInstance) {
		if((navigator.userAgent.indexOf('Safari')==-1) && (navigator.userAgent.indexOf('Opera')==-1)) {
			throw new Error("There is no public constructor for XMPPlaylistManager.");
		}
	}
	this.jsonurls = null;
	this.noCookies = false;
	this.forceSensitive = false;
	this.dataObject = null;
	this.cnnIsIntl = (location.hostname.indexOf('edition.') > -1) ? true : false; 
	this.playerName = null;
	this.playlists = new Array();
	this.activePlaylist = null;
	this.playlistType = '';
	this.vidString = 'BVP';
	this.vidContext = 'BVP';
	this.slateSize = '464x240';
	this.onlyCallMeOnce = false;
	this.isVideoError = false;
	this.errorObject = null;
	this.playlist = function(jsonList,pointer) {
		this.jsonList = jsonList;
		this.pointer = pointer;
		this.playlistJsonObjs = null;
		this.activeJson = function() { return this.jsonList[this.pointer]; }
	}
	this.advanceTo = function(playlistName,val) {
		if (this.noCookies == false) {
			if (this.splashActive) {
				this.splashActive = false;
				document.getElementById('cnnVPFlashLargeContainer').style.backgroundImage = '';
				document.getElementById('cnnVPFlashLargeContainer').innerHTML = '';
			}
			if (this.activePlaylist != playlistName) {
				this.activePlaylist = playlistName;
				this.playlists[this.activePlaylist].pointer = val;
				if (this.onlyCallMeOnce == false) {
					this.onlyCallMeOnce = true;
					XMPPlayer.getActivePlayer().setPlayerContext(this.vidContext);
					XMPPlayer.getActivePlayer().createPlayListContext(this.vidString);
				}
				XMPPlayer.getInstance('','advanceTo1').loadContent(this.playlists[this.activePlaylist].jsonList,this.playlists[this.activePlaylist].activeJson());
			} else {
				this.playlists[this.activePlaylist].pointer = val;
				XMPPlayer.getInstance('','advanceTo2').setCurrentPlayListPosition(this.playlists[this.activePlaylist].activeJson());			
			}
		}
	}
	this.advance = function() {
		this.playlists[this.activePlaylist].pointer = 0;
		XMPPlayer.getInstance('','advanceTo1').loadContent(this.playlists[this.activePlaylist].jsonList,this.playlists[this.activePlaylist].activeJson());
	}
	this.setPlaylist = function(playlistName,callBackFunc) {
		pt = this.playlists[playlistName];
		this.getPlayer().serializerFactory = xmp.baseplayer.MetaFileLoaderFactory.getInstance().create('videoContentMeta');
		pt.playlistJsonObjs = this.getPlayer().serializerFactory.setIds(pt.jsonList, (new xmp.util.Callback('contentItemCB', XMPPlayer.playlistContentItemCB, null)));	
		this.getPlayer().serializerFactory.setAllLoadedCallback(new xmp.util.Callback('allContentItemsCB', callBackFunc, null));
		this.getPlayer().serializerFactory.load();
	}
	this.getPlayer = function() {
		return XMPPlayer.getInstance('','getPlayer');
	}
	this.emailVideo = function() {
		this.emailThis(this.dataObject);
	}
	this.emailThis = function(obj) {
		clickTitle = this.dataObject.headline;
		clickURL = ((window.location.href.split("/"))[2])+'/video/?/'+this.dataObject.id.slice(1,this.dataObject.id.length);
		commonLoc="&fb=Y&url="+escape(getClickURL())+"&title="+escape(getClickTitle())+"&random="+Math.random()+"&partnerID="+partnerID+"&expire="+escape(getClickExpire());
		ET();
	}
}

XMPPlaylistManager.__instance__ = null; 

XMPPlaylistManager.getInstance = function (playerName) {
	if (this.__instance__ == null) {
		inheritAll(XMPPlaylistManager,SAPlaylistManager);
		this.__instance__ = new XMPPlaylistManager();
		this.__instance__.playerName = playerName;
		currentPlayer = playerName;
	}
	return this.__instance__;
}
XMPPlaylistManager.isBootStrapped = null;
XMPPlaylistManager.endOfVideoContent = function() {
	ppp = XMPPlaylistManager.getInstance().playlists[XMPPlaylistManager.getInstance().activePlaylist];
	if (ppp.playlistJsonObjs.length - 1 != ppp.pointer) {
		ppp.pointer++;
		XMPPlaylistManager.getInstance().runNextUpSlate = true;
	}
	XMPPlayer.getInstance('','endOfVideoContent').advance();
}
XMPPlaylistManager.findImageSize = function(imageSizeArray, id) {
	for (var i = 0; i < imageSizeArray.length; i++) {
		if (imageSizeArray[i].id == id) {
			return imageSizeArray[i].resource;
		}
	}
	return "/.element/img/2.0/global/"+id+".no.photo.gif";
	//return ("http://i.cdn.turner.com/cnn/.element/img/2.0/global/misc/"+id+".no.photo.gif");
}

function SAPlaylistManager() {}
SAPlaylistManager.prototype.SAConfiguration = null;
SAPlaylistManager.prototype.SALoadVideo = function(configuration) {
//	if (this.flashDetection()) {
		this.SAConfiguration = configuration;
		this.jsonurls = this.SAConfiguration.videoArray;
		this.vidContext = this.SAConfiguration.vidContext;
		this.vidString = this.SAConfiguration.vidString;
		this.slateSize = this.SAConfiguration.slateSize[0]+"x"+this.SAConfiguration.slateSize[1];
		XMPPlaylistManager.isBootStrapped = SAIsBootStrapped;
		XMPPlayer.create();
//	} else {
//		setTimeout("XMPPlaylistManager.getInstance().SANoFlashTimer()",1000);		
//	}
}
SAPlaylistManager.prototype.SABootStrapCallback = function(success) {
	if (success) {
		this.playlists['saplaylist'] = new this.playlist(this.jsonurls,this.SAConfiguration.startPoint);
		this.setPlaylist('saplaylist',SAPlaylistUICallback);
	} else {
		this.SAConfiguration.bootErrorHandler(this.errorObject);
	}
}
SAPlaylistManager.prototype.SAWriteSplash = function() {
	this.playlistType = 'sa';
	this.playStartSlate = true;
	this.dataObject = this.playlists['saplaylist'].playlistJsonObjs[this.SAConfiguration.startPoint].getDataObject();
	this.SAConfiguration.initHandler();
	XMPPlaylistManager.getInstance().advanceTo('saplaylist',this.SAConfiguration.startPoint);
}
SAPlaylistManager.prototype.SANoFlashTimer = function() {
	this.SAConfiguration.bootErrorHandler('No Flash');
}

SAPlaylistUICallback = function() { XMPPlaylistManager.getInstance().SAWriteSplash()}

SAIsBootStrapped = function(success) {
	XMPPlaylistManager.getInstance().SABootStrapCallback(success);
}

function flipBVPImage(imgName,srcName,onOff,ad) {
	if (ieVersion() == 0 || ieVersion() >= 7) {
		document.images[imgName+'Img'].src = 'http://i.cdn.turner.com/cnn/video/bvp/images/'+srcName+'_'+onOff+'.png';
	}
	else {
		if (ad == null) ad = '';
		document.getElementById(imgName+'_button'+ad).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://i.cdn.turner.com/cnn/video/bvp/images/"+srcName+"_"+onOff+".png')";
	}
}

function makeOn() { flipBVPImage('play','play','on'); }
function makeOff() { flipBVPImage('play','play','off'); }
function emailOn() { flipBVPImage('email','email','on'); }
function emailOff() { flipBVPImage('email','email','off'); }
function moveOn1() { flipBVPImage('replay','rply','on'); }
function moveOut1() { flipBVPImage('replay','rply','off'); }

function ieVersion() {
	var ua = window.navigator.userAgent;
  var msie = ua.indexOf ( "MSIE " );
  if ( msie > 0 )      // If Internet Explorer, return version number
  	return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
  else                 // If another browser, return 0
    return 0;
}


/* ****************************************************************
   Begin Adobe Client Side Flash Detection Script
   ****************************************************************
 */
 
// Flash Player Version Detection - Rev 1.6
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

XMPPlaylistManager.prototype.ADOBEControlVersion = function() {
	var version;
	var axo;
	var e;
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) { }
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			version = "WIN 6,0,21,0";
			axo.AllowScriptAccess = "always";
			version = axo.GetVariable("$version");
		} catch (e) { }
	}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) { }
	}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) { }
	}
	if (!version) {
		try {
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) { version = -1; }
	}
	return version;
}

XMPPlaylistManager.prototype.ADOBEGetSwfVer = function() {
	var flashVer = -1;
	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;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	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 if ( isIE && isWin && !isOpera ) {
		flashVer = this.ADOBEControlVersion();
	}	
	return flashVer;
}

XMPPlaylistManager.prototype.ADOBEDetectFlashVer = function(reqMajorVer, reqMinorVer, reqRevision) {
	versionStr = this.ADOBEGetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}