TVEUtil = {
	waitingSection: 'SHOWS',
	authBool: false,
	bIsFullScreen: false,
	bReloadCVP: false,
	currentBitrateId: "",
	isSwitching: false,
	hqBitrateId: "",
	standardBitrateId: "",
	defaultBitRate: "true",
	bitRateJson: "",
	switchingState: "switching",
	timeOutState: true,
	timeoutTimer: null,
	authVideoId: "",
	setState: false,
	provider: 'AdultSwim',
	bIsHD: false,
	strVideoId: '',
	distributor: 'Unspecified MVPD',
	
	// swfLoadedvar: false,
	
	TURNERPLAYER: null,
	AUTH: null,
	AUTHBOOL: false,
	AUTHREADY: false,
	WAITINGVIDEO: null,
	
	init: function(){
		//		Utilities.log('TVE INIT');
		TVEUtil.initCVPPlayer();
	},
	
	checkExTime: function(){
		Utilities.log('checkExTime');
		var cookieFullValue = $.cookie('authz_tv');
		if (cookieFullValue !== null) {
			var cookieExTime = cookieFullValue.substring(cookieFullValue.indexOf("|") +
			1, cookieFullValue.lastIndexOf("|"));
			cookieExTime = cookieExTime * 1000;
			var d = new Date();
			var utc = d.getTime();
			
			if (utc >= cookieExTime) {
				setTimeout("location.reload(true);", 10);
			}
		}
	},
	checkAuthz: function(){
		var cookieFullValue = $.cookie('authz_tv');
		var bAuthZ = false;
		if (cookieFullValue !== null) {
			bAuthZ = true;
		}
		//alert('|-o-| checkAuthz ' + bAuthZ);
		return bAuthZ;
	},
	initCVPPlayer: function(){
		Utilities.log('TVE INITCVP')
		// normal initialization of the CVP player from AdultSwim dev environment
		// on player ready it will init the auth method
		TVEUtil.TURNERPLAYER = new CVP({
			id: 'cvp_1',
			width: '992',
			height: '442',
			flashVars: {
				cvpContainerUrl: (location.hostname == 'www.adultswim.com') ? "/tools/xml/container.xml" : "/tools/xml/tve_container_preprod.xml",
				cvpConfigUrl: (location.hostname == 'www.adultswim.com') ? "/tools/xml/tve_config.xml" : "/tools/xml/tve_config_preprod.xml",
				basePath: '/tveverywhere_ref',
				context: 'main'
			},
			embed: {
				containerSwf: (location.hostname == 'www.adultswim.com') ? 'tools/swf/adultswim_video_f10.swf' : 'tools/swf/adultswim_video_staging_f10.swf',
				expressInstallSwf: 'http://i.cdn.turner.com/xslo/cvp/assets/flash/expressInstall.swf',
				//?playerUrl=http://i.cdn.turner.com/v5cache/TBS/mvpd/flash/dev/TurnerPlayer20100318_f10.swf&dmtdebug=true&configUrl=/tools/xml/tve_config.xml
				
				flashVersion: '10.1.53.64',
				options: {
					quality: 'high',
					bgcolor: '#000000',
					wmode: 'transparent',
					allowFullScreen: 'true',
					allowScriptAccess: 'always'
				}
			},
			onPlayerReady: function(){
				Utilities.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!playerReady');
				TVEUtil.cvpReady = true;
				PageControls.playScene(TVEUtil.strVideoId);
			},
			onAdStarted: function(token){
				Utilities.log('~~~~~~~~~~~~~~~~~onAdStarted');
			},
			onAdFinished: function(token){
				Utilities.log('~~~~~~~~~~~~~~~~~onAdFinished');
			},
			onAdError: function(token){
				Utilities.log('~~~~~~~~~~~~~~~~~onAdError');
			},
			onContentBegin: function(videoId, json, tveMode){
				Utilities.log('~~~~~~~~~~~~~~~~~onContentBegin ' + videoId + ' : ' + json + ' : ' + tveMode);
				var oJson = json;
				var myObject = {};
				json == undefined ? oJson = TVEUtil.TURNERPLAYER.getContentEntry(videoId) : oJson = json;
				myObject = eval('(' + oJson.toString() + ')');
				Utilities.log('|-o-| onContentBegin json ' + oJson);
				Utilities.log('myObject: ' + myObject);
				Utilities.log('myObject.tvemode: ' + myObject.tvemode);
				Utilities.log('|-o-| onContentBegin getContentEntry(videoId) ' + TVEUtil.TURNERPLAYER.getContentEntry(videoId));
				if (myObject.tveMode == 'C3') {
					if (TVEUtil.provider == "AdultSwim") {
						TVEUtil.TURNERPLAYER.setTrackingContext('short_interval_c3');
					}
					else {
						TVEUtil.TURNERPLAYER.setTrackingContext('long_interval_c3');
					}
				}
				else 
					if (myObject.tveMode == 'C4') {
						if (TVEUtil.provider == "AdultSwim") {
							TVEUtil.TURNERPLAYER.setTrackingContext('short_interval_c4');
						}
						else {
							TVEUtil.TURNERPLAYER.setTrackingContext('long_interval_c4');
						}
					}
					else {
						TVEUtil.TURNERPLAYER.setTrackingContext('clips');
					}
				TVEUtil.bitRateJson = TVEUtil.TURNERPLAYER.getAvailableBitrates('window');
				Utilities.log('|-o-| TVEUtil.bitRateJson ' + TVEUtil.bitRateJson);
				HQ.disableHQButton();
				if (TVEUtil.bitRateJson != null) {
					for (var i = 0; i < TVEUtil.bitRateJson.length; i++) {
						if (TVEUtil.bitRateJson[i].label == "standard") {
							TVEUtil.standardBitrateId = TVEUtil.bitRateJson[i].rateId;
						}
						else 
							if (TVEUtil.bitRateJson[i].label == "hq") {
								TVEUtil.hqBitrateId = TVEUtil.bitRateJson[i].rateId;
							}
					}
				}
				Dramavision.updateVideoInfo(videoId);
				// Dramavision.queueNext();
			},
			onContentPlay: function(){
				Utilities.log('~~~~~~~~~~~~~~~~~onContentPlay');
				Utilities.log("~~~~~~ onContentPlay");
				Utilities.log("~~~~~~ Playing: " + TVEUtil.TURNERPLAYER.getBitrateId() + ' : ' + TVEUtil.bIsHD);
				if (TVEUtil.bIsHD) {
					HQ.showHDToggleOn();
				}
				if (TVEUtil.bitRateJson == null) {
					HQ.disableHQButton();
				}
				else {
					HQ.enableHQButton();
				}
				Browse.bOverrideVid = false; // remove override
				Utilities.log(':-o-: ' + Browse.bOverrideVid + ' :: ' + this.getContentEntry(this.getContentId()));
				
				document.getElementById("adCountdown").innerHTML = "";
			},
			onStreamSwitchComplete: function(newRate){
				Utilities.log('~~~~~~~~~~~~~~~~~onStreamSwitchComplete');
				TVEUtil.timeOutState = false;
				HQ.switchHD(newRate);
			},
			onContentCompleted: function(){
				Utilities.log('~~~~~~~~~~~~~~~~~onContentCompleted');
				TVEUtil.setState = true;
				TVEUtil.bHasRun = false;
				Utilities.log("Completed : " + this.getContentId());
				if (TVEUtil.bIsFullScreen) {
					TVEUtil.TURNERPLAYER.goFullScreen();
				}
				
			},
			onContentTrackingFullscreen: function(videoId, fullscreen){
				TVEUtil.bIsFullScreen == true ? TVEUtil.bIsFullScreen = false : TVEUtil.bIsFullScreen = true;
				Utilities.log('|-o-| Fullscreen( ' + videoId + ' ): ' + fullscreen + ' :: ' + TVEUtil.bIsFullScreen);
			}
		});
		
		TVEUtil.TURNERPLAYER.embed("pod6");
		// as the auth doesn't really rely on the CVP player being 'ready', start its initiliazation process now
		TVEUtil.initAuth();
	},
	
	initAuth: function(){
		var oProviders = null;
		if (location.hostname == 'www.adultswim.com'){
			 oProviders = {
				 Verizon : true,
				 Cox : true,
				 Comcast : true,
				 ATT : true,
				 Dish : true,
				 DTV : true,
				 Suddenlink : true
			 }
		};
		Utilities.log('TVE INITAUTH')
		// the auth init is done in the same 'style' as the CVP init
		TVEUtil.AUTH = new CVP.AuthManager({
			/*staging*/
			//		adobeSwfURL: "https://entitlement.auth-staging.adobe.com/entitlement/AccessEnabler.swf",
			/*prod*/
			//		adobeSwfURL: "https://entitlement.auth.adobe.com/entitlement/AccessEnabler.swf",
			adobeSwfURL: (location.hostname == 'www.adultswim.com') ? "https://entitlement.auth.adobe.com/entitlement/AccessEnabler.swf" : "https://entitlement.auth-staging.adobe.com/entitlement/AccessEnabler.swf",
			clientId: "AdultSwim",
			swfStyleOverride: {
				height: 5,
				width: 5,
				style: "z-index: 500; position: absolute; left: 0px; top: 0px;"
			},
			providerWhitelist : oProviders,
			onCustomMVPDPicker: function(props){
				//TVEUtil.displayPropertyPicker(props);
				CVP.AuthManager.defaultPropertyPicker(props);
				
			},
			onInitReady: function(){
				Utilities.log('!!init ready');
				if (TVEUtil.bReloadCVP) 
					PageControls.playScene(TVEUtil.strVideoId);
				TVEUtil.AUTHREADY = true;
				TVEUtil.AUTH.isAuthenticated();
			},
			onAuthenticationPassed: function(){
				TVEUtil.AUTHBOOL = true;
				Utilities.log('!bHasRun ' + $.cookie(CookieJar.cookie_name) + ' :: ' + CookieJar.cookie_name);
				document.getElementById('introSwfContainer').style.visibility = 'visible';
				$('#logoutContainer,#navFaqBtn').show();
				
				if (TVEUtil.AUTH.getProviderID() == 'Comcast') {
					$('#provider-logo').show();
				}
				
				try {
					//Distributor
					Utilities.log('|-o-| TVEUtil.AUTH.getProviderID() ' + TVEUtil.AUTH.getProviderID());
					if (TVEUtil.AUTH.getProviderID() != null) {
						TVEUtil.distributor = TVEUtil.AUTH.getProviderID();
					}
					else {
						TVEUtil.distributor = "turner";
					}
					TVEUtil.provider = TVEUtil.distributor.toLowerCase() + "_tve";
				} 
				catch (e) {
					Utilities.log('|-o-| ERROR ERROR onAuthenticationPassed ' + e.name + ' : ' + e.message);
				}
				Utilities.log('|-o-| TVEUtil.provider ' + TVEUtil.provider);
				// Cookies
				try {
					if ($.cookie(CookieJar.cookie_name)) {
						Utilities.trace('$.cookie(CookieJar.cookie_name) ' + $.cookie(CookieJar.cookie_name));
						
						Utilities.log('Cookies! ');
						Utilities.log('Cookies! ' + $.cookie(CookieJar.cookie_name) + ' : ' + $.cookie(CookieJar.cookie_name_id) + ' : ' + $.cookie(CookieJar.cookie_name_page));
						$('#' + $.cookie(CookieJar.cookie_name)).addClass('nowPlaying');
						//Browse.pageNumber = $.cookie(CookieJar.cookie_name_page);
						Thumbnails.clickMethod($('#' + $.cookie(CookieJar.cookie_name)));
						Thumbnails.init();
						PageControls.playScene($.cookie(CookieJar.cookie_name_id));
						$.cookie(CookieJar.cookie_name, null, options);
						$.cookie(CookieJar.cookie_name_id, null, options);
					}
					else {
						try {
							Utilities.trace('!$.cookie(CookieJar.cookie_name  ' + TVEUtil.setState + ' : ' + TVEUtil.authVideoId + ' :: ' + Browse.videoId);
						} 
						catch (e) {
						}
						if (TVEUtil.setState) {
							TVEUtil.showMarketingSWF();
							PageControls.playScene(Browse.videoId);
						}
						else {
							TVEUtil.showMarketingSWF();
						}
					}
				} 
				catch (e) {
					Utilities.log('|-o-| ERROR ERROR ERROR onAuthenticationPassed ' + e.name + ' : ' + e.message);
				}
			},
			onAuthenticationFailed: function(){
				TVEUtil.AUTHBOOL = false;
				//authFail();
			
			},
			onAuthorizationPassed: function(resource){
				TVEUtil.AUTHBOOL = true;
				TVEUtil.playWaitingVideo();
			},
			onAuthorizationFailed: function(resourceID, errorCode, errorString){
				//alert("--authorization failed " + TVEUtil.AUTHBOOL);
				//alert(errorCode + ' : ' + errorString)
				//onAuthorizationFailed is called everything the cancel button is clicked in the default picker
				//we only want to display the message if the user is authenticated but not authorized
				if (TVEUtil.AUTHBOOL) {
					TVEUtil.AUTHBOOL = false;
					AuthError.noAuthToView(errorString);
				}
			},
			onTrackingData: function(trackingEventType, trackingData){
				//tracking data
				
				Utilities.log('onTrackingData et ' + trackingEventType)
				////alert('onTrackingData et ' + trackingEventType)
				Utilities.log('onTrackingData td ' + trackingData)
				
				switch (trackingEventType) {
					case "authorizationDetection":
						Utilities.log("rrr authorizationDetection :: " + trackingData[0] + ' : ' + trackingData[3] + ' : ' + hasSetFirstMetric);
						//						if (!trackingData[0]) {
						//							jQuery.facebox(Utilities.getAuthFailStatement());
						//						}
						/*  [0] Whether the token request was successful [true/false]
					 *       and if true:
					 *  [1] MVPD ID [string]
					 *  [2] User ID (md5 hashed) [string]
					 *  [3] Whether it was cached or not [true/false]
					 */
						// DEBUG
						//            if (logAdobe) {////alert("trackingEventType = " + trackingEventType + "; " + trackingData);}
						accessToken = '&mvpd=' + trackingData[1];
						// populate Omniture Metrics
						if (trackingData[0] == true) {
							setState = true;
						//track authorize
						}
						else {
						//track unauthorize
						}
						break;
					/*
					 case "authenticationDetection":
					 Utilities.log("rrr authenticationDetection :: " + trackingData[0] + ' : ' + trackingData[3] + ' : ' + hasSetFirstMetric);
					 /*  [0] Whether the token request was successful [true/false]
					 *	   and if true:
					 *  [1] MVPD ID [string]
					 *  [2] User ID (md5 hashed) [string]
					 *  [3] Whether it was cached or not [true/false]
					 * /
					 //log("trackingEventType = " + trackingEventType + "; " + trackingData);
					 accessToken = '&userId=' + trackingData[2] + '&mvpd=' + trackingData[1];
					 // populate Omniture Metrics
					 if (trackingData[0] == true) {
					 setState = true;
					 // if cached == true
					 if (trackingData[3] == true) {
					 trackAlreadyLoggedInPage(trackingData);
					 } else {
					 // else just redirected back from authorization
					 trackAuthenticationComplete(trackingData);
					 }
					 hasSetFirstMetric = true;
					 } else {
					 if (!hasSetFirstMetric) {
					 // populate Omniture Metrics
					 trackNotLoggedInPage();
					 hasSetFirstMetric = true;
					 }
					 }
					 break;
					 */
					case "authenticationDetection":
						Utilities.log("rrr authenticationDetection :: " + trackingData[0] + ' : ' + trackingData[3] + ' : ' + hasSetFirstMetric);
						/*  [0] Whether the token request was successful [true/false]
					 *	   and if true:
					 *  [1] MVPD ID [string]
					 *  [2] User ID (md5 hashed) [string]
					 *  [3] Whether it was cached or not [true/false]
					 */
						//log("trackingEventType = " + trackingEventType + "; " + trackingData);					
						accessToken = '&userId=' + trackingData[2] + '&mvpd=' + trackingData[1];
						// populate Omniture Metrics
						if (trackingData[0] == true) {
							setState = true;
							/*
						 // if cached == true
						 if (trackingData[3] == true) {
						 trackAlreadyLoggedInPage(trackingData);
						 } else {
						 // else just redirected back from authorization
						 trackAuthenticationComplete(trackingData);
						 }
						 */
							if ($.cookie('previousVisitor')) {
								log("track: previously authenicated");
								trackAlreadyLoggedInPage(trackingData);
							}
							else {
								log("track: authenicated");
								trackAuthenticationComplete(trackingData);
								$.cookie('previousVisitor', 'yes', {
									expires: 9999,
									path: '/'
								});
							}
							hasSetFirstMetric = true;
						}
						else {
							if (!hasSetFirstMetric) {
								// populate Omniture Metrics
								trackNotLoggedInPage();
								hasSetFirstMetric = true;
							}
						}
						break;
						
					case "mvpdSelection":
						Utilities.log("rrr mvpdSelection"); /*  [0] MVPD ID */
						// populate Omniture Metrics
						trackAuthenticationStart(trackingData);
						break;
					default:
						break;
				}
				
				//end tracking data		
			}
		});
	},
	
	showMarketingSWF: function(){
		Utilities.log("showMarketingSWF");
		TVEUtil.cvpReady = false;
		TVEUtil.setState = true;
		
		try {
			document.getElementById('dramavisionReturnTNT').style.display = 'none';
		} 
		catch (e) {
		};
		try {
			document.getElementById('videoContainer').style.display = 'none';
		} 
		catch (e) {
		};
		try {
			document.getElementById('introSwfContainer').style.display = 'block';
		} 
		catch (e) {
		};
		// try{document.getElementById('logoutContainer').style.display =
		// 'inline';}catch(e){};
		Utilities.log("@@-@@ logoutContainer");
		
		$('#logoutContainer,#navFaqBtn').show();
		TVEUtil.introSwf();
	},
	
	introSwf: function(){
		Utilities.log('introSwf');
		$('#introSwfContainer').html('');
		Slideshow.init();
	},
	
	initRestOfPage: function(){
		$.ajax({
			type: "GET",
			url: "http://teg8fdev1.turner.com:9196/tveverywhere/content/services/getCollections.do?id=58127",
			cache: false,
			dataType: "xml",
			success: function(data){
				var showList = new Array();
				$(data).find('subsubcollection').each(function(){
					if ($(this).find('name').text().indexOf('Full Episodes') > -1) {
						showList.push(new Array($(this).find('name').text(), $(this).attr('id')));
					}
				});
				var str = "";
				for (var i = 0; i < showList.length; i++) {
					str += '<div onclick="TVEUtil.renderShowList(' + showList[i][1] + ');" class="show"';
					if (i < showList.length - 1) 
						str += ' style="border-bottom: 1px solid #FFFFFF;"';
					str += '>' + showList[i][0] + '</div>';
				}
				document.getElementById('showListContainer').innerHTML = str;
			}
		});
	},
	
	getAuthorization: function(videoId){
		// save off the waiting video
		if (TVEUtil.AUTHREADY) {
			TVEUtil.WAITINGVIDEO = videoId;
			if (TVEUtil.AUTHBOOL) {
				TVEUtil.AUTH.getAuthorization("AdultSwim");
			}
			else {
				// if the user isn't authenticated yet, call the authentication piece
				// even though we know it's just calling authorization on the backside
				// saveVideoCookie(videoId);
				TVEUtil.AUTH.getAuthentication("AdultSwim");
			}
		}
	},
	
	playWaitingVideo: function(){
		if (TVEUtil.AUTHREADY) {
			// we must've already been authenticated, grab the token and play the video
			//TVEUtil.TURNERPLAYER.play(TVEUtil.WAITINGVIDEO, TVEUtil.AUTH.getAccessToken('', '&mvpd=Verizon'));
			TVEUtil.TURNERPLAYER.play(TVEUtil.WAITINGVIDEO, TVEUtil.AUTH.getAccessToken(null, null));
		}
	},
	
	authenticateUser: function(){
		var isFlashCurrent = FlashDetect.versionAtLeast(10, 2, 153);

		if ((!(isFlashCurrent)) || (!(FlashDetect.installed))) {
			jQuery.facebox('This website requires the Flash 10.2.153 (or higher) player.<br><br>You may upgrade your Flash plug-in by visiting the <a href="http://get.adobe.com/flashplayer/" style="color:black;text-decoration:underline;">Flash Download Center.</a><br><br>Please note you may need to reboot your system.');
		} else {
		      //return isFlashCurrent;
			Utilities.log('|-o-| authenticateUser ' + TVEUtil.AUTHREADY);
			if (TVEUtil.AUTHREADY) {
				// get the auth login
				TVEUtil.AUTH.getAuthentication('AdultSwim');
			}
		}
	},
	
	pickProvider: function(id){
		// send the selected provider into the authentication piece
		document.getElementById('accessEnablerContainer').innerHTML = "Authenticating...";
		document.getElementById('accessEnablerContainer').style.visibility = 'hidden'; //tveProviders
		//		document.getElementById('accessEnablerContainerDebug').style.height = '30px';
		TVEUtil.AUTH.selectProvider(id);
	},
	
	displayPropertyPicker: function(props){
		document.getElementById('accessEnablerContainer').innerHTML = "Please pick...";
		var str = '<table border="0" cellpadding="0" cellspacing="0"><tr>';
		for (var i = 0; i < props.length; i++) {
			str += '<td class="tveProviderPicker" valign="center" align="center"><a href="#" onclick="TVEUtil.pickProvider(\'' + props[i].ID + '\'); return false;"><img border="no" src="' + props[i].logoURL + '"></a><br><br>' + props[i].displayName + '</td>';
		}
		str += "</table>"
		document.getElementById('accessEnablerContainer').innerHTML = str; //tveProviders
		document.getElementById('accessEnablerContainer').style.visibility = 'visible'; //tveProviders
		//		document.getElementById('accessEnablerContainerDebug').style.height = '172px';
	},
	
	logout: function(){
		if (TVEUtil.AUTHREADY) {
			TVEUtil.AUTH.logout();
		}
	},
	
	renderShowList: function(id){
		// to do: put some better UI in here to determine if the auth piece is ready et or not
		$.ajax({
			type: "GET",
			url: ("http://teg8fdev1.turner.com:9196/tveverywhere/content/services/getCollectionByContentId.do?offset=0&sort=&limit=200&id=" + id),
			cache: false,
			dataType: "xml",
			success: function(data){
				var str = "<table><tr>";
				$(data).find('episode').each(function(){
					if ($(this).find('authType').text() == 'auth') 
						str += '<td><div onclick="TVEUtil.getAuthorization(' + $(this).attr('id') + ');" class="episodeAuth" id="episode_' + $(this).attr('id') + '">';
					else 
						str += '<td><div onclick="TVEUtil.TURNERPLAYER.play(' + $(this).attr('id') + ');" class="episode" id="episode_' + $(this).attr('id') + '">';
					str += '<div class="episodeImage"><img src="' + $(this).find('thumbnailUrl').text() + '"></div>';
					str += '<div class="episodeTitle">' + $(this).find('episodeTitle').text() + '</div>';
					str += '<div class="episodeBlurb">' + $(this).find('shortBlurb').text() + '</div>';
					str += '</div></td>';
				});
				str += '</tr></table>';
				document.getElementById('episodeListContainer').innerHTML = str;
			}
		});
	}
};
HQ = {
	init: function(){
	
	},
	enableHQButton: function(){
		$("#hd").css("display", "inline");
	},
	disableHQButton: function(){
		$("#hd").css("display", "none");
	},
	showHDToggleOn: function(){
		Utilities.log(':-o-: :-o-: :-o-: showHDToggleOn ' + TVEUtil.TURNERPLAYER.getBitrateId());
		if (TVEUtil.TURNERPLAYER.getBitrateId() == TVEUtil.hqBitrateId) {
			$("#hdstatus").attr("src", "tools/img/btn-hd-on.gif");
			$("#toggleIMG").css("display", "none");
		}
		else {
			HQ.showHDToggleOff();
		}
	},
	showHDToggleOff: function(){
		Utilities.log(':-o-: :-o-: :-o-: showHDToggleOff ' + TVEUtil.TURNERPLAYER.getBitrateId());
		if (TVEUtil.TURNERPLAYER.getBitrateId() == TVEUtil.standardBitrateId) {
			$("#hdstatus").attr("src", "tools/img/btn-hd-off.gif");
			$("#toggleIMG").css("display", "none");
		}
		else {
			HQ.showHDToggleOn();
		}
	},
	switchHD: function(newRate){
		if (TVEUtil.newRate == TVEUtil.switchingState) {
			theLoadingButton();
		}
		else 
			if (TVEUtil.newRate == TVEUtil.standardBitrateId) {
				HQ.showHDToggleOff();
			}
			else 
				if (TVEUtil.newRate == TVEUtil.hqBitrateId) {
					HQ.showHDToggleOn();
				}
	},
	hqReady: function(){
		var currentBitrateId = TVEUtil.TURNERPLAYER.getBitrateId();
		var isSwitching = false;
		Utilities.log('!!!!!! hqReady: ' + currentBitrateId + ' : ' + TVEUtil.switchingState + ' :: ' + TVEUtil.standardBitrateId + ' : ' + TVEUtil.hqBitrateId + ' ::: ' + TVEUtil.TURNERPLAYER.getBitrateId());
		if (currentBitrateId == TVEUtil.standardBitrateId) {
			isSwitching = TVEUtil.TURNERPLAYER.setBitrateId(TVEUtil.hqBitrateId);
			HQ.showHDToggleOn();
			TVEUtil.bIsHD = true;
			Utilities.log('@@@@@@ c=s: ' + TVEUtil.TURNERPLAYER.getBitrateId() + '==' + HQ.standardBitrateId);
		}
		else 
			if (currentBitrateId == TVEUtil.hqBitrateId) {
				isSwitching = TVEUtil.TURNERPLAYER.setBitrateId(TVEUtil.standardBitrateId);
				HQ.showHDToggleOff();
				TVEUtil.bIsHD = false;
				Utilities.log('###### c=h: ' + TVEUtil.TURNERPLAYER.getBitrateId() + '==' + HQ.hqBitrateId);
			}
		if (isSwitching) {
			HQ.switchHD(TVEUtil.switchingState);
		}
		Utilities.log('$$$$$$ switched: ' + currentBitrateId + ' :: ' + TVEUtil.switchingState);
	}
}

