/*
Naam				: 	addMovie.js
Omschrijving		: 	Code om een youtube filmpje toe te voegen aan een html pagina met zo weinig mogelijk code
getest				: 	IE6 IE8, FF3
bekende problemen	: 	geen
Auteur				: 	sjoerd
Wijzigingen			:   04/08/2009 		0.1		(SJKE)		-	test versie
        			:   11/08/2009 		1.0		(SJKE)		-	eerste online versie, getest en opgeschoond.


code om aan html toe te voegen: 
<script src="http://www.google.com/jsapi"></script>
<script src="./addMovie.js"></script>  										
<script>  loadMovie('1bfFvoF85jg'); </script>
<div id="ytapiplayer"> U heeft Flash player 8+ en JavaScript nodig om deze video te bekijken.</div>
					
*/


function addLoadEvent(func) {// add onload without risk of overwriting other onloads. thanks to Simon Willison 
  	var oldonload = window.onload;
  	if (typeof window.onload != 'function') {
    	window.onload = func;
  	} else {
    	window.onload = function() {
    		if (oldonload) {
        		oldonload();
    		}
      			func();
    		}
  	}//end else
}//end function


function createPlayer(){
	  //alert("init player");
      
	  //de variabele YoutubeMovieId word in de mdd gedefinieerd (zie beschrijving bovenin deze file)
	  var youtubeURL = "http://www.youtube.com/v/" + youtubeMovieId;
      // <![CDATA[
       // allowScriptAccess must be set to allow the Javascript from one 
      // domain to access the swf on the youtube domain
      var params = { allowScriptAccess: "always", bgcolor: "#cccccc" };
      // this sets the id of the object or embed tag to 'myytplayer'.
      // You then use this id to access the swf and make calls to the player's API
      var atts = { id: "myytplayer" };
      swfobject.embedSWF(youtubeURL+"&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer",
                         "ytapiplayer", "425", "344", "8", null, null, params, atts);
      //]]>
	  }
	  

//import andere javascript functie

if (typeof(km_scripts) == 'undefined') var km_scripts = new Object();
//km_myclass_import('importedfile.js');

function km_myclass_import(jsFile) {
  if (km_scripts[jsFile] != null) return;
  var scriptElt = document.createElement('script');
  scriptElt.type = 'text/javascript';
  scriptElt.src = jsFile;
  document.getElementsByTagName('head')[0].appendChild(scriptElt);
  km_scripts[jsFile] = jsFile; // or whatever value your prefer
}

function inc(filename)
{
var mybody = document.getElementsByTagName('body').item(0);
script = document.createElement('script');
script.src = filename;
script.type = 'text/javascript';
mybody.appendChild(script)
}


function loadMoviePlayer(youtubeMovieId){

      //de variabele YoutubeMovieId word in de mdd gedefinieerd (zie beschrijving bovenin deze file)
	  var youtubeURL = "http://www.youtube.com/v/" + youtubeMovieId;
      // <![CDATA[
       // allowScriptAccess must be set to allow the Javascript from one 
      // domain to access the swf on the youtube domain
      var params = { allowScriptAccess: "always", bgcolor: "#cccccc" };
      // this sets the id of the object or embed tag to 'myytplayer'.
      // You then use this id to access the swf and make calls to the player's API
      var atts = { id: "myytplayer" };
      swfobject.embedSWF(youtubeURL+"&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer",
                         "ytapiplayer", "425", "344", "8", null, null, params, atts);
      //]]>
	  }

function loadMovie(youtubeMovieId){
	google.load("swfobject", "2.1");
	//load container for movie when page has completed loading
	addLoadEvent(function(){loadMoviePlayer(youtubeMovieId);});	
}

//km_myclass_import("http://www.google.com/jsapi");
//inc("http://www.google.com/jsapi");

//write html to import google library for youtube
//document.write("<script type='text/javascript' src='http://www.google.com/jsapi'></scr"+"ipt>");






