if (!window.TV2Player || !window.TV2Player.insert) {
	
	if (!window.TV2Player) var TV2Player = {}

	// Backwards compatibility
	if (!TV2Player.insertPlayer) {
		TV2Player.insertPlayer = function (progId, isMainPlayer, injectElementId, autoplay, layoutId, design, clubname) {
			TV2Player.insert(progId, injectElementId, {'autoplay': autoplay, 'className': 'tv2player', 'stretch': 'fill' });
		}
	}

	TV2Player.version = '4.0.46';
	
	TV2Player.insert = function (programAndItemId, injectElement, options, onLoaded) {
		/* options: 
		autoplay
		muted
		panelMode
		bandwidth
		referrer
		startPos
		className
		stretch
		noCompanion
		width
		height
		emulateFallback
		showProgramInfo
		windowLess
		useLiveMenu
		useBeta
		companionAdContainerId
		openSumoOnNavigation
		companionAdSize
		analyticsTag
		*/
		
		function createPlayer() {
			if (!options.emulateFallback && !(incompatibleBrowser) && Silverlight.isInstalled('2.0.31005')) {
				var sl3path = '';
				if (Silverlight.isInstalled('3.0.40624.0')) {
					if (options.useBeta || document.cookie.indexOf('webtv.usePlayerBeta=true')>=0) {
						sl3path = 'player-beta/';
					} else {
						sl3path = 'sl3/';
					}
						
				}
				var xapUrl = 'http://www.tv2.no/multimedia/sl/' + sl3path + 'TV2Player.xap';
			
				var initParams = [];
				initParams.push('progId=' + progId);
				initParams.push('verticalAlignment=top');
				
				if (itemId) initParams.push('itemId=' + itemId);

				if (options.autoplay) initParams.push('autoplay=true');
				if (options.muted) initParams.push('muted=true');
				if (options.useLiveMenu == false) initParams.push('useLiveMenu=false');
				if (options.showProgramInfo) initParams.push('showProgramInfo=true');
				if (options.bandwidth) initParams.push('bandwidth=' + options.bandwidth);
				if (options.companionAdContainerId) initParams.push('companionAdContainerId=' + options.companionAdContainerId);
				if (options.companionAdSize) initParams.push('companionAdSize=' + options.companionAdSize);
				if (options.openSumoOnNavigation == false) initParams.push('openSumoOnNavigation=' + options.openSumoOnNavigation);
				if (options.panelMode) initParams.push('panelMode=' + options.panelMode)
				else initParams.push('panelMode=disabled');
				if (options.referrer) initParams.push('referrer=' + options.referrer);

				var className = options.className ? options.className : 'TV2Player';	
				var slCallbacks = new SlCallbacks();
							
				if (ie) {
					var slHtml = '<object type="application/x-silverlight-2" data="data:application/x-silverlight-2," id="' + elementId + '" class="' + className + '">';
					slHtml += '<param name="EnableGPUAcceleration" value="true"/>';
					slHtml += '<param name="Framerate" value="25"/>';
					slHtml += '<param name="AllowHtmlPopupWindow" value="true"/>';
					slHtml += '<param name="WindowLess" value="' + (options.windowLess && true) + '"/>';
					slHtml += '<param name="EnableHtmlAccess" value="true"/></object>';
			
					if (options.stretch == 'fill') {
						var newContainer = createFillContainer(injectElement);
						newContainer.innerHTML = slHtml;
						
						slElement = document.getElementById(elementId);
						styleForFill(slElement);
					} else {
						injectElement.innerHTML = slHtml;
						slElement = document.getElementById(elementId);
					  	if (width) slElement.style.width = width;
						if (height) slElement.style.height = height;
					}

					if (options.windowLess) {
					    slElement.style.backgroundColor = 'transparent';
					}
					
			 		slElement.callbackObj = slCallbacks;
		
		 			slElement.InitParams = initParams.join(',');
			      	slElement.Source = xapUrl;
				} else {
					slElement = document.createElement('object');
		  
					slElement.setAttribute('id',elementId);
						slElement.className = className;
					  
						if (options.stretch != 'fill') {
							if (width) slElement.style.width = width;
								if (height) slElement.style.height = height;
							}
					
						slElement.setAttribute('type','application/x-silverlight-2');
					slElement.setAttribute('data','data:application/x-silverlight-2,');
					
					slElement.appendChild(createParamElm('Source',xapUrl));
					slElement.appendChild(createParamElm('InitParams',initParams.join(',')));
					slElement.appendChild(createParamElm('MinRuntimeVersion','2.0.30523'));
					slElement.appendChild(createParamElm('EnableGPUAcceleration','true'));
					slElement.appendChild(createParamElm('Framerate','25'));
					slElement.appendChild(createParamElm('WindowLess',(options.windowLess && true)));
					slElement.appendChild(createParamElm('EnableHtmlAccess','true'));
					slElement.appendChild(createParamElm('AllowHtmlPopupWindow','true'));

			        if (options.windowLess) {
			            slElement.style.backgroundColor = 'transparent';
			        }

				    slElement.callbackObj = slCallbacks;
				
					if (options.stretch == 'fill') {
						var newContainer = createFillContainer(injectElement);
						slElement = styleForFill(slElement);
						newContainer.appendChild(slElement);
					} else {
						injectElement.appendChild(slElement);
					}
			}
				
				if (!window.SpringStreams) {
					loadScripts(['http://webtv.tv2.no/multimedia/webtv/dido/springstreams.js'],initSpringStreams);
				} else {
					initSpringStreams();	
				}
				

			var companionElement = document.createElement('div');
			
	        companionElement.className = 'tv2PlayerCompanionAd';
	        //companionElement.style.margin = '0 auto';
	        injectElement.appendChild(companionElement);
	        companionElement.style.display = 'none';
	        
	      if (options.noCompanion || options.companionAdContainerId) {
				injectElement.removeChild(companionElement);
        }
				
			} else {
				
				function startVideo() {
					if (!window.DartPlayer) {
						loadScripts(['http://ad.doubleclick.net/879366/DartPlayer_03_44.js'], startVideo);
						return false;
					}


					
					var wmElementId = elementId + '-wmp';
					if (ie) {
						var wmCode = '<object id="' + wmElementId + '" class="' + className + '" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">';
						wmCode += '<param name="stretchToFit" value="true"/><param name="uiMode" value="full"/><param name="URL" value="' + videoUrl + '"/>';
						wmCode += '<param name="enableContextMenu" value="true"/><param name="volume" value="85"/><param name="windowlessVideo" value="false"/>';
						wmCode += '<param name="mute" value="' + !!options.muted + '"/><param name="autoStart" value="true"/>';	
						wmCode += '</object>';
						if (options.stretch == 'fill') {
							newContainer.innerHTML = newContainer.innerHTML + wmCode;
						} else {
							container.innerHTML = container.innerHTML + wmCode;
						}
						wmElement = document.getElementById(wmElementId);
						if (options.stretch == 'fill') {
							styleForFill(wmElement);
						} else {
							wmElement.style.width = actualWidth + 'px';
							wmElement.style.height = actualHeight + 'px';
							wmElement.style.position = 'absolute';
							wmElement.style.top = '0';
							wmElement.style.left = '0';
						}
						wmElement.attachEvent('OpenStateChange', function(){if (wmElement.currentPlaylist) var ac = wmElement.currentPlaylist.getItemInfo("adCategory"); if (ac) {adCategory = ac;}});
					} else {
						wmElement = document.createElement('object');
						wmElement.setAttribute('id',wmElementId);
						wmElement.appendChild(createParamElm('stretchToFit','true'));
						wmElement.appendChild(createParamElm('uiMode','full'));
						wmElement.appendChild(createParamElm('url',videoUrl));
						wmElement.appendChild(createParamElm('autoStart','true'));
						wmElement.appendChild(createParamElm('enableContextMenu','true'));
						wmElement.appendChild(createParamElm('windowlessVideo','false'));
						wmElement.appendChild(createParamElm('volume','85'));
						wmElement.appendChild(createParamElm('mute',(!!options.muted) + ''));

					 	var wmpPluginAvailable = false;
					 	if (navigator.mimeTypes) {
			 				var x = '';
			 				for (var i=0; i<navigator.mimeTypes.length; i++ ) {
								var n = navigator.mimeTypes[i].type;
								if (n != null && n.indexOf("x-ms-wmp")>=0) {
									wmpPluginAvailable = true;
								}
							}
						}
						if (wmpPluginAvailable) {
							wmElement.setAttribute('type','application/x-ms-wmp');
						} else {
							wmElement.setAttribute('type','application/x-mplayer2');
							wmElement.appendChild(createParamElm('displaySize','4'));
							wmElement.appendChild(createParamElm('autoSize','0'));
							wmElement.appendChild(createParamElm('allowChangeDisplaySize','1'));
							wmElement.appendChild(createParamElm('showStatusBar','1'));
							wmElement.appendChild(createParamElm('showControls','1'));
							wmElement.appendChild(createParamElm('showTracker','1'));
							wmElement.appendChild(createParamElm('autoplay','1'));
							wmElement.appendChild(createParamElm('scale','toFit'));
						}
						if (options.stretch == 'fill') {
							styleForFill(wmElement);
							newContainer.appendChild(wmElement);
						} else {
							container.appendChild(wmElement);
							wmElement.style.width = actualWidth + 'px';
							wmElement.style.height = actualHeight + 'px';
							wmElement.style.position = 'absolute';
							wmElement.style.top = '0';
							wmElement.style.left = '0';
						}

					}

					// Spring
					if (!window.SpringStreams) {
						loadScripts(['http://webtv.tv2.no/multimedia/webtv/dido/springstreams.js'],initSpringStreams);
					} else {
						initSpringStreams();	
					}
					// End Spring
					
					
					if (window.DartPlayer) {
						DARTReady = function() {
							dartPlayer.attachOnAdStart(showDartBannerAd);		
						}
						dartPlayer = new DartPlayer(wmElementId, DARTReady);
					}
					
					if (wmElement.openState != null) setInterval(checkVideoStatus,300);

					return false;
				}
				
				var debugString = '';
				
				function checkVideoStatus() {

					if (wmElement && !isCheckedForError && wmElement.openState == 13 && wmElement.currentMedia) {
						isCheckedForError = true;
						if (wmElement.currentMedia.getItemInfo('entry-type') == 'error') {
							wmElement.controls.stop();
							var cont = wmElement.parentNode;
							cont.removeChild(wmElement);
							if (ie) {
								createStartPoster();
								cont = startPoster.parentNode;
							} else {
								if (installPoster) 
									cont.removeChild(installPoster);
							}
							var errorMessage = document.createElement('p');
							errorMessage.style.fontFamily = 'Arial, sans-serif';
							errorMessage.style.fontSize = '1.2em';
							errorMessage.style.color = 'white';
							errorMessage.style.textAlign = 'right';
							errorMessage.style.fontWeight = 'bold';
							errorMessage.style.position = 'absolute';
							errorMessage.style.right = '1em';
							errorMessage.style.top = '0.5em';
							errorMessage.style.backgroundColor = '#444444';
							errorMessage.style.padding = '0.2em';
							if (wmElement.currentMedia.getItemInfo('title') && wmElement.currentMedia.getItemInfo('title').indexOf('ikke startet') > 0) {
								errorMessage.innerHTML = 'SENDINGEN ER IKKE STARTET';							
							} else {
								errorMessage.innerHTML = wmElement.currentMedia.getItemInfo('title').toUpperCase();
							}
							cont.appendChild(errorMessage);
						}
					}
					if (wmElement && wmElement.currentMedia) {	
						if (currentItem && !isPlayerActive(wmElement)) {
							// to assure preroll is being recognized in new playback in same player 
							currentItem = null;
						}
						if (!(currentItem && wmElement.currentMedia.sourceURL == currentItem.url)) {
							var item;
							if (wmElement.currentMedia.getItemInfo('DartAdId')) {
								if (!currentItem) {
									item = {'ct': 'ads/preroll',
											//'desc': '',
											//'name': wmElement.currentMedia.name,
											'stream': wmElement.currentMedia.sourceURL,
											'url': wmElement.currentMedia.sourceURL };
								} else {
									item = {'ct': 'ads/postroll',
											//'desc': '',
											//'name': wmElement.currentMedia.name,
											'stream': wmElement.currentMedia.sourceURL,
											'url': wmElement.currentMedia.sourceURL };
								}
							} else if (wmElement.currentMedia.getItemInfo('progId') && isPlayerActive(wmElement)) {
								item = {'ct': 'content',
										//'desc': wmElement.currentMedia.getItemInfo('abstract'),
										//'name': wmElement.currentMedia.name,
										'stream': (options.analyticsTag ? options.analyticsTag : '/TV2stream/udefinert') + formatAnalyticsString(wmElement.currentMedia.name), 
										//'stream':  'http://webtv.tv2.no/webtv/metafile.asx?progId=' + progId,
										'url': wmElement.currentMedia.sourceURL };
							}
							
							if (item) {
								currentItem = item;
								if (springSensors) {
									if (springStreamsStream) {
										springStreamsStream.stop();
									}
									var logItem = {'ct': item['ct'], 'stream': item['stream']};
									springStreamsStream = springSensors.track(wmElement,logItem);
								}
							}
						}
					}
				}
				
				function isPlayerActive(wmObject) {
					return !(wmObject.playState == 1 || wmObject.playState == 8 || wmObject.playState == 10);	
				}
				
				
				function showDartBannerAd(x) {						
					var adSize = options.companionAdSize ? options.companionAdSize : '450x60';
					if (companionElement) {
						var compString = dartAdUrl.replace(/{adCategory}/ig,adCategory).replace(/{adSize}/ig,adSize);  // + dartPlayer.getAd().getDartId() + ';ord=' + ord;
						var compTag = dartPlayer.getRoadblockURL(compString);
						var iframeStyle = 'width: 468px; height: 60px'; 
						
						if (companionElement.className.indexOf('tv2PlayerCompanionAd') < 0) { 
							iframeStyle = 'width: 100%; height: 100%';
						}
						
						companionElement.innerHTML = '<iframe src="' + compTag + '" style="' + iframeStyle + '" scrolling="no" frameborder="0" allowtransparency="true">' + '</iframe>';
						
						companionElement.style.display = 'block';
					}
				}

				function recommendSilverlight() {
					if (incompatibleBrowser) {
						startVideo();
						return false;					
					}
					installPoster = document.createElement('a');
					installPoster.target = '_blank';
					installPoster.href = 'http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0';
					
					var installImage = document.createElement('img');
					installImage.src = 'http://webtv.tv2.no/multimedia/webtv/images/dido/player/4.0/silverlight-fallback.jpg';
					installPoster.appendChild(installImage);
					installImage.style.border = '0';
					if (options.stretch == 'fill') {
						installImage = styleForFill(installImage);
						newContainer.appendChild(installPoster);
					} else {
						styleForStatic(installImage,actualWidth, actualHeight)
						container.appendChild(installPoster);
					}

					var fallbackButton = document.createElement('a');
					fallbackButton.href = '#';
					fallbackButton.onclick = startVideo;
					
					var fallbackImage = document.createElement('img');
					fallbackImage.src = 'http://webtv.tv2.no/multimedia/webtv/images/dido/player/4.0/pixel.gif';
					fallbackImage.style.border = '0';
					fallbackImage.style.margin = '0';
					fallbackImage.style.padding = '0';
					if (options.stretch == 'fill') {
						fallbackImage = styleForFill(fallbackImage);
						fallbackImage.style.top = 'auto';
						fallbackImage.style.bottom = '0';
						fallbackImage.style.height = '20%';
						fallbackButton.appendChild(fallbackImage);
						newContainer.appendChild(fallbackButton);
					} else {
						fallbackImage.style.position = 'absolute';
						fallbackImage.style.top = Math.round(actualHeight * 4 / 5) + 'px';
						fallbackImage.style.left = '0px';
						fallbackImage.style.width = actualWidth + 'px';
						fallbackImage.style.height = Math.round(actualHeight / 5) + 'px';
						fallbackButton.appendChild(fallbackImage);
						container.appendChild(fallbackButton);
					}
					return false;
				}


			
				function createStartPoster() {
					injectElement.innerHTML = '';
					var playIconWidth = 57;
					var playIconHeight = 57;
					var playIconUrl = 'http://webtv.tv2.no/multimedia/webtv/images/dido/player/4.0/play.' + (ie6 ? 'gif' : 'png');
		
					var imageDir = Math.floor(parseInt(progId)/1000);
				
					container = document.createElement('div');
					container.className = options.className || '';
					container.setAttribute('id',elementId);
				  container.style.position = 'relative';
					container.style.padding = '0';
					if (options.stretch == 'fill') {
						//container.style.width = '100%';
						newContainer = createFillContainer(injectElement);
						container = styleForFill(container);
						newContainer.appendChild(container);
					} else {
				  	if (width) container.style.width = width;
					  if (height) container.style.height = height;
						injectElement.appendChild(container);
					}

					startPoster = document.createElement("a");
					startPoster.href = '#';
					startPoster.onclick = recommendSilverlight;
				
					startImage = document.createElement('img');
					startImage.src = 'http://www.tv2.no/tvid/VMan-P{imageDir}/VMan-P{progId}.jpg'.replace(/{progId}/ig,progId).replace(/{imageDir}/ig,imageDir);
				
					// The container element should be rendered by the browser by now
					actualWidth = container.clientWidth;
					actualHeight = Math.round(actualWidth * 9 / 16);
					if (options.stretch == 'fill') {
						startImage = styleForFill(startImage);
					} else {
						container.style.width = actualWidth + 'px';
						container.style.height = actualHeight + 'px';
						styleForStatic(startImage,actualWidth, actualHeight);
					}
								
					var playIcon = document.createElement('img');
					playIcon.src = playIconUrl;
					playIcon.style.border = '0';
					playIcon.style.position = 'absolute';
					playIcon.style.right = '5%';
					playIcon.style.bottom = '8%';
					
					startPoster.appendChild(startImage);
					startPoster.appendChild(playIcon);
				
					if (options.stretch == 'fill') {
						newContainer.appendChild(startPoster);
					} else {
						container.appendChild(startPoster);
					}
										
					if (!options.noCompanion) {
						if (options.companionAdContainerId) {
						  companionElement = document.getElementById(options.companionAdContainerId);
						} else {
				          companionElement = document.createElement('div');
				          companionElement.className = 'tv2PlayerCompanionAd';
				          companionElement.style.display = 'none';
				          //companionElement.style.margin = '0 auto';
				          injectElement.appendChild(companionElement);
						}
					}
				}
        
				var isExternal = window.TV2no && true ? 0 : 1;
				var webtvUrl = 'http://webtv.tv2.no/embed/';
				var dartAdUrl = 'http://ad.doubleclick.net/adi/{adCategory};sz={adSize};tile=2;dc_seed=;ord={ord}';
				var videoUrl =  webtvUrl + 'metafile.asx?p={progId}&i={itemId}&bw=1000&ads=true&external={external}'.replace(/{progId}/ig,progId).replace(/{itemId}/ig,itemId).replace(/{external}/ig,isExternal); 
				
				var wmElement;
				var adCategory;
				var installPoster;
				var container;
				var newContainer;
				var startPoster;
				var startImage;
				var actualWidth;
				var actualHeight;
				var companionElement;
				
				var nsScriptLoaded = false;
				
				var isCheckedForError = false;
				var currentItem;
				
				
				createStartPoster();
				
				if (options.autoplay) recommendSilverlight();
				
				if (onLoaded) onLoaded(container);
			}
		}
		
		// Initial stuff for all cases of inserting
		if (!options) options = {};

		if (typeof injectElement == 'string') {
			injectElement = document.getElementById(injectElement);
		}

		var elementId = 'video-' + programAndItemId;
		while (document.getElementById(elementId)) {
			elementId = elementId + '_';
		}

		var width = '';
		var height = '';
		
		var splitted = ('' + programAndItemId).split('-');
		var progId = splitted[0];
		var itemId = '';
		if (splitted[1]) {
			itemId = splitted[1];
		}
		
		if (options.width)
			width = isNaN(options.width) ? options.width : options.width + 'px';
		if (options.height)
			height = isNaN(options.height) ? options.height : options.height + 'px';

		var opera = navigator.userAgent.indexOf("Opera")>=0;
		var linux = navigator.userAgent.indexOf('inux')>=0;
		var mac = navigator.userAgent.indexOf("Mac")>=0;
		var incompatibleBrowser = (opera && parseFloat(navigator.appVersion) < 9.8) || (navigator.userAgent.indexOf("mac") != -1 && navigator.userAgent.indexOf("ppc") != -1) || linux;
		var ie = navigator.userAgent.indexOf("MSIE")>=0 && !opera && navigator.userAgent.indexOf("Mac")<0;
		var ie6 = navigator.userAgent.indexOf('MSIE 6') != -1;
		
		var springSensors;
	    var springStreamsStream;
		var slBridge;
		var slElement;
		
		if (window.Silverlight && window.Silverlight.isInstalled)
			createPlayer();
		else
			loadScripts(['http://webtv.tv2.no/multimedia/webtv/dido/silverlight.js'], createPlayer);

		// Common code

		function createFillContainer(originalContainer) {
			// Thanks to http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/
			
			var outerWrapper = document.createElement('div');
			outerWrapper.style.position = 'relative';
			outerWrapper.style.height = '0';
			outerWrapper.style.paddingBottom = '56.25%';
			outerWrapper.style.paddingTop = '0';
			outerWrapper.style.border = '0';
			outerWrapper.style.margin = '0';
			
			var innerWrapper = document.createElement('div');
			innerWrapper = styleForFill(innerWrapper);
			outerWrapper.appendChild(innerWrapper);
			originalContainer.appendChild(outerWrapper);
			return innerWrapper;
		}
		
		function styleForFill(elm) {
			elm.style.position = 'absolute';
			elm.style.width = '100%';
			elm.style.height = '100%';
			elm.style.left = '0';
			elm.style.top = '0';
			elm.style.border = '0';
			elm.style.margin = '0';
			elm.style.padding = '0';
			return elm;
		}
		
		function styleForStatic(elm, w, h) {
			elm.style.position = 'absolute';
			elm.style.width = w + 'px';
			elm.style.height = h + 'px';
			elm.style.left = '0';
			elm.style.top = '0';
			elm.style.border = '0';
			elm.style.margin = '0';
			elm.style.padding = '0';
			return elm;
		}
		
    function createParamElm(name,value) {
      var newParam = document.createElement('param');
      newParam.setAttribute('name',name);
      newParam.setAttribute('value',value);
      return newParam;
    }

		function loadScripts(scripts,onComplete) {
			var i=-1;
			var finished = false;
			var isSafari = (navigator.userAgent.toLowerCase().indexOf('safari')>=0);
	
			loadNextScript();
		
			function loadNextScript() {
				i++;
				if (i<scripts.length) {
					var head = document.getElementsByTagName("head")[0];         
					var newScript = document.createElement('script');
					newScript.onload = loadNextScript;
					newScript.type = 'text/javascript';
					newScript.charset = 'ISO-8859-1';
					newScript.onreadystatechange=function(){if(newScript.readyState=='loaded' || newScript.readyState=='complete'){loadNextScript()}};
					newScript.src = scripts[i];
					head.appendChild(newScript);
					if (isSafari) {
						loadNextScript();
					}
				} else if (onComplete && !finished) {
					if (isSafari) {
						finished = true;
						tryOnComplete();
					} else {
						finished = true;
						onComplete();
					}
				}
			}
			
			function tryOnComplete() {
				try {
					onComplete();
				} catch(e) {
					window.setTimeout(tryOnComplete,500);
				}
			}
		}
		
		function formatAnalyticsString(s) {
			var sep = "/";
			if (s.length > 0)
				return sep + s.replace(/[^a-zA-Z0-9]+/g,'_').replace(/^_|_$/,'');
			else
				return "";
		}
		
		
		  function initSpringStreams() {
			  function detectExternalPartners(u) {
				  if (options.referrer) {
					  return '/TV2stream/ekstern/' + formatAnalyticsString(options.referrer);
				  } else {
					  if ((u.indexOf('dagbladet.no')>=0 || u.indexOf('kjendis.no')>=0 || u.indexOf('sport.no')>=0 || u.indexOf('se.no')>=0)) {
						  return '/TV2stream/ekstern/Dagbladet';
					  } else if (u.indexOf('no.msn.com')>=0 || u.indexOf('msnno.starlounge')>0) {
						  return '/TV2stream/ekstern/MSN';
					  } else if (u.indexOf('startsiden.no')>=0) {
						  return '/TV2stream/ekstern/Startsiden';
					  } else if (u.indexOf('sol.no')>=0) {
						  return '/TV2stream/ekstern/SOL';
					  } else {
						  return '/TV2stream/ekstern/ovrige';
					  }
				  }
			  }
			  
			  springSensors = new SpringStreams('tv2');
			  if (window.addEventListener) {
				window.addEventListener('unload',springSensors.unload,false);  
			  } else if (window.attachEvent){
				  window.attachEvent('unload', springSensors.unload);
			  }
			  
			  if (!options.analyticsTag) {
				  var h = document.location.hostname;
				  if (h.indexOf('tv2nyhetene.no')>=0) {
					  options.analyticsTag = '/TV2stream/Artikler/Nyheter'
				  } else if (h.indexOf('tv2underholdning.no')>=0 || document.location.href.indexOf('biip.no/waschera')>=0) {
					  options.analyticsTag = '/TV2stream/Artikler/Underholdning'
				  } else if (h.indexOf('tv2veret.no')>=0 || h.indexOf('storm.no')>=0) {
					  options.analyticsTag = '/TV2stream/Artikler/Vaer'
				  } else if (h.indexOf('tv2sporten.no')>=0 || h.indexOf('altomfotball.no')>=0 || h.indexOf('minfotball.no')>=0) {
					  options.analyticsTag = '/TV2stream/Artikler/Sport'
				  } else if (h.indexOf('tv2.no')>=0 || h.indexOf('tv2asa.no')>=0) {
					  if (document.location.href.indexOf('embed.html')>0 && parent != self && document.referrer) {
						  options.analyticsTag = detectExternalPartners(document.referrer);
					  } else {
						  options.analyticsTag = '/TV2stream/Annet_TV_2';
					  }
				  } else {
					  options.analyticsTag = detectExternalPartners(document.location.href);
				  }			  
			  }
			  //springSensors.debug = function(v) {
				//if (window.console)
				//	console.debug(v);  
			  //}
		  }
		
		  
		  var slSpringStreamsAdapter = {
			'getMeta': function(id) {
			  		return {
			  			'pl': 'TV 2 Video',
			  			'pv': slBridge.getVersion(),
			  			'sx': screen.width,
			  			'sy': screen.height
			  		};
		  		},
		  	'getPosition': function(id) {
		  			if (slBridge) return slBridge.getPos()
		  			else return 0;
		  		},
		  	'getDuration': function(id) {
		  			if (slBridge) return slBridge.getDuration()
		  			else return 0;
		  		}
		  }
		
		function SlCallbacks() {
		    var externalOnLoaded = onLoaded;
			this.onLoaded = function () { 
		    	slBridge = slElement.Content.playerPage;
				if (externalOnLoaded)
					externalOnLoaded(slBridge);
		    }
		    
		    this.onStreamChanged = function(metadata) {
		    	if (springSensors) {
					if (metadata.Ended && springStreamsStream) {
						springStreamsStream.stop();
						springStreamsStream = null;
					} else {
						var desc = {
								'stream': metadata.Url
								//'name': metadata.Title,
								//'desc': metadata.Description
							};
						switch (metadata.StreamType) {
							case 2: //AdPreroll
								desc['ct'] = 'ads/preroll';
							break;
							case 3: //AdMidroll
								desc['ct'] = 'ads/midroll';
							break;
							case 4: //AdPostroll
								desc['ct'] = 'ads/postroll';
							break;
							default: //Content
								desc['ct'] = 'content';
								desc['stream'] = (options.analyticsTag ? options.analyticsTag : '/TV2stream/udefinert') + formatAnalyticsString(metadata.Title);
								//desc['stream'] = 'http://webtv.tv2.no/webtv/metafile.asx?progId=' + progId;
							break;
						}
						if (springStreamsStream != null) springStreamsStream.stop();
						springStreamsStream = springSensors.track(slElement,desc,slSpringStreamsAdapter);
					}
				}

		    }
		    
		}
	}	
}