function CoreVideoControls(parentDiv) {
	this.parentDiv = $(parentDiv);
	this.buttons = new Array();
	this.scrubbers = new Array();
	this.clocks = new Array();
	this.amScrubbing = false;
	this.duration = null;
	this.initList = new Array();
	this.endSlateActive = false;
}

CoreVideoControls.prototype.initialize = function(callbackMethod) {
	for (var i = 0; i < this.initList.length; i++) {
		this.initList[i]();
	}
	callbackMethod();
}

CoreVideoControls.prototype.handleXMPEvent = function(p_method, p_arg) {
	var returnVal;
	switch(p_method) {
		case 'endSlateStarted':
			this.endSlateActive = true;
			this.enableShare();
			this.enableEmbed();
			break;
		case 'newVideo':
			this.hideEmbed();
			this.hideShare();
			break;
		case 'videoStarted':
			this.endSlateActive = false;
			this.enableShare();
			this.enableEmbed();
			this.enableFullscreen();
			break;
		case 'turnOffSharing':
			this.disableShare();
			this.disableEmbed();
			break;
		case 'setEnabled':
			if (p_arg == false) {
				this.disablePause();
				this.disableShare();
				this.disableEmbed();
				this.disableFullscreen();
				this.disableTimelineScrubber();
			}
			if (p_arg == true) {
				this.enablePause();
			}
			break;
		case 'setVolume':
			this.scrubbers['volume'].scrubberPointer.setValue((p_arg/100));
			break;
		case 'setTime':
			this.setTime(p_arg);
			break;
		case 'setDuration':
			this.setDuration(p_arg);
			break;
		case 'togglePlay':
			if (p_arg == true) {
				this.enablePause();
			} else {
				this.enablePlay();
			}
			break;
		case 'setScrubberEnabled':
			if (p_arg == true) {
				this.enableTimelineScrubber();
			} else {
				this.disableTimelineScrubber();
			}
			break;
		case 'setLoadedPercent':
			this.setTimelineScrubberBuffer(p_arg);
			break;
		case 'getVolume':
			returnVal = 100 * this.scrubbers['volume'].scrubberPointer.value;
			break;
	}
	return returnVal;
}

/* 	**********************************************

	End		-	Initialization
	Start 	- 	Play

	********************************************** */

function CoreVideoControls_Play() { }

CoreVideoControls_Play.prototype.swapPlayPause = function(hide,show) {
	$(hide).style.display = 'none';
	$(show).style.display = 'block';
}

CoreVideoControls_Play.prototype.disablePlay = function() {
	if ($('playLayer')) {
		this.swapPlayPause('pauseLayer','playLayer');
		$('playLayer').className = this.buttons['play'].classes['disabled'];
		$('playLayer').onclick = function() { }
	}
}

CoreVideoControls_Play.prototype.enablePlay = function(useSpecialHandler) {
	if ($('playLayer')) {
		this.swapPlayPause('pauseLayer','playLayer');
		$('playLayer').className = this.buttons['play'].classes['activeOff'];
		if(useSpecialHandler) {
			$('playLayer').onclick = CNNPlaylistManager.beginPlayback;
		}
		else {
			$('playLayer').onclick = this.buttons['play'].clickEvent;
		}		
	}
}

