(function(container) {

	var version = "0.5.3 + centering + resize + png + IE7 fix + redirect";
	var debug = true;

	if (!window.CVP) {
		// Using jresig's Class implementation http://ejohn.org/blog/simple-javascript-inheritance/
		(function(){var initializing=false, fnTest=/xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/; this.Class = function(){}; Class.extend = function(prop) { var _super = this.prototype; initializing = true; var prototype = new this(); initializing = false; for (var name in prop) { prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn){ return function() { var tmp = this._super; this._super = _super[name]; var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } function Class() { if ( !initializing && this.init ) this.init.apply(this, arguments); } Class.prototype = prototype; Class.constructor = Class; Class.extend = arguments.callee; return Class;};})();
	}


	var deleteElement = function (element) {
		while ( element.firstChild ) {
			element.removeChild( element.firstChild );
		}
		element.parentNode.removeChild( element );
	};


	var addEvent =
		document.addEventListener
		? function ( elem, type, handle ) {
				if ( elem.addEventListener ) {
					elem.addEventListener( type, handle, false );
				}
			}
		: function ( elem, type, handle ) {
				if ( elem.attachEvent ) {
					elem.attachEvent( "on" + type, handle );
				}
			};

	var removeEvent =
		document.removeEventListener
		? function ( elem, type, handle ) {
				if ( elem.removeEventListener ) {
					elem.removeEventListener( type, handle, false );
				}
			}
		: function ( elem, type, handle ) {
				if ( elem.detachEvent ) {
					elem.detachEvent( "on" + type, handle );
				}
			};

	var didResize = false;
	var onresizeHandler = function (event) {
		didResize = true;
	};
	var onresizeTimer;

	var unobserveResize = function () {
		if ( onresizeTimer ) {
			removeEvent( window, 'resize', onresizeHandler );
			window.clearInterval( onresizeTimer );
			onresizeTimer = null;
		}
	};

	var observeResize = function (callback) {
		if ( onresizeTimer ) {
			unobserveResize();
		}
		addEvent( window, 'resize', onresizeHandler );
		onresizeTimer = window.setInterval(
			function () {
				if ( didResize ) {
					didResize = false;
					callback();
				}
			},
			600
		);
	};


	if (!container.CVP) {
		window.CVP = {};
		var Class = this.Class;
		var slice = function(arr, index) {
			return Array.prototype.slice.call(arr, index || 0);
		};
		var extend = function (target, source) {
			if (!target) target = {};
			for (var p in source) {
				target[p] = source[p];
			}
			return target;
		};
		var undef = function(obj) {
			return obj == undefined;
		};

	} else {
		var Class = CVP.Class;
		var slice = CVP.Utils.slice;
		var extend = CVP.Utils.extend;
		var undef = CVP.Utils.undef;
	}

	var log = function() {
		if (window.console
			&& window.console.log
			&& debug) {
			window.console.log(slice(arguments).join(" | "));
		}
	};

	var createRedirectUrl = function (redirect_url) {
		// ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
		var re_url = /^([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,
			re_url_result = [],
			location = '',
			query = '',
			fragment = '',
			cbr = '',
			hr = '',
			min = '',
			sec = '',
			pad = function (num) { return ('' + (num < 10 ? '0' : '') + num); },
			date;

		url = window.location.href;  // I believe this is the default if not provided

		if ( !redirect_url || String(redirect_url).indexOf('/') === -1 ) {  // if the provided param is not a path
			redirect_url = url;  // ... use the current location instead.
		}

		if ( url.indexOf('#') !== -1 ) {  // if it has a hash, we add a cache-busting query string
			date = new Date();
			hr = pad(date.getHours());
			min = pad(date.getMinutes());
			sec = pad(date.getSeconds());
			cbr = '_=' + hr + min + sec;
			re_url_result = re_url.exec( url );
			if ( re_url_result ) {
				location = re_url_result[1];
				query = re_url_result[2];
				if (query) {
					query = query.replace(/&?_=\d+/g, '');
				}
				fragment = re_url_result[3];
				redirect_url = ''
					+ location
					+ '?' + ( query ? query + '&' : '' ) + cbr
					+ '#' + fragment
				;
			}
		}

		return redirect_url;
	};


	// 3rd party dependencies

	var AUTH_adobeFlash = container.AUTH_adobeFlash = "AUTHADOBEFLASH";
	var AUTH_adobeHTML5 = container.AUTH_adobeHTML5 = "AUTHADOBEHTML5";

	var CVPAuthManager = CVP.AuthManager = Class.extend({

		_version_: version,
		initReady : false,
		securityToken : null,
		authenticatedMVPD : null,
		pickerInstantiated : false,

		init : function(options)
		{
			CVP.AuthManager = this;
			this.options = extend({}, options || {});
			this.AuthClass = this.determineAuthClass();
		},

		determineAuthClass : function() {
			if (undef(this.options.authClass)) {
				// in future iterations determine which auth class to use by testing for Apple
				// Mobile browser signature or other factors, until then, just use the
				// AdobeFlashAuth class by default
				return (new AdobeFlashAuthorization(this.options));
			} else {
				switch(this.options.authClass) {
					case AUTH_adobeFlash:
						return (new AdobeFlashAuthorization(this.options));
						break;
					case AUTH_adobeHTML5:
						return (new AdobeHTML5Authorization(this.options));
						break;
					default:
						return (new AdobeFlashAuthorization(this.options));
						break;
				}
			}
		},

		logout : function() {
			log("AuthManager","logout");
			// logs the user out of the authN provider
			if (this.initReady && !undef(this.AuthClass)) {
				return (this.AuthClass.logout());
			}
		},

		onInitReady : function() {
			log("AuthManager","initialized");
			// called after the Auth class is ready
			if (!undef(this.options.onInitReady)) {
				this.initReady = true;
				this.options.onInitReady();
			}
		},

		isAuthenticated : function() {
			log("AuthManager","isAuthenticated");
			// checks for authN, not expected to prompt login query
			if (this.initReady && !undef(this.AuthClass)) {
				this.AuthClass.isAuthenticated();
			}
		},

		getAuthentication : function(redirect_url) {
			log("AuthManager","getAuthentication");
			// gets authN, is expected to prompt login query
			// the arguement ID is being passed in right now
			// because of a bug in the AdobeFlash code
			if (this.initReady && !undef(this.AuthClass)) {
				redirect_url = createRedirectUrl(redirect_url);  // fix for hash/fragment URLs
				this.AuthClass.getAuthentication(redirect_url);
			}
		},

		checkAuthorization : function(id) {
			log("AuthManager","checkAuthorization");
			// check for authorization to a given resource
			// not expected to prompt authN login
			if (this.initReady && !undef(this.AuthClass)) {
				this.AuthClass.checkAuthorization(id);
			}
		},

		getAuthorization : function(id, redirect_url) {
			log("AuthManager","getAuthorization");
			// get the authorization for a given resource
			// ideally this should only be called after the
			// user is verified to be authenticated
			if (this.initReady && !undef(this.AuthClass)) {
				redirect_url = createRedirectUrl(redirect_url);  // fix for hash/fragment URLs
				this.AuthClass.getAuthorization(id, redirect_url);
			}
		},

		getAccessToken : function(prepend, append) {
			log("AuthManager","getAccessToken");
			// gets the full access token object that needs
			// to be sent on to the video player
			if (this.initReady && !undef(this.AuthClass)) {
				return this.AuthClass.getAccessToken(prepend, append);
			}
		},

		selectProvider : function(id) {
			log("AuthManager","selectProvider");
			// allows the user to select the provider
			if (this.initReady && !undef(this.AuthClass)) {
				return this.AuthClass.selectProvider(id);
			}
		},

		getProvider : function() {
			log("AuthManager","getProvider");
			// allows the user to find out the authentication status synchronously
			if (this.initReady && !undef(this.AuthClass)) {
				return (this.AuthClass.getProvider());
			}
		},

		getProviderID : function() {
			log("AuthManager", "getProviderID");
			// allows the user to retrieve the specific provider id sychronously
			if (this.initReady && !undef(this.AuthClass)) {
				return (this.AuthClass.getProviderID());
			}
		},

		defaultPropertyPicker : function(props) {
			var mvpdobj = this.getProvider(),
				backer = document.getElementById('cvp_backer'),
				pp = document.getElementById('cvp_props');
			if (backer) {
				backer.style.display = 'block';
			} else {
				backer = document.createElement('div');
				backer.setAttribute('id','cvp_backer');
				backer.style.position = 'fixed';
				backer.style.top = '0px';
				backer.style.left = '0px';
				backer.style.backgroundColor = '#000000';
				backer.style.width = '100%';
				backer.style.height = '100%';
				backer.style.opacity = '0.5';
				backer.style.zIndex = '1999';
				backer.style.filter = 'alpha(opacity=50)';
				backer.style.display = 'block';
				backer.onclick = CVP.AuthManager.cancelPickerDiv;
				document.body.appendChild(backer);
			}
			if (pp) {
				pp.style.display = 'none';
			} else {
				pp = document.createElement('div');
				pp.setAttribute('id','cvp_props');
				pp.style.position = 'fixed';
				pp.style.top = '50px';
				pp.style.left = '50px';
				pp.style.width = '408px';
				pp.style.zIndex = '2000';
				pp.style.display = 'none';
				document.body.appendChild(pp);
			}
			var divFill = "";
			divFill += '<div id="pickerTop" style="padding-top: 5px; padding-bottom: 5px; width: 404px; height: 40px; background-color: #081738; border: 2px solid #FFFFFF; border-top-right-radius: 15px; border-top-left-radius: 15px; height: 40px; font-family: Arial; color: #FFFFFF; font-size: 11pt; font-weight: bold;">Please select your TV service<br>provider from the list below.</div>';
			divFill += '<table style="background-color: #FFFFFF;" border="0" cellpadding="0" cellspacing="0">';
			props.sort(function(a,b) { x = a.ID.toUpperCase(); y = b.ID.toUpperCase(); if (x < y) return -1; if (x == y) return 0; if (x > y) return 1;});
			for (var i = 0; i < props.length; i++) {
				if (i % 2 == 0)
					divFill += '<tr>';
				divFill += '<td><div style="padding: 5px 0px 5px 0px; cursor: pointer;';
				if (props[i].ID == mvpdobj.MVPD)
					divFill += 'background-color: grey;';
				else
					divFill += 'background-color: #FFFFFF;';
				divFill += ' width: 200px; border: 2px solid #FFFFFF;" onclick="CVP.AuthManager.cancelPicker(true); CVP.AuthManager.selectProvider(\'' + props[i].ID + '\');"><center><img style="background-color: #FFFFFF; padding: 5px;" border="no" src="' + props[i].logoURL + '"></center></div></td>';
				if (i % 2 != 0 || i == props.length - 1)
					divFill += '</tr>';
			}
			divFill += '</table><div id="pickerBottom" style="width: 404px; padding-top: 10px; height: 30px; background-color: #081738; border: 2px solid #FFFFFF; border-bottom-right-radius: 15px; border-bottom-left-radius: 15px;"><input type="button" value="Cancel" onclick="CVP.AuthManager.cancelPicker(false);"></div>';
			pp.innerHTML = divFill;
			this.pickerInstantiated = true;
			this.centerElement(pp, 404, 400);
			observeResize(function () {
				CVP.AuthManager.centerElement( pp, 404, 400 );
			});
		},

		cancelPickerDiv : function() {
			CVP.AuthManager.cancelPicker(false);
		},

		cancelPicker : function(flip) {
			if (!flip) {
				this.selectProvider(null);
			}
			this.pickerInstantiated = false;
			document.getElementById('cvp_props').style.display = 'none';
			document.getElementById('cvp_backer').style.display = 'none';
			unobserveResize();
		},

		centerElement: function (domElement, width, height) {
			var domElemStyle,
				p_width = width || 0,
				p_height = height || 0,
				elementWidth = 0,
				elementHeight = 0,
				leftOffset = 0,
				topOffset = 0,
				scrolledX = 0,
				scrolledY = 0,
				viewportX = 0,
				viewportY = 0,
				docEl = document.documentElement,
				docBody = document.body;

			if ( typeof domElement === 'string' ) {
				// just in case someone passed an id instead of an element
				domElement = document.getElementById(domElement);
			}

			if ( domElement ) {

				domElemStyle = domElement.style;

				if ( window.getComputedStyle ) {
				  elementWidth = window.getComputedStyle( domElement, null ).getPropertyValue('width');
				  elementHeight = window.getComputedStyle( domElement, null ).getPropertyValue('height');
				} else if ( domElement.currentStyle ) {
				  elementWidth = domElement.currentStyle.width;
				  elementHeight = domElement.currentStyle.height;
				} else if ( domElement.offsetHeight ) {
					elementWidth = domElement.offsetWidth;
					elementHeight = domElement.offsetHeight;
				} else if ( domElemStyle.height ) {
					elementWidth = domElemStyle.width;
					elementHeight = domElemStyle.height;
				}

				elementWidth = parseInt( elementWidth, 10 );
				elementHeight = parseInt( elementHeight, 10 );

				// if it doesn't parse or the value is "auto", fallback to params
				if ( isNaN(elementWidth) ) {
					elementWidth = p_width;
				}
				if ( isNaN(elementHeight) ) {
					elementHeight = p_height;
				}

				if ( window.pageYOffset ) {
					scrolledX = window.pageXOffset;
					scrolledY = window.pageYOffset;
				} else if ( docEl && docEl.scrollTop ) {
					scrolledX = docEl.scrollLeft;
					scrolledY = docEl.scrollTop;
				} else if ( docBody ) {
					scrolledX = docBody.scrollLeft;
					scrolledY = docBody.scrollTop;
				}

				if ( window.innerHeight ) {
					viewportX = window.innerWidth;
					viewportY = window.innerHeight;
				} else if ( docEl && docEl.clientHeight ) {
					viewportX = docEl.clientWidth;
					viewportY = docEl.clientHeight;
				} else if ( docBody ) {
					viewportX = docBody.clientWidth;
					viewportY = docBody.clientHeight;
				}

				// defaults are set just away from viewport edge
				// defaults are used if element is larger than viewport
				leftOffset = scrolledX + 2;
				topOffset = scrolledY + 2;

				if ( viewportX > elementWidth ) {
					leftOffset = scrolledX + (viewportX / 2) - (elementWidth / 2);
				}
				if ( viewportY > elementHeight ) {
					topOffset = scrolledY + (viewportY / 2) - (elementHeight / 2);
				}

				domElemStyle.position = 'absolute';
				domElemStyle.top = '' + topOffset + 'px';
				domElemStyle.left = '' + leftOffset + 'px';
				domElemStyle.display = 'block';
			}
		}

	});

	var AdobeFlashAuthorization = window.AdobeFlashAuthorization = Class.extend({
		init : function(options)
		{
			log("AuthManager","AdobeFlashAuthorization","initialized");
			// set the methods that the Adobe flash needs to use to be accessible at the
			// container level
			this.externalizeCallbacks();
			// copy the options from the manager class so we don't always have to
			// call backwards
			this.options = extend({}, options || {});

			// during the init, create the div that the swf should be loaded into
			var bodyElement = document.getElementsByTagName('body')[0];
			var swfContainer = document.createElement('div');
			swfContainer.setAttribute('id','AccessEnabler');
			bodyElement.appendChild(swfContainer);

			var swfptr = null;
			if (!undef(this.options.swfobject))
				swfptr = this.options.swfobject
			else
				swfptr = CVP.swfobject;
			// use the core CVP method to get the swf on the page but give the client the
			// ability to choose where it gets placed with a swfStyleOverride
			if (undef(this.options.swfStyleOverride)) {
				swfptr.embedSWF(this.options.adobeSwfURL, "AccessEnabler", 5, 5, "10.1.53.64",
					null, null, { bgcolor: "#000000", quality: "high", wmode: "transparent", align: "middle", allowScriptAccess: "always"},
					{id: "AccessEnabler", name: "AccessEnabler", style: "z-index: 500;"});
			} else {
				swfptr.embedSWF(this.options.adobeSwfURL, "AccessEnabler", this.options.swfStyleOverride.width, this.options.swfStyleOverride.height, "10.1.53.64",
					null, null, { bgcolor: "#000000", quality: "high", wmode: "transparent", align: "middle", allowScriptAccess: "always"},
					{id: "AccessEnabler", name: "AccessEnabler", style: this.options.swfStyleOverride.style});
			}
		},

		externalizeCallbacks : function() {
			// this takes all the internal methods for adobe callbacks and gets
			// them accessible at the container level where adobe looks for them
			container.swfLoaded = this._adobeCallback_swfLoaded;
			container.setAuthenticationStatus = this._adobeCallback_setAuthenticationStatus;
			container.setToken = this._adobeCallback_setToken;
			container.tokenRequestFailed = this._adobeCallback_tokenRequestFailed;
			container.displayProviderDialog = this._adobeCallback_displayProviderDialog;
			container.sendTrackingData = this._adobeCallback_sendTrackingData;
			container.createIFrame = this._adobeCallback_createIFrame;
			container.setMovieDimensions = this._adobeCallback_setMovieDimensions;
		},

		isAuthenticated : function() {
			log("AuthManager","AdobeFlashAuthorization","isAuthenticated");
			// pokes the swf for the check authN method
			// this method will check if the client is logged in with the provider
			// and will not prompt login
			this.swfPointer.checkAuthentication();
		},

		getAuthentication : function(redirect_url) {
			log("AuthManager","AdobeFlashAuthorization","getAuthentication");
			// slight bug with adobe as they don't actually offer a get authN method
			// so this method actually calls get authZ
			// other adobe bugs will force our page to be reloaded anyway so
			// this bug is transparent to the customer
			this.swfPointer.getAuthentication(redirect_url);
		},

		checkAuthorization : function(id) {
			log("AuthManager","AdobeFlashAuthorization","checkAuthorization");
			// this will return a token or a failure but will never prompt login
			if (this.providerCheck(id)) {
				this.swfPointer.checkAuthorization(id);
			}
		},

		getAuthorization : function(id, redirect_url) {
			log("AuthManager","AdobeFlashAuthorization","getAuthorization");
			// this will return a token or a failure and will prompt login if authN fails
			if (CVP.AuthManager.pickerInstantiated == true) {
				CVP.AuthManager.cancelPicker(false);
			}
			if (this.providerCheck(id)) {
				this.swfPointer.getAuthorization(id, redirect_url);
			}
		},

		getAccessToken : function(prepend, append) {
			log("AuthManager","AdobeFlashAuthorization","getAccessToken");
			// returns the token object that the player needs to send to CVP
			var token = CVP.AuthManager.token;
			if (undef(prepend) == false) {
				log("AuthManager","AdobeFlashAuthorization","getAccessToken :: prepend :: " + prepend);
				token = prepend + token;
			}
			if (undef(append) == false) {
				log("AuthManager","AdobeFlashAuthorization","getAccessToken :: append :: " + append);
				token = token + append;
			}
			return ({'accessToken':token, 'accessTokenType':'Adobe'});
		},

		selectProvider : function(id) {
			log("AuthManager","AdobeFlashAuthorization","select provider");
			// allows the customer to set the provider from the custom picker
			this.swfPointer.setSelectedProvider(id);
		},

		getProvider : function() {
			log("AuthManager","AdobeFlashAuthorization","get provider");
			return this.swfPointer.getSelectedProvider();
		},

		getProviderID : function() {
			log("AuthManager", "AdobeFlashAuthorization","get provider id");
			var obj = this.swfPointer.getSelectedProvider();
			if (obj == null) return "";
			log("AuthManager", "AdobeFlashAuthorization",("get provider id :: MVPD = " + obj.MVPD + " :: STATE = " + obj.AE_STATE));
			return obj.MVPD;
		},

		providerCheck : function(resource) {
			log("AuthManager","AdobeFlashAuthorization","provider check");
			if (undef(this.options.providerWhitelist)) {
				return true;
			}
			else {
				var aeMVPDObject = this.swfPointer.getSelectedProvider();
				if (aeMVPDObject == null) return true;
				if (aeMVPDObject.AE_State == 'User Authenticated') {
					if (undef(this.options.providerWhitelist[aeMVPDObject.MVPD])) {
						tokenRequestFailed(resource, 'code', 'NOT PROPER AUTHENTICATION');
						return false;
					}
				}
				return true;
			}
		},

		logout : function() {
			log("AuthManager","AdobeFlashAuthorization","logout");
			// logs the user out, adobe refreshes page
			this.swfPointer.logout();
		},

		_adobeCallback_swfLoaded : function() {
			log("AuthManager","AdobeFlashAuthorization","callback - swf loaded");
			// setup a pointer to the swf object, set the requestor, set the custom picker
			// if beings used and then callback to initReady
			CVP.AuthManager.AuthClass.swfPointer = document.getElementById('AccessEnabler');
			CVP.AuthManager.AuthClass.swfPointer.setRequestor(CVP.AuthManager.options.clientId);
			if (undef(CVP.AuthManager.options.onCustomMVPDPicker) == false) {
				CVP.AuthManager.AuthClass.swfPointer.setProviderDialogURL('http://www.turner.com/index.html');
			}
			CVP.AuthManager.onInitReady();
		},

		_adobeCallback_setToken : function(resource, token) {
			log("AuthManager","AdobeFlashAuthorization","callback - set token");
			// set the token and call back to success method
			CVP.AuthManager.token = token;
			CVP.AuthManager.options.onAuthorizationPassed(resource);
		},

		_adobeCallback_tokenRequestFailed : function(resource, errorCode, errorString) {
			log("AuthManager","AdobeFlashAuthorization","callback - token request failed");
			// passthrough
			if (undef(errorString))
				errorString = 'You are not authorized to view this content. Please contact your TV provider for further assistance.';
			CVP.AuthManager.options.onAuthorizationFailed(resource, errorCode, errorString);
		},

		_adobeCallback_setAuthenticationStatus : function(isAuthenticated, errorCode) {
			log("AuthManager","AdobeFlashAuthorization","callback - set authentication status");
			if (isAuthenticated == 0) {
				CVP.AuthManager.options.onAuthenticationFailed(errorCode);
			}
			if (isAuthenticated == 1) {
				CVP.AuthManager.options.onAuthenticationPassed();
			}
		},

		_adobeCallback_sendTrackingData : function(eventType, trackingData) {
			log("AuthManager","AdobeFlashAuthorization","callback - send tracking data :: eventType : " + eventType + "; trackingData : " + trackingData);
			// passthrough
			CVP.AuthManager.options.onTrackingData(eventType, trackingData);
		},

		_adobeCallback_displayProviderDialog : function(providers) {
			log("AuthManager","AdobeFlashAuthorization","callback - display provider dialog");
			// passthrough
			if (undef(CVP.AuthManager.options.providerWhitelist))
				CVP.AuthManager.options.onCustomMVPDPicker(providers);
			else {
				var retlist = new Array();
				for (var i = 0; i < providers.length; i++) {
					if (undef(CVP.AuthManager.options.providerWhitelist[providers[i].ID]) == false) {
						retlist.push(providers[i]);
					}
				}
				CVP.AuthManager.options.onCustomMVPDPicker(retlist);
			}
		},

		_adobeCallback_createIFrame : function(width, height) {
			var iframe, iframeStyle, iframeContainer, iframeContainerStyle, backer, backerStyle, closeButton, closeButtonStyle;
			log("AuthManager","AdobeFlashAuthorization","callback - create iframe");
			// build the iframe for the provider that might use iframe (verizon)
			// allow style override
			backer = document.getElementById('cvp_backer');
			if (!backer) {
				backer = document.createElement('div');
				backerStyle = backer.style;
				backer.setAttribute('id','cvp_backer');
				backerStyle.position = 'fixed';
				backerStyle.top = '0px';
				backerStyle.left = '0px';
				backerStyle.backgroundColor = '#000000';
				backerStyle.width = '100%';
				backerStyle.height = '100%';
				backerStyle.opacity = '0.4';
				backerStyle.zIndex = '1999';
				backerStyle.filter = 'alpha(opacity=40)';
				document.body.appendChild(backer);
			}
			backer.onclick = null;
			backer.style.display = 'block';
			iframeContainer = document.getElementById('mvpddiv');
			iframe = document.getElementById('mvpdframe');
			if (iframeContainer) {
				iframeContainerStyle = iframeContainer.style;
				iframeContainerStyle.width = '' + width + 'px';
				iframeContainerStyle.height = '' + height + 'px';
			} else {
				iframeContainer = document.createElement('div');
				iframeContainerStyle = iframeContainer.style;
				iframeContainer.setAttribute('id','mvpddiv');
				if (undef(CVP.AuthManager.AuthClass.options.iframeStyleOverride)) {
					iframeContainerStyle.position = 'absolute';
					iframeContainerStyle.top = '50px';
					iframeContainerStyle.zIndex = '2000';
					iframeContainerStyle.width = '' + width + 'px';
					iframeContainerStyle.height = '' + height + 'px';
					iframeContainerStyle.marginLeft = '0';
					iframeContainerStyle.backgroundColor = 'white';
					iframeContainerStyle.borderRadius = '4px';
					iframeContainerStyle.boxShadow = '4px 4px 8px #111';
				} else {
					iframeContainer.className = CVP.AuthManager.AuthClass.options.iframeStyleOverride;
				}
				closeButton = document.createElement('span');
				if (undef(CVP.AuthManager.AuthClass.options.closeButtonStyleOverride)) {
					closeButtonStyle = closeButton.style;
					closeButtonStyle.backgroundImage = 'url("http://i.cdn.turner.com/xslo/cvp/js/cvp.auth/close.png")';
					closeButtonStyle.backgroundRepeat = 'no-repeat';
					closeButtonStyle.zIndex = '1000';
					closeButtonStyle.position = 'absolute';
					closeButtonStyle.top = '3px';
					closeButtonStyle.right = '3px';
					closeButtonStyle.width = '54px';
					closeButtonStyle.height = '14px';
					closeButtonStyle.cursor = 'pointer';
				} else {
					closeButton.className = CVP.AuthManager.AuthClass.options.closeButtonStyleOverride;
				}
				closeButton.onclick = function () {
					var iframe = document.getElementById('mvpdframe');
					if (iframe) {
						// iframe.src = 'about:blank';  // kill the content of the iframe
						// iframeContainer.removeChild(iframe);
						deleteElement( iframe );
						try {
							delete window.frames["mvpdframe"];  // kill reference Adobe uses from Firefox [Bug 170799]
						} catch (e) {
						}
						// iframe.style.display = 'none';
					}
					iframeContainer.style.display = 'none';  // hide the iframe container
					CVP.AuthManager.selectProvider(null);  // working in SWF 1.3
					backer.style.display = 'none';  // hide the fade-out background
					unobserveResize();  // stop watching resize to center div
				};
				iframeContainer.appendChild(closeButton);
				document.body.appendChild(iframeContainer);
			}
			if (iframe) {
				iframeStyle = iframe.style;
				iframeStyle.width = '' + width + 'px';
				iframeStyle.height = '' + height + 'px';
				// iframe.style.display = 'block';
			} else {
				iframe = document.createElement("IFRAME");
				iframeStyle = iframe.style;
				iframeStyle.width = '' + width + 'px';
				iframeStyle.height = '' + height + 'px';
				iframeStyle.border = '0';
				iframe.name = "mvpdframe";
				iframe.id = "mvpdframe";
				iframe.scrolling = 'no';
				iframeContainer.appendChild(iframe);
				window.frames["mvpdframe"].name = "mvpdframe";// Force the name into the DOM since it is still not refreshed, for IE
				// iframe.style.display = 'block';
			}
			CVP.AuthManager.centerElement( iframeContainer, width, height );
			observeResize(function () {
				CVP.AuthManager.centerElement( iframeContainer, width, height );
			});
		},

		_adobeCallback_setMovieDimensions : function(width, height) {
			log("AuthManager","AdobeFlashAuthorization","callback - set movie dimensions :: " + width + "x" + height);
			// this sets the movie dimensions for the swf, usually called
			// when not doing a custom picker
			if (undef(CVP.AuthManager.options.onCustomMVPDPicker)) {
				// adobe has a bug where they're calling the movie dimension
				// method when they shouldn't be (during non-swf custom picker)
				CVP.AuthManager.AuthClass.swfPointer.width = width;
				CVP.AuthManager.AuthClass.swfPointer.height = height;
			}
		}

	});

	var AdobeHTML5Authorization = window.AdobeHTML5Authorization = Class.extend({
		src : ('http://teg8fdev1.turner.com:7777/adobe/ae_html5/AccessEnabler.html#' + encodeURIComponent(document.location.href)),
		selectedProvider : null,
		init : function(options)
		{
			log("AuthManager","AdobeHTML5Authorization","init");
            // Append the Iframe into the DOM.
            iframe = $( '<iframe " src="' + this.src + '"><\/iframe>' ).appendTo( '#iframe' );
			$.receiveMessage(
				function(message) {
					log("AuthManager","AdobeHTML5Authorization","received postmessage");
					var parsedMessage = $.parseQuery(message.data);
					switch(parsedMessage.method) {
						case 'init':
							log("AuthManager","AdobeHTML5Authorization","received postmessage :: init");
							$.postMessage({method: "setRequestor", params: CVP.AuthManager.options.clientId}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
							$.postMessage({method: "setDomain", params: 'tnt.tv'}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
							CVP.AuthManager.onInitReady();
							break;
						case 'checkAuthentication':
							log("AuthManager","AdobeHTML5Authorization","received postmessage :: checkAuthentication");
							CVP.AuthManager.AuthClass.checkAuthentication(parsedMessage.params);
							break;
						case 'navigateToURL':
							log("AuthManager","AdobeHTML5Authorization","received postmessage :: navigateToURL");
							window.location.href = parsedMessage.params;
							break;
						case 'log':
							logToAd(parsedMessage.params,true);
							break;
						case 'providerList':
							log("AuthManager","AdobeHTML5Authorization","received postmessage :: providerList");
							// break apart laziness
							var retAr = new Array();
							var pat = parsedMessage.params.split("!!**!!");
							for (var i = 0; i < pat.length; i++) {
								var mat = pat[i].split("*!*");
								var obj = new Object();
								obj.ID = mat[0];
								obj.logoURL = mat[1];
								obj.displayName = mat[2];
								retAr.push(obj);
							}
							CVP.AuthManager.AuthClass.displayProviders(retAr);
							break;
						case 'setToken':
							logToAd("From Adobe: AUTHZ Token<br>"+parsedMessage.params);
							log("AuthManager","AdobeHTML5Authorization","received postmessage :: setToken");
							CVP.AuthManager.token = parsedMessage.params;
							CVP.AuthManager.options.onAuthorizationPassed(CVP.AuthManager.options.clientId);
							break;
						case 'error':
							log("AuthManager","AdobeHTML5Authorization","received postmessage :: error");
							alert("ERROR - " + parsedMessage.params);
							break;
					}
				},
				'http://teg8fdev1.turner.com:7777'
			);
		},

		getAccessToken : function(prepend, append) {
			log("AuthManager","AdobeHTML5Authorization","getAccessToken");
			// returns the token object that the player needs to send to CVP
			var token = CVP.AuthManager.token;
			if (undef(prepend) == false) {
				log("AuthManager","AdobeFlashAuthorization","getAccessToken :: prepend :: " + prepend);
				token = prepend + token;
			}
			if (undef(append) == false) {
				log("AuthManager","AdobeFlashAuthorization","getAccessToken :: append :: " + append);
				token = token + append;
			}
			return ({'accessToken':token, 'accessTokenType':'Adobe'});
		},

		selectProvider : function(id) {
			log("AuthManager","AdobeHTML5Authorization","select provider");
			// allows the customer to set the provider from the custom picker
			if (id != null) {
				this.selectedProvider = id;
				$.postMessage({method: "setSelectedProvider", params: id}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
				CVP.AuthManager.getAuthentication(CVP.AuthManager.options.clientId);
			}
		},

		isAuthenticated : function() {
			log("AuthManager","AdobeHTML5Authorization","isAuthenticated");
			// pokes the swf for the check authN method
			// this method will check if the client is logged in with the provider
			// and will not prompt login
			$.postMessage({method: "checkAuthentication", params: null}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
		},

		checkAuthentication : function(authenticationToken) {
			log("AuthManager","AdobeHTML5Authorization","checkAuthentication return");
			if (undef(authenticationToken) || authenticationToken == '') {
				CVP.AuthManager.options.onAuthenticationFailed();
			} else {
				CVP.AuthManager.options.onAuthenticationPassed();
			}
		},

		getAuthentication : function(id) {
			log("AuthManager","AdobeHTML5Authorization","getAuthentication");
			if (this.selectedProvider == null) {
				$.postMessage({method: "getProviderList", params: CVP.AuthManager.options.clientId}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
				return true;
			}
			// slight bug with adobe as they don't actually offer a get authN method
			// so this method actually calls get authZ
			// other adobe bugs will force our page to be reloaded anyway so
			// this bug is transparent to the customer
			$.postMessage({method: "getAuthentication", params: id}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
		},

		checkAuthorization : function(id) {
			log("AuthManager","AdobeHTML5Authorization","checkAuthorization");
			// this will return a token or a failure but will never prompt login
			if (this.providerCheck(id)) {
				this.swfPointer.checkAuthorization(id);
			}
		},

		getAuthorization : function(id) {
			log("AuthManager","AdobeHTML5Authorization","getAuthorization");
			// this will return a token or a failure and will prompt login if authN fails
			if (CVP.AuthManager.pickerInstantiated == true) {
				CVP.AuthManager.cancelPicker(false);
			}
			if (this.providerCheck(id)) {
				$.postMessage({method: "getAuthorization", params: id}, CVP.AuthManager.AuthClass.src, iframe.get(0).contentWindow);
			}
		},

		displayProviders : function(providers) {
			log("AuthManager","AdobeHTML5Authorization","callback - display provider dialog");
			// passthrough
			if (undef(CVP.AuthManager.options.providerWhitelist))
				CVP.AuthManager.options.onCustomMVPDPicker(providers);
			else {
				var retlist = new Array();
				for (var i = 0; i < providers.length; i++) {
					if (undef(CVP.AuthManager.options.providerWhitelist[providers[i].ID]) == false) {
						retlist.push(providers[i]);
					}
				}
				CVP.AuthManager.options.onCustomMVPDPicker(retlist);
			}
		},

		providerCheck : function(resource) {
			log("AuthManager","AdobeHTML5Authorization","provider check");
			return true;
			if (undef(this.options.providerWhitelist)) {
				return true;
			}
			else {
				var aeMVPDObject = this.swfPointer.getSelectedProvider();
				if (aeMVPDObject.AE_State == 'User Authenticated') {
					if (undef(this.options.providerWhitelist[aeMVPDObject.MVPD])) {
						tokenRequestFailed(resource, 'code', 'NOT PROPER AUTHENTICATION');
						return false;
					}
				}
				return true;
			}
		}

	});


})(window);



