// JavaScript Document
function gamesModule(station,version,color,maxQuestions){
	color = color ? color : "green" ;
    var dimension = {     Medium:{width:400,height:115},
                           Large:{width:300,height:250}
                    };
					
    var width = dimension[version].width;
    var height = dimension[version].height;
    var script_name = 'stationGamesModule.js';
    var script = getModuleScript(script_name);
    var o = getObject(station,version,color,width,height,maxQuestions);
    script.parentNode.insertBefore(o, script);
    script.parentNode.removeChild(script);
}
 
function getModuleScript(script_name){
    var scripts = document.body.getElementsByTagName('script');
        for (i = 0; i < scripts.length; i++) {
                if (scripts[i].src.indexOf(script_name) != -1) {
                        script = scripts[i];
                        break;
                }
        }
    return script;
}
 
function getObject(station,version,color,width,height,maxQuestions){
    var flashvars = 'stationCallLetters=' + station + '&maxQuestions=' + maxQuestions;
    var swf_url = 'http://pbskids.org/modules/gamesModule/'+color.toLowerCase()+'/'+ width + 'x' + height + 'stationModules' + version + 'Games.swf';
   
    var s = document.createElement('span');
    var o = "<object type='application/x-shockwave-flash' " +
            " data='" + swf_url + "' " +
            "width='" + width + "' " +
            "height='" + height + "' >" +
	    "<param name=allowScriptAccess value=always>" +
            "<param name='flashvars' value='" + flashvars + "' />" +
            "<param name='movie' value='" + swf_url + "' />"; 
    
 
    s.innerHTML = o;
    return s;
}