CoreVideoControls_Play.init = function() {
	// place the play button
	var divObj = document.createElement('div');
	divObj.setAttribute('id','playLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['play'].classes['disabled'];
	divObj.style.display = 'none';
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
}

CoreVideoControls_Play.clickEvent = function() {
	CNNPlaylistManager.getInstance().controller.hideShare();
	CNNPlaylistManager.getInstance().controller.hideEmbed();
	CNNPlayer.getActivePlayer().handleEvent('playPressed');
}

/* 	**********************************************

	End		-	Play
	Start 	- 	Pause

	********************************************** */

function CoreVideoControls_Pause() { }

CoreVideoControls_Pause.prototype.disablePause = function() {
	if ($('pauseLayer')) {
	this.swapPlayPause('playLayer','pauseLayer');
	$('pauseLayer').className = this.buttons['pause'].classes['disabled'];
	$('pauseLayer').onclick = function() { }
	}
}

CoreVideoControls_Pause.prototype.enablePause = function() {
	if ($('pauseLayer')) {
		this.swapPlayPause('playLayer','pauseLayer');
		$('pauseLayer').className = this.buttons['pause'].classes['activeOff'];
		$('pauseLayer').onclick = this.buttons['pause'].clickEvent;
	}
}

CoreVideoControls_Pause.init = function() {
	// place the pause disabled button
	var divObj = document.createElement('div');
	divObj.setAttribute('id','pauseLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['pause'].classes['activeOff'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
}

CoreVideoControls_Pause.clickEvent = function() {
	CNNPlayer.getActivePlayer().handleEvent('pausePressed');
}

/* 	**********************************************

	End		-	Play/Pause
	Start 	- 	Embed

	********************************************** */

function CoreVideoControls_Embed() { }

CoreVideoControls_Embed.prototype.disableEmbed = function() {
	if ($('embedLayer')) {
		this.hideEmbed();
		$('embedLayer').className = this.buttons['embed'].classes['disabled'];
		$('embedLayer').onclick = function() { }
	}
}

CoreVideoControls_Embed.prototype.enableEmbed = function() {
	if ($('embedLayer')) {
		$('embedLayer').className = this.buttons['embed'].classes['activeOff'];
		$('embedLayer').onclick = this.buttons['embed'].clickEvent;
	}
}

CoreVideoControls_Embed.prototype.showEmbed = function() {
	if ($('embedLayer')) {
		if (this.endSlateActive == false) {
			CNNPlayer.getActivePlayer().handleEvent('pausePressed');
		}
		var p = CNNPlaylistManager.getInstance();
		var tracking = 'dom';
		if (location.hostname.indexOf('edition.') > -1) {
			tracking = 'int';
		}
		$('embedForm').value = '<script src="http://i.cdn.turner.com/cnn/.element/js/2.0/video/evp/module.js?loc=' + tracking + '&vid=' + p.playlists[p.activePlaylist].playlistJsonObjs[p.playlists[p.activePlaylist].pointer].getDataObject().id + '" type="text/javascript"></script><noscript>Embedded video from <a href="http://www.cnn.com/video">CNN Video</a></noscript>';
		$('embedOverlay').style.display = 'block';
	}
}

CoreVideoControls_Embed.prototype.hideEmbed = function(restart) {
	if ($('embedLayer')) {
		$('embedOverlay').style.display = 'none';
		if (this.endSlateActive) {
			//$('endReplay').style.display = 'block';
			//$('endEmbed').style.display = 'block';
			//$('endShare').style.display = 'block';
		} else {
			if (restart) {
				CNNPlayer.getActivePlayer().handleEvent('playPressed');
			}
		}
	}
}

CoreVideoControls_Embed.init = function() {
	var divObj = document.createElement('div');
	divObj.setAttribute('id','embedLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['embed'].classes['disabled'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
	var divObj = document.createElement('div');
	divObj.setAttribute('id','embedOverlay');
	divObj.setAttribute('class', 'embedOverlay');

	//new
	var str = '';
	str += '<div id="embedClose" onclick="CNNPlaylistManager.getInstance().controller.hideEmbed(true);"></div>';
	str += '<div id="embedButton">';
	str += '	<a href="javascript:CNNPlaylistManager.getInstance().controller.copyEmbed()">';
	str += '		<img border="no" src="http://i.cdn.turner.com/cnn/.e/img/2.0/video/controls/copy.png">';
	str += '	</a>';
	str += '</div>';
	str += '<input onfocus="this.select();" id="embedForm">';
	str += '<div id="embedTitle">Embed this video</div>';
	str += '<div id="embedDesc1">Copy and paste this code into your blog/website</div>';
	//str += '<div id="embedDesc2" class="embedDesc2">Or click on the button to copy the code</div>';

	divObj.innerHTML = str;
	if ($('mosVidContainer')) {
		$('mosVidContainer').appendChild(divObj);
	} else {
		$('cnnVPFlashLarge').appendChild(divObj);
	}
}

CoreVideoControls_Embed.clickEvent = function() {
	var c =CNNPlaylistManager.getInstance().controller;
	if ($('embedOverlay').style.display == 'block') {
		CNNPlaylistManager.getInstance().controller.hideEmbed(true);
		$('shareLayerId').className = c.buttons['share'].classes['activeOn'];
	} else {
		CNNPlaylistManager.getInstance().controller.hideShare();
		if (CNNPlaylistManager.getInstance().controller.endSlateActive == true) {
			//$('endReplay').style.display = 'none';
			//$('endEmbed').style.display = 'none';
			//$('endShare').style.display = 'none';
		}
		CNNPlaylistManager.getInstance().controller.showEmbed();
		$('shareLayerId').className = c.buttons['share'].classes['disabled'];
	}
}

/* 	**********************************************

	End		-	Embed
	Start 	- 	Share

	********************************************** */

function CoreVideoControls_Share() { }

CoreVideoControls_Share.prototype.disableShare = function() {
	if ($('shareLayerId')) {
		this.hideShare();
		$('shareLayerId').className = this.buttons['share'].classes['disabled'];
		$('shareLayerId').onclick = function() { }
	}
}

CoreVideoControls_Share.prototype.enableShare = function() {
	if ($('shareLayerId')) {
		$('shareLayerId').className = this.buttons['share'].classes['activeOff'];
		$('shareLayerId').onclick = this.buttons['share'].clickEvent;
	}
}

CoreVideoControls_Share.prototype.showShare = function() {
	if ($('shareLayerId')) {
		if (this.endSlateActive == false) {
			CNNPlayer.getActivePlayer().handleEvent('pausePressed');
		}

		var p = CNNPlaylistManager.getInstance();
		var tracking = 'dom';
		$('embedFormField').value = '<script src="http://i.cdn.turner.com/money/.element/script/3.0/video/evp/module.js?loc=' + tracking + '&vid=' + p.playlists[p.activePlaylist].playlistJsonObjs[p.playlists[p.activePlaylist].pointer].getDataObject().id + '" type="text/javascript"></script><noscript>Embedded video from <a href="http://money.cnn.com/video">CNNMoney Video</a></noscript>';
		$('shareOverlay').style.display = 'block';
		$('embedFormField').focus();

		var dataObj = p.playlists[p.activePlaylist].playlistJsonObjs[p.playlists[p.activePlaylist].pointer].getDataObject();
		//var vidURI = getFullDomain() + dataObj.id;
		var vidURI = 'http://money.cnn.com'+dataObj.id;
		$('emailFormField').value = vidURI;

	}
}

CoreVideoControls_Share.prototype.hideShare = function(restart) {
	if ($('shareLayerId')) {
		$('shareOverlay').style.display = 'none';
		if (this.endSlateActive) {
			//$('endReplay').style.display = 'block';
			//$('endEmbed').style.display = 'block';
			//$('endShare').style.display = 'block';
		} else {
			if (restart) {
				CNNPlayer.getActivePlayer().handleEvent('playPressed');
			}
		}
	}
}

CoreVideoControls_Share.prototype.hideShareButton = function() {
	if ($('shareLayerId'))  {
		$('shareLayerId').hide();
	}
}

CoreVideoControls_Share.prototype.showShareButton = function() {
	if ($('shareLayerId'))  {
		$('shareLayerId').show();
	}
}

CoreVideoControls_Share.prototype.toggleShareSites = function() {
	if($('sharePostSites').style.display == 'none') {
		$('sharePostSites').show();
	}
	else {
		$('sharePostSites').hide();
	}
}

CoreVideoControls_Share.prototype.shareVideo = function(shareType) {
	var p = CNNPlaylistManager.getInstance();
	var dataObj = p.playlists[p.activePlaylist].playlistJsonObjs[p.playlists[p.activePlaylist].pointer].getDataObject();
	var linkUrl = null;
	var vidUrl = encodeURIComponent('http://money.cnn.com/video/?JSONLINK='+dataObj.id);
	var desc = encodeURIComponent(dataObj.description);
	var headline = encodeURIComponent(dataObj.headline);

	//var vidURI = encodeURIComponent(getFullDomain() + dataObj.id);
	var vidURI = vidUrl;
	switch (shareType) {
		case 'twitter':
			linkUrl = 'http://cnntweet.appspot.com/articles/'+vidURI+'/'+headline+'/cnnmoney/';
		break;
		case 'mixx':
			linkUrl = 'http://www.mixx.com/submit/video?page_url='+vidURI+'&title='+headline+'&description='+desc+'&partner=CNN';
			break;
		case 'digg':
			linkUrl = 'http://digg.com/submit?phase=2&url='+vidURI+'&title='+headline+'&bodytext='+desc;
			break;
		case 'facebook':
			linkUrl = 'http://www.facebook.com/sharer.php?u='+vidURI+'&t='+headline;
			break;
		case 'delicious':
			linkUrl = 'http://del.icio.us/post?v=4&partner=cnn&noui&jump=close&url='+vidURI+'&title='+headline;
			break;
		case 'reddit':
			linkUrl = 'http://reddit.com/submit?url='+vidURI+'&title='+headline;
			break;
		case 'stumbleupon':
			linkUrl = 'http://www.stumbleupon.com/submit?url='+vidURI+'&title='+headline;
			break;
		case 'myspace':
			linkUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?t='+headline+'&c='+desc+'&u='+vidURI;
			break;
	}
	if (linkUrl != null) {
		window.open(linkUrl,'videoShareLink');
	}
}

CoreVideoControls_Share.init = function() {
	var divObj = document.createElement('div');
	divObj.setAttribute('id','shareLayerId');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['share'].classes['disabled'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
	var divObj = document.createElement('div');
	divObj.setAttribute('id','shareOverlay');

	var str = '';
	str += '';
	str += '<div id="shareClose" onclick="CNNPlaylistManager.getInstance().controller.hideShare(true);"></div>';
	str += '<div id="shareGroup">';
	str += '	<div id="shareEmailBox">';
	str += '		<div id="shareEmailTitle" onclick="CNNPlaylistManager.getInstance().emailVideo()">EMAIL THIS VIDEO</div>';
	str += '		<div class="shareEmbedDesc">Or copy and paste the URL below</div>';
	str += '		<div id="shareEmailField"><input type="text" id="emailFormField" onfocus="this.select()" value="" /></div>';
	str += '	</div>';
	str += '	<div id="shareEmbedBox">';
	str += '		<div id="shareEmbedTitle">EMBED THIS VIDEO</div>';
	str += '		<div class="shareEmbedDesc">Copy and paste the code below into your blog or website</div>';
	str += '		<div id="shareEmbedField"><input id="embedFormField" onfocus="this.select()" /></div>';
	str += '	</div>';
	str += '	<div id="sharePostBox">';
	str += '		<div id="sharePostTitle">POST THIS VIDEO</div>';
	str += '		<div class="shareEmbedDesc">Choose your social networking site or personal homepage</div>';
	str += '		<div id="sharePostSitesGroup">';
	str += '			<div id="sharePostSitesDrpdn">';
	str += '				<span id="sharePostSitesDrpdnTitle">Choose your social networking site</span>';
	str += '				<div id="sharePostSitesDrpdnButton" onclick="CNNPlaylistManager.getInstance().controller.toggleShareSites();"></div>';
	str += '			</div>';
	str += '			<div id="sharePostSites" style="display: none;">';
	str += '				<ul>';
	str += '					<li id="shareTwitter" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'twitter\')">Twitter</a></li>';
	str += '					<li id="shareDelicious" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'delicious\')">Delicious</a></li>';
	str += '					<li id="shareDigg" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'digg\')">Digg</a></li>';
	str += '					<li id="shareFacebook" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'facebook\')">Facebook</a></li>';
	str += '					<li id="shareMixx" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'mixx\')">Mixx</a></li>';
	str += '					<li id="shareMyspace" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'myspace\')">MySpace</a></li>';
	str += '					<li id="shareReddit" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'reddit\')">Reddit</a></li>';
	str += '					<li id="shareStumbleupon" class="shareItem"><a href="javascript:CNNPlaylistManager.getInstance().controller.shareVideo(\'stumbleupon\')">StumbleUpon</a></li>';
	str += '					<li id="shareMyYahoo" class="shareItem">Yahoo Buzz</li>';
	str += '				</ul>';
	str += '			</div>';
	str += '		</div>';
	str += '	</div>';
 	str += '</div>';

	divObj.innerHTML = str;

	if ($('mosVidContainer')) {
		$('mosVidContainer').appendChild(divObj);
	} else {
		$('cnnVPFlashLarge').appendChild(divObj);
	}
}

CoreVideoControls_Share.clickEvent = function() {
	var c =CNNPlaylistManager.getInstance().controller;
	if ($('shareOverlay').style.display == 'block') {
		CNNPlaylistManager.getInstance().controller.hideShare(true);
		$('shareLayerId').className = c.buttons['share'].classes['activeOn'];
	} else {
		CNNPlaylistManager.getInstance().controller.hideEmbed();
		if (CNNPlaylistManager.getInstance().controller.endSlateActive == true) {
			//$('endReplay').style.display = 'none';
			//$('endEmbed').style.display = 'none';
			//$('endShare').style.display = 'none';
		}
		CNNPlaylistManager.getInstance().controller.showShare();
		$('shareLayerId').className = c.buttons['share'].classes['disabled'];
	}
}

/* 	**********************************************

	End		-	Share
	Start 	- 	Fullscreen

	********************************************** */

function CoreVideoControls_Fullscreen() { }

CoreVideoControls_Fullscreen.prototype.fullscreenDiv = null;
CoreVideoControls_Fullscreen.prototype.fullscreenHide = false;

CoreVideoControls_Fullscreen.prototype.disableFullscreen = function() {
	if ($('fullscreenLayer')) {
		$('fullscreenLayer').className = this.buttons['fullscreen'].classes['disabled'];
		$('fullscreenLayer').onclick = function() { }
		$('fullscreenLayer').onmouseover = function() { }
		$('fullscreenLayer').onmouseover = function() { }
		CNNPlaylistManager.getInstance().controller.fullscreenDiv.style.display = 'none';
	}
}

CoreVideoControls_Fullscreen.prototype.enableFullscreen = function() {
	if ($('fullscreenLayer')) {
		$('fullscreenLayer').className = this.buttons['fullscreen'].classes['activeOff'];
		$('fullscreenLayer').onclick = this.buttons['fullscreen'].clickEvent;
		$('fullscreenLayer').onmouseover = function() { CNNPlaylistManager.getInstance().controller.fullscreenHide = false; CNNPlaylistManager.getInstance().controller.fullscreenDiv.style.display = 'block'; }
		$('fullscreenLayer').onmouseout = function() {

			if (CNNPlaylistManager.getInstance().controller.fullscreenDiv.id == 'fullscreenUpgrade') {
				CNNPlaylistManager.getInstance().controller.fullscreenHide = true;
				setTimeout("if (CNNPlaylistManager.getInstance().controller.fullscreenHide) { CNNPlaylistManager.getInstance().controller.fullscreenDiv.style.display = 'none'; }",3000);
			} else {
				CNNPlaylistManager.getInstance().controller.fullscreenDiv.style.display = 'none';
			}
		}
	}
}

CoreVideoControls_Fullscreen.init = function() {
	var divObj = document.createElement('div');
	divObj.setAttribute('id','fullscreenLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['fullscreen'].classes['disabled'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);

	// build the div for the fullscreen item
	var fullScreenBubbleCheck = DetectFlashVer(9,0,115);
	if (fullScreenBubbleCheck)
	{
		divObj = document.createElement('div');
		divObj.setAttribute('id','fullscreenDoubleClick');
		divObj.innerHTML = '<img src="http://i.cdn.turner.com/cnn/.e/img/2.0/video/controls/flashDoubleClick.gif">';
		$('mosVidContainer').appendChild(divObj);
		CNNPlaylistManager.getInstance().controller.fullscreenDiv = $('fullscreenDoubleClick');
	}
	else
	{
		divObj = document.createElement('div');
		divObj.setAttribute('id','fullscreenUpgrade');
		divObj.setAttribute('class', 'fullscreenUpgrade');
		divObj.innerHTML = '<a href="http://www.adobe.com/products/flashplayer/" target="_blank"><img border="no" src="http://i.cdn.turner.com/cnn/.e/img/2.0/video/controls/flashUpgrade.gif"></a>';
		$('mosVidContainer').appendChild(divObj);
		CNNPlaylistManager.getInstance().controller.fullscreenDiv = $('fullscreenUpgrade');
	}
}

CoreVideoControls_Fullscreen.clickEvent = function() {
	CNNPlayer.getActivePlayer().handleEvent('fullscreenPressed');
}

/* 	**********************************************

	End		-	Fullscreen
	Start 	- 	Timeline

	********************************************** */

function CoreVideoControls_Timeline() { }

CoreVideoControls_Timeline.prototype.enableTimelineScrubber = function() {
	if ($('timelineTrackBackground')) {
		this.scrubbers['timeline'].scrubberPointer.disabled = false;
		$('timelineHandler').className = this.scrubbers['timeline'].classes['handlerEnabled'];
	}
}

CoreVideoControls_Timeline.prototype.disableTimelineScrubber = function() {
	if ($('timelineTrackBackground')) {
		this.scrubbers['timeline'].scrubberPointer.disabled = true;
		$('timelineHandler').className = this.scrubbers['timeline'].classes['handlerDisabled'];
	}
}

CoreVideoControls_Timeline.prototype.setTimelineScrubberBuffer = function(val) {
	if ($('timelineTrackBackground')) {
		$('timelineTrackBuffer').style.width = ('' + (val * 100) + '%');
	}
}

CoreVideoControls_Timeline.prototype.doneTimelineScrubbing = function(val) {
	if ($('timelineTrackBackground')) {
		CNNPlayer.getActivePlayer().getMediaPlayer().seek(Math.floor(this.duration * val));
	}
}

CoreVideoControls_Timeline.prototype.hideTimeLineScrubber = function() {
	if($('timelineTrackBackground')) {
		$('timelineTrackBackground').hide();
		$('timelineHandlerBacker').hide();
	}
}

CoreVideoControls_Timeline.prototype.showTimeLineScrubber = function() {
	if($('timelineTrackBackground')) {
		$('timelineTrackBackground').show();
		$('timelineHandlerBacker').show();
	}
}

CoreVideoControls_Timeline.init = function()
{
	// track container
	var divObj = document.createElement('div');
	divObj.setAttribute('id','timelineTrackContainer');
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);

	// place the background layer for the handle
	var divObj = document.createElement('div');
	divObj.setAttribute('id','timelineTrackBackground');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].classes['trackBackground'];
	$('timelineTrackContainer').appendChild(divObj);

	// fill the background layer
	var divObj = document.createElement('div');
	divObj.setAttribute('id','timelineTrackBuffer');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].classes['trackBuffer'];
	$('timelineTrackBackground').appendChild(divObj);

	// create the handle encloser
	var divObj = document.createElement('div');
	divObj.setAttribute('id','timelineHandlerBacker');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].classes['handlerBacker'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);

	// create the handle
	var divObj = document.createElement('div');
	divObj.setAttribute('id','timelineHandler');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].classes['handlerDisabled'];
	$('timelineHandlerBacker').appendChild(divObj);

	CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].scrubberPointer = new Control.Slider('timelineHandler', 'timelineHandlerBacker', {
		onSlide: CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].slideEvent,
		onChange: CNNPlaylistManager.getInstance().controller.scrubbers['timeline'].changeEvent,
		disabled: true
	});

}

