function NascarFlashControls() {
	this.controller = (navigator.appName.indexOf("Microsoft") != -1) ? window["nascarControls"] : document["nascarControls"];
}
NascarFlashControls.prototype.handleXMPEvent = function( p_method, p_arg ) {
	var returnVal;
	switch( p_method ) {
		case 'setTime':
		case 'setVolume':
		case 'setEnabled':
		case 'togglePlay':
		case 'setDuration':
		case 'setLoadedPercent':
		case 'setScrubberEnabled':
			this.controller[p_method](p_arg);
			break;

		case 'getVolume':
			returnVal = cnnNascarXmpControls.currentVolume;
			break;

		case 'setEmailEnabled':
		default:
			// Ignore
			break;
	}
	return returnVal;
};
NascarFlashControls.prototype.hideShare = function() {
	$('cnnXmpShare').style.display = 'none';
	XMPPlayer.getActivePlayer().handleEvent('playPressed');
};
NascarFlashControls.prototype.shareVideo = function( shareType ) {
	var p = XMPPlaylistManager.getInstance();
	var dataObj = p.playlists[p.activePlaylist].playlistJsonObjs[p.playlists[p.activePlaylist].pointer].getDataObject();
	var linkUrl = null;
	var vidUrl = encodeURIComponent('http://www.nascar.com/'+ dataObj.id +'/index.html');
	var desc = encodeURIComponent(dataObj.description);
	var headline = encodeURIComponent(dataObj.headline);
	switch (shareType) {
		case 'mixx':
			linkUrl = 'http://www.mixx.com/submit/video?page_url='+ vidUrl +'&title='+ headline +'&description='+ desc +'&partner=NASCAR';
			break;
			
		case 'digg':
			linkUrl = 'http://digg.com/submit?phase=2&url='+ vidUrl +'&title='+ headline +'&bodytext='+ desc;
			break;
			
		case 'facebook':
			//var vidUrl = encodeURIComponent('http://www.nascar.com/'+ dataObj.id +'');
			linkUrl = 'http://www.facebook.com/sharer.php?u='+ vidUrl +'&t='+ headline;
			break;
			
		case 'delicious':
			linkUrl = 'http://del.icio.us/post?v=4&partner=cnn&noui&jump=close&url='+ vidUrl +'&title='+ headline;
			break;
			
		case 'reddit':
			linkUrl = 'http://reddit.com/submit?url='+ vidUrl +'&title='+ headline;
			break;
			
		case 'stumbleupon':
			linkUrl = 'http://www.stumbleupon.com/submit?url='+ vidUrl +'&title='+ headline;
			break;
			
		case 'myspace':
			linkUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?t='+ headline +'&c='+ desc +'&u='+ vidUrl;
			break;
	}
	if (linkUrl != null) {
		window.open(linkUrl,'videoShareLink');
		//alert("Share with "+ shareType +"\n"+ linkUrl);
	}
};

var cnnNascarXmpControls = {
	currentVolume: 0,
	play: function() {
		XMPPlayer.getActivePlayer().handleEvent('playPressed');
	},
	
	pause: function () {
		XMPPlayer.getActivePlayer().handleEvent('pausePressed');
	},
	
	setVolume: function( val ) {
		cnnNascarXmpControls.currentVolume = val;
		XMPPlayer.getActivePlayer().handleEvent('volumeChanged');
	},
	
	seek: function( val ) {
		XMPPlayer.getActivePlayer().getMediaPlayer().seek(val);
	},
	
	share: function () {
		//XMPPlayer.getActivePlayer().handleEvent('sharePressed');
		if ( $('cnnXmpVideoURL').value == '' ) {
			var thumb = '';
			var p = XMPPlaylistManager.getInstance();
			var dataObj = p.playlists[p.activePlaylist].playlistJsonObjs[p.playlists[p.activePlaylist].pointer].getDataObject();
			for ( var i = 0; i < dataObj.images.length; i++ ) {
				if ( dataObj.images[i].id == '145x93' ) {
					thumb = dataObj.images[i].resource;
				}
			}
			$('cnnXmpVideoURL').value = 'http://www.nascar.com'+ dataObj.id +'/index.html';
			$('cnnXmpVideoImageURL').value = thumb;
			$('cnnXmpShareThumb').setAttribute('src', thumb);
		}
		var currentDisplay = $('cnnXmpShare').style.display;
		if ( !currentDisplay || currentDisplay == 'none' ) {
			$('cnnXmpShare').style.display = 'block';
			XMPPlayer.getActivePlayer().handleEvent('pausePressed');
		}
		else {
			$('cnnXmpShare').style.display = 'none';
			XMPPlayer.getActivePlayer().handleEvent('playPressed');
		}

	},
	
	fullscreen: function ( bool ) {
		//XMPPlayer.getActivePlayer().handleEvent('fullscreenPressed');
		if ( bool ) {
			$('cnnXmpFullscreen').style.display = 'block';
		}
		else {
			$('cnnXmpFullscreen').style.display = 'none';
		}
	},
	
	hideShare: function( bool ) {
		this.share();
	}
};