// JavaScript Document

var debugDiv;
var head;
var currentLoadScript = 0;
var scripts = [
"http://yui.yahooapis.com/combo?2.9.0/build/yahoo-dom-event/yahoo-dom-event.js&2.9.0/build/connection/connection-min.js&2.9.0/build/container/container-min.js&2.9.0/build/cookie/cookie-min.js",
	ROOT+"popin/script.js"
];
var styles = [
	'http://yui.yahooapis.com/combo?2.9.0/build/container/assets/skins/sam/container.css',
	ROOT+'popin/style.css',
	ROOT+'popin/html/style.css'
];
var ie6 = false;
var ie7 = false;
var ie8 = false;

if (typeof(document.all) != "undefined") {
	if ((document.compatMode && document.all) && !(document.documentElement && typeof document.documentElement.style.maxHeight!="undefined"))
		ie6 = true;
	else if ((document.documentElement && typeof(document.documentElement.style.maxHeight)!="undefined") && (typeof(XDomainRequest) != "function"))
		ie7 = true;
	else if ((typeof(XDomainRequest) == "function") && (typeof(window.styleMedia) !="object"))
		ie8 = true;
}

function initalise() {
	debugDiv = document.createElement("div");
	debugDiv.id = "debug";
	debugDiv.style.position = "absolute";
	debugDiv.style.top = "50px";
	debugDiv.style.left = 0;
	debugDiv.style.zIndex = 9999;
	debugDiv.style.width = "300px";
	debugDiv.style.backgroundColor = "#FFF";
	//window.document.body.appendChild(debugDiv);
	
	
	head = document.getElementsByTagName("head")[0];
	
	// On construit et charge le style de la popin
	for (i=0; i<styles.length; i++)	{
		var newStyle = document.createElement('link');
		newStyle.rel = 'stylesheet';
		newStyle.type = 'text/css';
		if (i > 0)
			newStyle.href = styles[i]+"?d=" + new Date().getTime();
		else
			newStyle.href = styles[i];
		head.appendChild(newStyle);
	}
	loadScript();
}

function loadScript() {
	if (currentLoadScript < scripts.length) {
		var newScript = document.createElement('script');
		newScript.type = 'text/javascript';
		newScript.src = scripts[currentLoadScript];//+"?d=" + new Date().getTime();
		head.appendChild(newScript);
		
		if (ie6 || ie7 || ie8) {
			newScript.onreadystatechange = function() {
				if (this.readyState == "loaded")
					loadScript();
			};
		} else {
			newScript.onload = loadScript;
		}
	}
	currentLoadScript++;
}

window.onload = initalise;
