
$(document).ready(showMovies);

function onSilverlightError(sender, args) {
	var e = sender.getHost().parentNode;
	e.parentNode.style.backgroundImage = e.style.backgroundImage;
	$(".movie").hide();
}

function showMovies() {
	var movies = $(".movie");
	for (var i = 0; i < movies.length; i++) {
		var e = movies[i];

		if (Silverlight.isInstalled('3.0.40624.0')) {

			e.style.visibility = 'visible'; // only needed for IE
			try {
				e.innerHTML = embedSilverlight(null, 'slObj_'+e.id, e.id);
			}
			catch (err) {
			}
			e.style.visibility = 'hidden'; // only needed for IE
		}
		else
		{
			if (e.id == 'croybier') {
				e.innerHTML = '<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration: none;"><img src="ClientBin/silverlightinstallbier.png" alt="Installeer Microsoft Silverlight" style="border-style: none"/></a>';
				showCanvas(e);
			}
			break;
		}

	}
}

function embedSilverlight(parent, pluginId, userContext) {
	var	 slObject = Silverlight.createObjectEx({
						source: "ClientBin/Motion.xap",
						parentElement: parent,
						id: pluginId, 
						properties: {
							width: "100%", 
							height: "100%",
							background: "black", 
							alt: "",
							version: "3.0.40624.0" },
						events: {
							onError: onSilverlightError, 
							onLoad: onSLLoad},
						initParams: "videoUrl="+userContext+".wmv,imageUrl="+userContext+".jpg,playButtonText=Start de film",
						context: userContext
					});
	return slObject;
}

function onSLLoad(plugIn, userContext, sender) {
	if (plugIn) {
	  var e = sender.getHost();
	  showCanvas(e.parentNode);
	}
}

function showCanvas( sl ) {
	if (sl != null) {
		var p = sl.parentNode;
		sl.style.backgroundImage = p.style.backgroundImage; p.style.backgroundImage = 'none';
		sl.style.visibility = 'visible';
	}
}