CoreVideoControls_Timeline.slideEvent = function(val) {
	CNNPlaylistManager.getInstance().controller.amScrubbing = true;
}

CoreVideoControls_Timeline.changeEvent = function(val) {
	if(val >= .97) {
			val = .95;
	}
	
	CNNPlaylistManager.getInstance().controller.amScrubbing = false;
	CNNPlaylistManager.getInstance().controller.doneTimelineScrubbing(val);
}

/* 	**********************************************

	End		-	Timeline
	Start 	- 	Volume Button

	********************************************** */

function CoreVideoControls_VolumeButton() { }

CoreVideoControls_VolumeButton.prototype.setVolumeButton = function(val) {
	//alert('mute: '+this.buttons['volume'].isMuted);
	this.buttons['volume'].isMuted = false;

	if (val < 0.05 )						//if slide to (almost) 0 show 'muted' button
	{
		$('volumeLayer').className = this.buttons['volume'].classes['disabled'];
		this.buttons['volume'].isMuted = true;
		$('muteLayer').className = this.buttons['mute'].classes['activeOn'];
	}
	else if (val >= 0.05 && val < 0.6666)	// show mid volume button
	{
		$('volumeLayer').className = this.buttons['volume'].classes['activeOff'];
		$('volumeLayer').onmouseover = function() {
			CNNPlaylistManager.getInstance().controller.showVolumeOverlay();
		}
		$('volumeLayer').onmouseout = function() {
			CNNPlaylistManager.getInstance().controller.hideVolumeOverlay(true);
		}
		$('muteLayer').className = this.buttons['mute'].classes['disabled'];
	}
	else if (val >= 0.6666)					// show full volume button
	{
		$('volumeLayer').className = this.buttons['volume'].classes['activeOn'];
	}

	//volumeCookie(val);
	CNNPlayer.getActivePlayer().handleEvent('volumeChanged');
}


