window.onresize = adjustLayout;
window.onload = adjustLayout;

/**
 * feuille de style "apple"
 */
if(navigator.platform == "MacIntel" || "iPhone,iPad,iPod".indexOf(navigator.platform) > -1 ) {
	var fileref=document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", "./css/safari.css");
	setCSS(fileref);
}
function setCSS(css)
{
	try {
		document.getElementsByTagName("head")[0].appendChild(css);
	} catch (e) {
		setTimeout(function(){setCSS(css)}, 100);
	}
}

/**
 * ajustements
 */
function adjustLayout()
{
	fixBookmark();
	fixBackground();
}
/**
 * positions dans le "bookmark"
 */
function fixBookmark()
{
	var nav = getObj("nav");
	var iso = getObj("isoImg");
	
	var H = 640; 
	var navMT = 84;
	var navMB = 40;
	var isoMT = 116;
	var minH = 131 + 100 + nav.offsetHeight; // hauteur minimum en dessous de laquelle aucune compression supplémentaire n'est appliquée
	var h;
	
	if (window.innerHeight) h = window.innerHeight;
	else h = document.documentElement.clientHeight;
	
	if (h < H && h > minH) {
		//var p = (h-minH)/(H-minH);
		// on n'utilise que 90% de l'espace disponible (H-minH)*(1-0.1)
		var minP = 0.1;
		// pourcentage à appliquer aux marges, en fonction de l'espace disponible
		// p: 0.1 ->1 quand h:minH -> H
		var p = (1-minP)/(H-minH)*h + minP - (1-minP)*minH/(H-minH); 
		nav.style.marginTop = p * navMT + "px";
		nav.style.marginBottom = p * navMB + "px";
		iso.style.marginTop = p * isoMT + "px";
	} else if (h>H) {
		nav.style.marginTop = navMT + "px";
		nav.style.marginBottom = navMB + "px";
		iso.style.marginTop = isoMT + "px";
	}
}
/**
 * fond
 */
function fixBackground() {
	if (document.body.clientWidth < 960) {
		getObj("main").style.backgroundPosition = "0% 0%";
	} else {
		getObj("main").style.backgroundPosition = "50% 0%";
	}
}

/**
 * outils
 */
function getObj(name)
{
	if (document.getElementById) return document.getElementById(name);
	else if (document.all) return document.all[name];
}
