function createSilverlight()
{
	var scene = new Stw_slplayback.Page();
	Silverlight.createObjectEx({
		source: "assets/js/Page.xaml",
		parentElement: document.getElementById("silverlightControlHost"),
		id: "SilverlightControl",
		properties: {
			width: "100%",
			height: "100%",
			version: "1.0",
			inplaceInstallPrompt: true
		},
		events: {
			onLoad: Silverlight.createDelegate(scene, scene.handleLoad),
			onError: function(sender, args) {
				var errorDiv = document.getElementById("errorLocation");
				if (errorDiv != null) {
					var errorText = args.errorType + "- " + args.errorMessage;
							
					if (args.ErrorType == "ParserError") {
						errorText += "<br>File: " + args.xamlFile;
						errorText += ", line " + args.lineNumber;
						errorText += " character " + args.charPosition;
					}
					else if (args.ErrorType == "RuntimeError") {
						errorText += "<br>line " + args.lineNumber;
						errorText += " character " +  args.charPosition;
					}
					errorDiv.innerHTML = errorText;
				}	
			}
		},
		initParams: "prerollURL=" + prerollURL + ",linkURL=" + linkURL
	});
}

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

Silverlight.createDelegate = function(instance, method) {
	return function() {
		return method.apply(instance, arguments);
	}
}