CoreVideoControls_VolumeButton.init = function() {
	// place the volume mutted button
	CNNPlaylistManager.getInstance().controller.buttons['volume'].isMuted = false;
	CNNPlaylistManager.getInstance().controller.buttons['volume'].lastDrop = 0;
	var divObj = document.createElement('div');
	divObj.setAttribute('id','volumeLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['volume'].classes['disabled'];
	divObj.onclick = function() { CNNPlaylistManager.getInstance().controller.buttons['volume'].clickEvent(); }
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
}

CoreVideoControls_VolumeButton.clickEvent = function() {
	var c = CNNPlaylistManager.getInstance().controller;


	if (c.buttons['volume'].isMuted)
	{
		c.buttons['volume'].isMuted = false;
		if(c.buttons['volume'].lastDrop==0) { c.buttons['volume'].lastDrop=0.45; }
		c.scrubbers['volume'].scrubberPointer.setValue(c.buttons['volume'].lastDrop);
		c.setVolumeButton(c.buttons['volume'].lastDrop);
		$('muteLayer').className = c.buttons['mute'].classes['disabled'];
	}
	else
	{
		c.buttons['volume'].lastDrop = c.scrubbers['volume'].scrubberPointer.value;
		c.scrubbers['volume'].scrubberPointer.setValue(0);
		c.setVolumeButton(0);
		c.buttons['volume'].isMuted = true;
		$('muteLayer').className = c.buttons['mute'].classes['activeOn'];
	}

}

CoreVideoControls_VolumeButton.prototype.showVolumeButton = function() {
	if($('volumeLayer')) {
		$('volumeLayer').show();
	}
}

CoreVideoControls_VolumeButton.prototype.hideVolumeButton = function() {
	if($('volumeLayer')) {
		$('volumeLayer').hide();
	}
}

CoreVideoControls_VolumeButton.prototype.hideVolumeOverlayIntervalId = null;
CoreVideoControls_VolumeButton.prototype.showVolumeOverlay = function()
{
	window.clearTimeout(this.hideVolumeOverlayIntervalId);
	this.hideVolumeOverlayIntervalId = null;
	this.hideMute();
	this.showVolumeScrubber();

}

CoreVideoControls_VolumeButton._hideVolumeOverlay = function(showMute)
{
	window.clearTimeout(CNNPlaylistManager.getInstance().controller.hideVolumeOverlayIntervalId);
	CNNPlaylistManager.getInstance().controller.hideVolumeOverlayIntervalId = null;
	CNNPlaylistManager.getInstance().controller.hideVolumeScrubber();
	if(showMute) {
		CNNPlaylistManager.getInstance().controller.showMute();
	}
}


CoreVideoControls_VolumeButton.prototype.hideVolumeOverlay = function(showMute)
{
	if(typeof(showMute) == 'undefined') {
		var showMute = false;
	}

	//if hiding already scheduled, call immediately and bail
	if(this.hideVolumeOverlayIntervalId != null) {
		CoreVideoControls_VolumeButton._hideVolumeOverlay(showMute);
		return;
	}

	//schedule a call to hide
	this.hideVolumeOverlayIntervalId = window.setTimeout('CoreVideoControls_VolumeButton._hideVolumeOverlay('+showMute+')', 2000);
}


/* 	**********************************************

	End		-	Volume Button
	Start 	- 	Volume Scrubber

	********************************************** */

function CoreVideoControls_VolumeScrubber() { }

CoreVideoControls_VolumeScrubber.slideChangeEvent = function(val) {
	var width = Math.ceil(33 * val);
	$('volumeTrackBuffer').style.width = width + 'px';
	CNNPlaylistManager.getInstance().controller.setVolumeButton(val);
}

CoreVideoControls_VolumeScrubber.init = function() {

	// place the background layer for the handle
	var divObj = document.createElement('div');
	divObj.setAttribute('id','volumeTrackBackground');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['volume'].classes['trackBackground'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);

	/* background layer */
	var divObj = document.createElement('div');
	divObj.setAttribute('id','volumeTrackBuffer');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['volume'].classes['trackBuffer'];
	$('volumeTrackBackground').appendChild(divObj);

	// create the handle encloser
	var divObj = document.createElement('div');
	divObj.setAttribute('id','volumeHandlerBacker');

	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['volume'].classes['handlerBacker'];
	divObj.onmouseover = function() { 	CNNPlaylistManager.getInstance().controller.showVolumeOverlay(); }
	divObj.onmouseout = function() { CNNPlaylistManager.getInstance().controller.hideVolumeOverlay(true); }

	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);

	// create the handle
	var divObj = document.createElement('div');
	divObj.setAttribute('id','volumeHandler');
	divObj.className = CNNPlaylistManager.getInstance().controller.scrubbers['volume'].classes['handlerEnabled'];
	$('volumeHandlerBacker').appendChild(divObj);

	CNNPlaylistManager.getInstance().controller.scrubbers['volume'].scrubberPointer = new Control.Slider('volumeHandler', 'volumeHandlerBacker', {
		onSlide: CNNPlaylistManager.getInstance().controller.scrubbers['volume'].slideEvent,
		onChange: CNNPlaylistManager.getInstance().controller.scrubbers['volume'].changeEvent
	});

}