AuthError = {
	init: function(){
	},
	onAuthenticationError: function(errorType, errorMessage, errorCode){
		Utilities.log('onAuthenticationError');
		switch (errorType) {
			case "code":
				Utilities.log("Error code = " + errorType + ' | ' + errorMessage + ' | ' + errorCode);
				break;
			case "message":
				Utilities.log("Error message = " + errorType + ' | ' + errorMessage + ' | ' + errorCode);
				break;
			default:
				Utilities.log("Unknown error type: " + errorType + ' | ' + errorMessage + ' | ' + errorCode);
				break;
		}
	},
	/*	
	 getNoAuthorMessage: function(){
	 var message = 'You are not authorized to view this content. Please contact ';
	 if (TVEUtil.distributor !== 'Unspecified MVPD') {
	 message += '<em>' + TVEUtil.distributor + '</em> Customer Care';
	 }
	 else {
	 message += 'your TV provider';
	 }
	 message += ' for further assistance';
	 return message;
	 },
	 */
	getNoAuthorMessage: function(errorMessage){
		if (errorMessage) {
			message = errorMessage;
		}
		else {
			var message = 'You are not authorized to view this content. Please contact ';
			if (TVEUtil.distributor !== 'Unspecified MVPD') {
				message += '<em>' + TVEUtil.distributor + '</em> Customer Care';
			}
			else {
				message += 'your TV provider';
			}
			message += ' for further assistance.';
		}
		return message;
	},
	noAuthToView: function(errorMessage){
		if (errorMessage != undefined && errorMessage != "") {
			jQuery.facebox(errorMessage);
		}
		else {
			jQuery.facebox(AuthError.getNoAuthorMessage());
		}
		
	}
}