function thisMovie(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
function loadLogoSmall(LogoSmall, WebsiteURL, Name)
{
	document.getElementById('LogoSmallContainer').innerHTML = '<a href="' + WebsiteURL + '" target="_blank"><img alt="' + Name + '" title="' + Name + '" border="0" src="' + LogoSmall + '"></a>';
}

currentAdBannerSmallURL = "";
function loadAdBannerSmall(bannerURL)
{
	//alert(currentAdBannerSmallURL + ' / ' + bannerURL);
	if (currentAdBannerSmallURL != bannerURL)
	{
		document.getElementById("IframeAdBannerSmallContainer").contentWindow.location.replace(bannerURL);
		currentAdBannerSmallURL = bannerURL;
	}
}
function loadLogoBigBoxContainer(StageArt, WebsiteURL, Name)
{
	document.getElementById('LogoBigBoxContainer').innerHTML = '<a href="' + WebsiteURL + '" target="_blank"><img alt="' + Name + '" title="' + Name + '" border="0" src="' + StageArt + '"></a>';
}
function onTSAdvertising()
{
	//alert('onTSAdvertising()');
	hideStatusMessage();
	document.getElementById('LogoBigBoxContainer').style.zIndex = "6";
	document.getElementById('TargetSpotContainer').style.zIndex = "7";
	thisMovie("EnterComPlayer").onTSAdvertising();
}
function onTSAdvertised()
{
	//alert('onTSAdvertised()');
	document.getElementById('LogoBigBoxContainer').style.zIndex = "7";
	document.getElementById('TargetSpotContainer').style.zIndex = "6";
	thisMovie("EnterComPlayer").onTSAdvertised();
}
function onSilverLightAdvertising()
{
	//alert('onSilverLightAdvertising()');
	hideStatusMessage();
	document.getElementById('silverlightControlHost').style.zIndex = "100";
	thisMovie("EntercomStationList").onSilverLightAdvertising();
}
function onSilverLightAdvertised()
{
	//alert('onSilverLightAdvertised()');
	document.getElementById('silverlightControlHost').style.zIndex = "1";
	document.getElementById('silverlightControlHost').innerHTML = "";
	thisMovie("EntercomStationList").onSilverLightAdvertised();
}

function onVolumeTS(volume)
{
	 //alert('onVolumeTS');
	 thisMovie("EnterComPlayer").onVolumeTS(volume);
}
function onVolume(volume)
{
	//alert('onVolume');
	thisMovie("EntercomStationList").onVolume(volume);
	thisMovie("TargetSpotPlayer").onVolume(volume);
}
function onLiveStop()
{
	//alert('onLiveStop');
	thisMovie("EntercomStationList").onLiveStop();
	thisMovie("TargetSpotPlayer").onLiveStop();
}
function onLivePlay()
{
	//alert('onLivePlay');
	thisMovie("EntercomStationList").onLivePlay();
}
function onTargetSpotID(TargetSpotID)
{
	//alert('onTargetSpotID');
	thisMovie("TargetSpotPlayer").onTargetSpotID(TargetSpotID);
}
function loadStation(CallSign, sid, nonMusicProgramming, Name)
{
	//alert('loadStation - sid=' + sid);
	thisMovie("EnterComPlayer").loadStation(CallSign, sid, nonMusicProgramming);
	top.document.title = Name;
}
function onStationListLoaded()
{
	//alert('onStationListLoaded');
	thisMovie("EnterComPlayer").onStationListLoaded();
}
function loadFirstStation()
{
	//alert('loadFirstStation');
	thisMovie("EntercomStationList").loadFirstStation();
}
function onNowPlaying(nowPlaying)
{
	//alert('onNowPlaying');
	thisMovie("EntercomStationList").onNowPlaying(nowPlaying);
}
function onAds(ads)
{
	//alert('onAds');
	thisMovie("TargetSpotPlayer").onAds(ads);
}
function onStationList()
{
	//alert('onStationList');
	thisMovie("EntercomStationList").onStationList();
}
function onSongHistory()
{
	//alert('onSongHistory');
	thisMovie("EntercomStationList").onSongHistory();
}
//playLive() is called by Silverlight on end of preroll or when preroll is not found / Or by Flash Video if preroll is flv
function playLive()
{
	//alert('playLive');
	thisMovie("EnterComPlayer").playLive();
}
function onPlayerLoaded()
{
	//alert('onPlayerLoaded');
	thisMovie("EntercomStationList").onPlayerLoaded();
}
function updateStatusMessage(message)
{
	document.getElementById('StreamStatusContainer').style.zIndex = 110;
	document.getElementById('StreamStatusContainer').innerHTML = '<div style="margin-left:5px; margin-top:1px;">' + message + '</div>';
	//alert('updateStatusMessage - message=' + message);
}
function hideStatusMessage()
{
	document.getElementById('StreamStatusContainer').innerHTML = "";
	document.getElementById('StreamStatusContainer').style.zIndex = "0";
	//alert('hideStatusMessage');
}
function loadExternalAd(adURL)
{
	//alert('loadExternalAd ' + adURL);
	hideStatusMessage();
	document.getElementById('IframeBigBoxAdContainer').style.display = "block";
	document.getElementById("IframeBigBoxAdContainer").contentWindow.location.replace(adURL);
	document.getElementById('BigBoxAdContainer').style.zIndex = 10;
}
function hideExternalAd()
{
	//alert('hideExternalAd');
	document.getElementById('IframeBigBoxAdContainer').style.display = "none";
	document.getElementById('BigBoxAdContainer').style.zIndex = "3";
}
function onAdBreakAdvertising()
{
	thisMovie("EntercomStationList").onAdBreakAdvertising();
}
function onAdBreakAdvertised()
{
	thisMovie("EntercomStationList").onAdBreakAdvertised();
}
function onCustomButton(customButtonDisplayed, buttonName, buttonLink, customButtonPopup)
{
	thisMovie("EnterComPlayer").onCustomButton(customButtonDisplayed, buttonName, buttonLink, customButtonPopup);
}
function setCustomSongHistoryButton(buttonName, buttonLink)
{
	thisMovie("EnterComPlayer").setCustomSongHistoryButton(buttonName, buttonLink);
}

//Flash Video
function onPlayAdVideo(videoURL, linkURL)
{
	//alert('onPlayAdVideo()');
	thisMovie("EnterComVideo").onPlayAdVideo(videoURL, linkURL);
}
function onFlashVideoAdvertising()
{
	//alert('onFlashVideoAdvertising()');
	hideStatusMessage();
	document.getElementById('EntercomVideoContainer').style.zIndex = "50";
	thisMovie("EntercomStationList").onFlashVideoAdvertising();
}
function onFlashVideoAdvertised()
{
	//alert('onFlashVideoAdvertised()');
	document.getElementById('EntercomVideoContainer').style.zIndex = "2";
	thisMovie("EntercomStationList").onFlashVideoAdvertised();
}
function onSetTimeOut(timeout)
{
	//alert('onSetTimeOut() ' + timeout);
	thisMovie("EnterComPlayer").onSetTimeOut(timeout);
}
function loadMainBackground(mainBackgroundImageURL)
{
	document.getElementById('TopBackground').style.backgroundImage = "url('"+ mainBackgroundImageURL +"')";
}
function loadDefaultBackground()
{
	document.getElementById('TopBackground').style.backgroundImage = "url('assets/img/background.jpg')";
}