(function() {
				var checkJWReady = setInterval( function() {
					console.log("AMI jwp init jwplayer_wJC05Aa7_Bk5vyVYE_div");
					if ("undefined" !== typeof jwplayer ) {
						clearInterval(checkJWReady);
						if(typeof(jQuery)=="function"){(function($){$.fn.fitVids=function(){}})(jQuery)};
						var el = decodeURIComponent( "jwplayer_wJC05Aa7_Bk5vyVYE_div" );
						var mHash = "ami" + decodeURIComponent( "wJC05Aa7" );
						window.jwpDef[mHash] = JSON.parse( decodeURIComponent( "%7B%22setTimeEvents%22%3Atrue%2C%22ph%22%3A2%2C%22playlist%22%3A%22https%3A%5C%2F%5C%2Fcontent.jwplatform.com%5C%2Ffeeds%5C%2FwJC05Aa7.json%22%2C%22plugins%22%3A%7B%22https%3A%5C%2F%5C%2Fsb.scorecardresearch.com%5C%2Fc2%5C%2Fplugins%5C%2Fstreamingtag_plugin_jwplayer.js%22%3A%5B%5D%2C%22https%3A%5C%2F%5C%2Fovp.iris.tv%5C%2Fplugins%5C%2Fjwplayer%5C%2Fv2%5C%2Firis-jwplayer8.adaptive.min.js%22%3A%7B%22settings%22%3A%7B%22client_token%22%3A%22nvonvsnnlg8c%22%2C%22platform_id%22%3A%22wJC05Aa7%22%2C%22player_id%22%3A%22jwplayer_wJC05Aa7_Bk5vyVYE_div%22%2C%22end_up_next%22%3Atrue%2C%22ssl%22%3Atrue%2C%22campaign_tracking%22%3Atrue%2C%22disable_mobile_upnext%22%3Afalse%7D%2C%22iris_buttons%22%3A%7B%22thumbs_up%22%3Afalse%2C%22thumbs_down%22%3Afalse%2C%22skip_forward%22%3Afalse%2C%22skip_back%22%3Afalse%2C%22skip_on_thumbs_down%22%3Afalse%7D%2C%22global%22%3A%22iris%22%2C%22jwCMS%22%3Atrue%7D%7D%2C%22nextUpDisplay%22%3Afalse%7D" ) );
						var videoParams   = JSON.parse( decodeURIComponent( "%7B%22setTimeEvents%22%3Atrue%2C%22ph%22%3A2%2C%22playlist%22%3A%22https%3A%5C%2F%5C%2Fcontent.jwplatform.com%5C%2Ffeeds%5C%2FwJC05Aa7.json%22%2C%22plugins%22%3A%7B%22https%3A%5C%2F%5C%2Fsb.scorecardresearch.com%5C%2Fc2%5C%2Fplugins%5C%2Fstreamingtag_plugin_jwplayer.js%22%3A%5B%5D%2C%22https%3A%5C%2F%5C%2Fovp.iris.tv%5C%2Fplugins%5C%2Fjwplayer%5C%2Fv2%5C%2Firis-jwplayer8.adaptive.min.js%22%3A%7B%22settings%22%3A%7B%22client_token%22%3A%22nvonvsnnlg8c%22%2C%22platform_id%22%3A%22wJC05Aa7%22%2C%22player_id%22%3A%22jwplayer_wJC05Aa7_Bk5vyVYE_div%22%2C%22end_up_next%22%3Atrue%2C%22ssl%22%3Atrue%2C%22campaign_tracking%22%3Atrue%2C%22disable_mobile_upnext%22%3Afalse%7D%2C%22iris_buttons%22%3A%7B%22thumbs_up%22%3Afalse%2C%22thumbs_down%22%3Afalse%2C%22skip_forward%22%3Afalse%2C%22skip_back%22%3Afalse%2C%22skip_on_thumbs_down%22%3Afalse%7D%2C%22global%22%3A%22iris%22%2C%22jwCMS%22%3Atrue%7D%7D%2C%22nextUpDisplay%22%3Afalse%2C%22advertising%22%3A%7B%22schedule%22%3A%5B%5D%7D%7D" ) );

						console.log("AMI jwp params", videoParams);
						if ( videoParams.advertising ) {
							console.log("AMI jwp ad params", videoParams.advertising);
						}
						var vHash = "ami" + decodeURIComponent( "wJC05Aa7" );
						if ( window.jwpDef[vHash].advertising ) {
							if ( window.jwpDef[vHash].advertising.schedule ) {
								if ( window.jwpDef[vHash].advertising.schedule[0].tag ) {
									if ( typeof window.jwVastTag[vHash] === "undefined" ){
										window.jwVastTag[vHash] = window.jwpDef[vHash].advertising.schedule[0].tag;
										var vastURL = new URL( window.jwVastTag[vHash] );
									    var vastParams = new URLSearchParams( vastURL.search );
									    var ui = vastParams.get( "iu" ).split( "/" );
									    window.prerollTag[vHash] = vastParams.get( "iu" );
									    window.prerollTag[vHash] = vastParams.get( "iu" );
									    window.jwpBids[vHash] = {};
									    console.log("AMI jwp", window.jwpBids);
									    console.log("AMI jwp prerolltag", window.prerollTag[vHash]);
									    console.log("AMI jwp GAM Tag", window.jwVastTag[vHash]);
									}
								}
							}
						}
						function performAsyncBidding(player, item, index) {
							var el = decodeURIComponent( "jwplayer_wJC05Aa7_Bk5vyVYE_div" );
							var vHash = "ami" + decodeURIComponent( "wJC05Aa7" );
							let url = window.jwVastTag[vHash];

							var utms = {};
						    if ( adsParseUrlParams( "utm_source" ) || typeof getCookie("utm_source") !== "undefined" ) {
						        var utm_source;
						        if(adsParseUrlParams( "utm_source" )){
						            utm_source = adsParseUrlParams( "utm_source" );
						            setCookie("utm_source", utm_source, {expires:1800, path: "/"});
						        } else {
						            utm_source = getCookie("utm_source");
						        }
						        utms.utm_source = utm_source;
						    }

						    if ( adsParseUrlParams( "utm_medium" ) || typeof getCookie("utm_medium") !== "undefined" ) {
						        var utm_medium;
						        if( adsParseUrlParams( "utm_medium" ) ){
						            utm_medium = adsParseUrlParams( "utm_medium" );
						            setCookie("utm_medium", utm_medium, {expires:1800, path: "/"});
						        } else {
						            utm_medium = getCookie("utm_medium");
						        }
						        utms.utm_medium = utm_medium;
						    }

						    if ( adsParseUrlParams( "utm_campaign" ) || typeof getCookie("utm_campaign") !== "undefined" ) {
						        var utm_campaign;
						        if(adsParseUrlParams( "utm_campaign" )){
						            utm_campaign = adsParseUrlParams( "utm_campaign" );
						            setCookie("utm_campaign", utm_campaign, {expires:1800, path: "/"});
						        } else {
						            utm_campaign = getCookie("utm_campaign");
						        }
						        utms.utm_campaign = utm_campaign ;
						    }

						    if ( typeof utms.utm_source !== "undefined" || typeof utms.utm_medium !== "undefined" || typeof utms.utm_campaign !== "undefined" ) {
						        var vastURL = new URL( window.jwVastTag[vHash] );
						        var vastParams = new URLSearchParams( vastURL.search );
						        var keys = Object.keys( utms );
						        if ( vastParams.has( "cust_params" ) ) {
						            var custParams = new URLSearchParams( vastParams.get( "cust_params" ) );
						        } else {
						            var custParams = new URLSearchParams();
						        }
					            for ( var key of keys ) {
					                custParams.set( key, utms[key]);
						        }
						        vastParams.set( "cust_params", decodeURIComponent( custParams.toString() ) );
						        vastURL.search = vastParams.toString();
						        url = vastURL.toString();
						    }

						    console.log( "AMI jwp GAM tag with UTM", url );

						    if ( localStorage._pdfps ) {
								var playerSegsPerm = encodeURIComponent("&permutive=" + encodeURIComponent(JSON.parse(localStorage._pdfps || "[]").slice(0,250).join(",")));
								url = url.replace(/(cust_params[^&]+)/, "$1" + playerSegsPerm);
						    }

						    console.log( "AMI jwp GAM tag with Permutive", url );

							


							return new Promise((resolve, reject) => {
							    let bidders = ["a9", "iris"];

				                // create a requestManager to keep track of bidder state to determine when to send ad server
				                // request and what amazonSlots to request from the ad server
				                var requestManager = {
				                    adserverRequestSent: false,
				                };

				                //loop through bidder array and add the bidders to the request manager:
				                bidders.forEach( function( bidder ) {
				                    requestManager[bidder] = false;
				                } );

				                // return true if all bidders have returned
				                function allBiddersBack() {
				                    var allBiddersBack = bidders
				                            // get the booleans from the object
				                            .map( function( bidder ) {
				                                return requestManager[bidder];
				                            } )
				                            // get rid of false values - indicates that the bidder has responded
				                            .filter( Boolean )
				                            // if length is equal to bidders, all bidders are back
				                            .length === bidders.length;

				                    return allBiddersBack;
				                }

				                // handler for header bidder responses
				                function headerBidderBack( bidder ) {
				                    // return early if request to adserver is already sent
				                    if ( requestManager.adserverRequestSent === true ) {
				                        return;
				                    }
				                    // flip bidder back flag
				                    if ( bidder === "a9" ) {
				                        requestManager.a9 = true;
				                        console.log("second promise a9 ready");
				                    } else if ( bidder === "iris" ) {
				                        requestManager.iris = true;
				                        console.log("second promise iris ready");
				                    }
				                    // if all bidders are back, send the request to the ad server
				                    if ( allBiddersBack() ) {
				                        resolve( url );
				                    }
				                }

								if ( typeof apstag == "object" && apstag ) {
					                apstag.fetchBids({
					                    slots: [{
					                        slotID: window.prerollTag[vHash],
					                        mediaType: "video"
					                    }]
					                }, function( bids ) {
					                    console.log( "AMI jwp amazon bid callback", new Date().getTime(), bids );
					                    window.jwpBids[vHash].amazon = true;
					                    if ( bids.length > 0 ) { //If we have received any bids back
					                        try {
					                            console.log("AMI jwp amazon bid request ad", bids[0].encodedQsParams);
					                            url = url + "&scp=" + bids[0].encodedQsParams;
					                        } catch ( e ) {
					                            console.log(e);
					                        }
					                    } else {
					                        console.log("AMI jwp amazon no bids");
					                    }
					                    headerBidderBack("a9");
					                });
				                } else {
				                    headerBidderBack("a9");
				                }

				                // Get main item context data
							    window.irisContext.getContext(jwplayer(el).getPlaylistItem().mediaid).then(function(data) {
									// Encode the context data
									console.log( "AMI jwp IrisTV Bids", new Date().getTime(), data.context );
									// Replace the server url with the context data (this is for simple ad requests),
									// If you have the serverUrl dynamically configured, then you will need to append the context data
									// under cust_params, so this is just for testing purpose

									if ( data.context && Object.keys( data.context ).length ) {
										var vastURL = new URL( url );
									    var vastParams = new URLSearchParams( vastURL.search );
									    if ( vastParams.has( "cust_params" ) ) {
									        var custParams = new URLSearchParams( vastParams.get( "cust_params" ) );
									    } else {
									        var custParams = new URLSearchParams();
									    }
						                custParams.set( "iris_context", data.context.join(","));
									    vastParams.set( "cust_params", decodeURIComponent( custParams.toString() ) );
									    vastURL.search = vastParams.toString();
									    url = vastURL.toString();
								    }
									headerBidderBack("iris");
							    });

								setTimeout(function(){
									resolve( url );
								}, 10000);
							});
						}
						console.log("AMI jwp before init el", el );
						console.log("AMI jwp before init jwp", jwplayer );
						var player_jwplayer_wJC05Aa7_Bk5vyVYE_div = jwplayer(el).setup(videoParams).on("ready", function(){
						var el = decodeURIComponent( "jwplayer_wJC05Aa7_Bk5vyVYE_div" );
						var playerInstance = jwplayer(el);
						ns_.StreamingAnalytics.JWPlayer( playerInstance, {
							publisherId: "6036076",
							labelmapping: "ns_st_pu=\"AMI\", c3=\"Us Weekly\", ns_st_ge=\"" + decodeURIComponent( "%2Anull" ) + "\", ns_st_ia=\"" + decodeURIComponent( "%2Anull" ) + "\", ns_st_ce=\"" + decodeURIComponent( "1" ) + "\", ns_st_ddt=\"" + decodeURIComponent( "%2Anull" ) + "\", ns_st_tdt=\"" + decodeURIComponent( "%2Anull" ) + "\"",
						});
					}).on('adsManager', (e) => {
				var vHash = 'ami' + decodeURIComponent( 'wJC05Aa7' );
				const { adsManager, videoElement } = e;
				const iasConfig = {
				  anId: '928572',
				  campId: `${jwplayer().getWidth()}x${jwplayer().getHeight()}`, // This is dynamic based on player dimensions, but can be hard coded
				  chanId: window.prerollTag[vHash],
				  placementId: 'Open Auction',
				  pubOrder: 'Video',
				  pubId: 'Direct'
				};
				if (googleImaVansAdapter) {
				  googleImaVansAdapter.init(window.google, adsManager, videoElement, iasConfig);
				}
			}).on( 'time', function( e ) {
				var id = this.id;
				var pct = Math.round( e.position );

				if ( ! window.amiPlayersData ) {
					window.amiPlayersData = {};
				}


				if ( ! window.amiPlayersData[id] ) {
					window.amiPlayersData[id] = {
						m3: false,
						m10: false
					};
				}

				if ( window.amiPlayersData[id]['m3'] === false && pct >= 3 ) {
					window.amiPlayersData[id]['m3'] = true;
					console.log( '3sec played: ', id );
					window.dataLayer = window.dataLayer || [];
					dataLayer.push( {event: 'JWPlayEvent', jwTime: '3s played'} );
				}

				if ( window.amiPlayersData[id]['m10'] === false && pct >= 10 ) {
					window.amiPlayersData[id]['m10'] = true;
					console.log( '10sec played: ', id );
					window.dataLayer = window.dataLayer || [];
					dataLayer.push( {event: 'JWPlayEvent', jwTime: '10s played'} );
				}

			}).on( 'complete', function( e ) {
						if ( window.amiPlayersData && window.amiPlayersData[ this.id ] ) {
							window.amiPlayersData[ this.id ]['m3']  = false;
							window.amiPlayersData[ this.id ]['m10'] = false;
							console.log( 'clear played: ', this.id );
						}
					}).once("play", function(){
			var el = decodeURIComponent( "jwplayer_wJC05Aa7_Bk5vyVYE_div" );
			var playerInstance = jwplayer(el);
			loadIrisPlugin(playerInstance, playerInstance.getConfig().plugins["https://ovp.iris.tv/plugins/jwplayer/v2/iris-jwplayer8.adaptive.min.js"])
			}).setPlaylistItemCallback(function(item, index) {
			return waitForAmazon // Wait until Amazon is loaded.
		        .then(() => performAsyncBidding( player_jwplayer_wJC05Aa7_Bk5vyVYE_div, item, index ), () => { console.log("AMI JWP bidding FAILER"); }) // External bidding.
		        .then(tag => {
		            // Update the playlist item.
		            console.log("AMI jwp new headerbid", tag);

		            return Object.assign({}, item, {
		                adschedule: [{
		                    tag,
		                    offset: "pre"
		                }]
		            });
		        }).catch(function(e){
		            console.log("AMI jwp bidding failed", e);
		            return item;
		        }); // If bidding fails, use unmodified playlist item.
		});
					}
				}, 500);
			})();