﻿/* Sesame video player 
usage: 
	sesamevideo.embed(id,flashvars);
*/
var sesamevideo = function(){
	var baseUrl = "http://archive.sesameworkshop.org/podcasts/player/";
	var playerUrl = baseUrl + "player.htm";
	var width = 430;
	var height = 510;
	var version = "9.0.115.0";

	return {
		// deferred processing
		embed:function(id, uservars){			
				var oldonload = window.onload;
				if (typeof window.onload != 'function') {
					window.onload = function() { sesamevideo.doEmbed(id, uservars) };
				} else {
					window.onload = function() {
						if (oldonload) {
							oldonload();
						}	
						sesamevideo.doEmbed(id, uservars);
					}
				}
		},
		// actually embed
		doEmbed : function(id, uservars){
			var qString = playerUrl.indexOf("?")>=0 ? "" : "?";
			var qArray = [];
			uservars.shareUrl = document.location.href;
			for(var o in uservars){ qArray.push(o+"="+escape(uservars[o])) }
			playerUrl += (qString + qArray.join("&"));
			var domObj = document.getElementById(id);			
			var iframe = document.createElement("iframe");
			iframe.setAttribute("width",width);
			iframe.setAttribute("height",height);
			iframe.setAttribute("src",playerUrl);
			iframe.setAttribute("frameBorder","no");
			iframe.setAttribute("scrolling","no");			
			iframe.setAttribute("allowTransparency","true");	
			if(domObj) {
				domObj.innerHTML = "";
				domObj.appendChild(iframe);
			}
		}
	};
}();