//why does this method make me happy?
CoreVideoControls_VolumeScrubber.prototype.showVolumeScrubber = function()
{
	$('volumeTrackBackground').show();
	$('volumeTrackBuffer').show();
	$('volumeHandlerBacker').show();
	$('volumeHandler').show();

}

//oh this one too!
CoreVideoControls_VolumeScrubber.prototype.hideVolumeScrubber = function()
{
	$('volumeTrackBackground').hide();
	$('volumeTrackBuffer').hide();
	$('volumeHandlerBacker').hide();
	$('volumeHandler').hide();

}


/* 	**********************************************

	End		-	Volume Scrubber
	Start 	- 	Mute Button

	********************************************** */

function CoreVideoControls_MuteButton() { }

CoreVideoControls_MuteButton.init = function() {
	CNNPlaylistManager.getInstance().controller.buttons['volume'].isMuted = false;
	CNNPlaylistManager.getInstance().controller.buttons['volume'].lastDrop = 0;
	var divObj = document.createElement('div');
	divObj.setAttribute('id','muteLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['mute'].classes['disabled'];
	divObj.onclick = function() { CNNPlaylistManager.getInstance().controller.buttons['mute'].clickEvent(); }
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
}

CoreVideoControls_MuteButton.clickEvent = function() {
	var c = CNNPlaylistManager.getInstance().controller;
	if (c.buttons['volume'].isMuted)
	{
		c.buttons['volume'].isMuted = false;
		if(c.buttons['volume'].lastDrop==0) { c.buttons['volume'].lastDrop=0.45; }
		c.scrubbers['volume'].scrubberPointer.setValue(c.buttons['volume'].lastDrop);
		c.setVolumeButton(c.buttons['volume'].lastDrop);
		$('muteLayer').className = c.buttons['mute'].classes['disabled'];
//		CNNPlaylistManager.getInstance().controller.buttons['volume'].clickEvent();
	}
	else
	{
		c.buttons['volume'].lastDrop = c.scrubbers['volume'].scrubberPointer.value;
		c.scrubbers['volume'].scrubberPointer.setValue(0);
		c.setVolumeButton(0);
		c.buttons['volume'].isMuted = true;
		$('muteLayer').className = c.buttons['mute'].classes['activeOn'];
	}
}

CoreVideoControls_MuteButton.prototype.showMute = function() {
	$('muteLayer').show();
}

CoreVideoControls_MuteButton.prototype.hideMute = function() {
	$('muteLayer').hide();
}

/* 	**********************************************

	End		-	Mute Button
	Start 	- 	Time and Duration

	********************************************** */

function CoreVideoControls_Clock() { }

CoreVideoControls_Clock.prototype.calculateTime = function(val) {
	if ($('timeLayer'))
	{
		if (val > 59)
		{
			var minutes = Math.floor(val / 60);
			seconds = (val % 60);
			var seconds = val - (60 * minutes);
			if (seconds < 10) seconds = ('' + "0") + seconds;
			return (minutes + ":" + seconds);
		}
		else
		{
			if (val < 10) val = ('' + "0") + val;
			return ("0:" + val);
		}
	}
}

CoreVideoControls_Clock.prototype.setDuration = function(val) {
	if ($('timeLayer'))
	{
		if ( val ) {
			this.duration = val;
			$('durationLayer').innerHTML = this.calculateTime(val);
		}
	}
}

CoreVideoControls_Clock.prototype.setTime = function(val) {
	if ($('timeLayer'))
	{
		$('timeLayer').innerHTML = this.calculateTime(val);
		if (this.duration != null && this.amScrubbing == false) {
			this.scrubbers['timeline'].scrubberPointer.setValueExternally(val/this.duration);
		}
	}
}

CoreVideoControls_Clock.prototype.resetTimeDuration = function() {
	if ($('timeLayer')) {
		this.setTime(0);
		this.setDuration(0);
	}
}

CoreVideoControls_Clock.init = function() {
	var divObj = document.createElement('div');
	divObj.setAttribute('id','timeLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.clocks['time and duration'].classes['time'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
	$('timeLayer').innerHTML = "0:00";

	var divObj = document.createElement('div');
	divObj.setAttribute('id','sepLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.clocks['time and duration'].classes['sep'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
	$('sepLayer').innerHTML = "/";

	var divObj = document.createElement('div');
	divObj.setAttribute('id','durationLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.clocks['time and duration'].classes['duration'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
	$('durationLayer').innerHTML = "0:00";

}


/* 	**********************************************

	End		-	Time and Duration
	Start 	- 	add<object> abstracts

	********************************************** */

CoreVideoControls.prototype.addButton = function(buttonName,buttonInit,disabledClass,activeOffClass,activeOnClass,clickEvent) {
	this.buttons[buttonName] = new CoreVideoControls.Button(disabledClass,activeOffClass,activeOnClass,clickEvent);
	this.initList[this.initList.length] = buttonInit;
}

CoreVideoControls.prototype.addClock = function(clockName,clockInit,timeClass,durationClass,sepClass) {
	this.clocks[clockName] = new CoreVideoControls.Clock(timeClass,durationClass,sepClass);
	this.initList[this.initList.length] = clockInit;
}

CoreVideoControls.prototype.addScrubber = function(scrubberName,scrubberInit,trackBackground,trackBuffer,handlerBacker,handlerDisabled,handlerEnabled,slideEvent,changeEvent) {
	this.scrubbers[scrubberName] = new CoreVideoControls.Scrubber(trackBackground,trackBuffer,handlerBacker,handlerDisabled,handlerEnabled,slideEvent,changeEvent);
	this.initList[this.initList.length] = scrubberInit;
}

CoreVideoControls.inheritAll = function() {
	for (var i = 1; i < arguments.length; i++) {
		for (x in arguments[i].prototype) {
			arguments[0].prototype[x] = arguments[i].prototype[x];
		}
	}
}

/* 	**********************************************

	End 	- 	add<object> abstracts
	Start 	- 	<object> abstracts

	********************************************** */

CoreVideoControls.Button = function(disabledClass,activeOffClass,activeOnClass,clickEvent) {
	this.classes = new Array();
	this.classes['disabled'] = disabledClass;
	this.classes['activeOff'] = activeOffClass;
	this.classes['activeOn'] = activeOnClass;
	this.clickEvent = clickEvent;
}

CoreVideoControls.Clock = function(time,duration,sep) {
	this.classes = new Array();
	this.classes['time'] = time;
	this.classes['duration'] = duration;
	this.classes['sep'] = sep;
}

CoreVideoControls.Scrubber = function(trackBackground,trackBuffer,handlerBacker,handlerDisabled,handlerEnabled,slideEvent,changeEvent) {
	this.classes = new Array();
	this.classes['trackBackground'] = trackBackground;
	this.classes['trackBuffer'] = trackBuffer;
	this.classes['handlerBacker'] = handlerBacker;
	this.classes['handlerEnabled'] = handlerEnabled;
	this.classes['handlerDisabled'] = handlerDisabled;
	this.slideEvent = slideEvent;
	this.changeEvent = changeEvent;
}

Control.Slider.prototype.setValueExternally = function(sliderValue, handleIdx){
	if(!this.active) {
		this.activeHandleIdx = handleIdx || 0;
		this.activeHandle    = this.handles[this.activeHandleIdx];
		this.updateStyles();
	}
	handleIdx = handleIdx || this.activeHandleIdx || 0;
	if(this.initialized && this.restricted) {
		if((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
			sliderValue = this.values[handleIdx-1];
		if((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
			sliderValue = this.values[handleIdx+1];
	}
	sliderValue = this.getNearestValue(sliderValue);
	this.values[handleIdx] = sliderValue;
	this.value = this.values[0]; // assure backwards compat

	this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] =
	this.translateToPx(sliderValue);

	this.drawSpans();

}


/* 	**********************************************

	End		-	<object> abstracts
	Start 	- 	Email

	********************************************** */
function CoreVideoControls_Email() { }

CoreVideoControls_Email.prototype.disableEmail = function() {
	$('emailLayer').className = this.buttons['email'].classes['disabled'];
	$('emailLayer').onclick = function() { }
	$('emailLayer').onmouseover = function() { }
	$('emailLayer').onmouseout = function() { }
}

CoreVideoControls_Email.prototype.enableEmail = function() {
	$('emailLayer').className = this.buttons['email'].classes['activeOff'];
	$('emailLayer').onclick = this.buttons['email'].clickEvent;
	$('emailLayer').onmouseover = function() { this.className = CNNPlaylistManager.getInstance().controller.buttons['email'].classes['activeOn']; }
	$('emailLayer').onmouseout = function() { this.className = CNNPlaylistManager.getInstance().controller.buttons['email'].classes['activeOff']; }
}

CoreVideoControls_Email.init = function() {
	// place the email disabled button
	var divObj = document.createElement('div');
	divObj.setAttribute('id','emailLayer');
	divObj.className = CNNPlaylistManager.getInstance().controller.buttons['email'].classes['disabled'];
	CNNPlaylistManager.getInstance().controller.parentDiv.appendChild(divObj);
}

CoreVideoControls_Email.clickEvent = function() {
	CNNPlayer.getActivePlayer().handleEvent('sharePressed');
}

CoreVideoControls.inheritAll(
	CoreVideoControls,
	CoreVideoControls_Play,
	CoreVideoControls_Pause,
	CoreVideoControls_Email,
	CoreVideoControls_Embed,
	CoreVideoControls_Share,
	CoreVideoControls_Fullscreen,
	CoreVideoControls_Timeline,
	CoreVideoControls_VolumeButton,
	CoreVideoControls_VolumeScrubber,
	CoreVideoControls_MuteButton,
	CoreVideoControls_Clock);


