// Bootstrap the different JS files needed function loadJS(url, callback){ var script = document.createElement("script"); script.src = url; script.type = 'text/javascript'; script.onload = callback; script.onreadystatechange = function() { if (this.readyState == 'complete' || this.readyState == 'loaded') { callback(); } }; document.getElementsByTagName("head")[0].appendChild(script); //document.head.appendChild(script); } function loadCSS(href, callback){ var css = document.createElement("link"); css.href = href; css.rel = "stylesheet"; css.media = "all"; css.type = 'text/css'; document.getElementsByTagName("head")[0].appendChild(css); callback(); //document.head.appendChild(script); } function createCallBack(args,cb){ return function(){ cb(args); }; } function initFiles(files){ if(files.length > 0){ var row = files.shift(); var type = row[0]; var file = row[1]; var cbTemplate = function(arg){ initFiles(arg); }; var cb = createCallBack(files, cbTemplate); if(type=="js"){ loadJS(file,cb); } if(type=="css"){ loadCSS(file, cb); } } } var files = [ ['css','http://uidget.appspot.com/vaa/vaa_uk-widget_us-hk-terms/image.css'], ['js','http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'], ['js','http://uidget.appspot.com/vaa/vaa_uk-widget_us-hk-terms/drawer3.js'], ['js','http://www.virgin-atlantic.com/en/gb/js/common_booking.js'], ['js','http://www.virgin-atlantic.com/en/gb/js/booking.js'], ['js','http://www.virgin-atlantic.com/en/gb/js/date.js'], ['js','http://uidget.appspot.com/vaa/static/va-js-1.new.js'], ['js','http://uidget.appspot.com/vaa/static/vaa_init.js']]; initFiles(files);