/**
 * Module pour utiliser un calque opaque
 * 	Ce script necessite que
 *		- le fichier pngfix.js soit chargé avec un tag
 *		- une action soit ajouter sur le onresize du body "resizeDivOpaque"
 *		- une action soit ajouter sur le onload du body "writeDivOpaque"
 *		
 *	exemple :
 *	<!--[if lt IE 7]>
 *	<script defer type="text/javascript" src="{REP_SCRIPTS}js/pngfix.js"></script>
 *	<![endif]-->
 *
 * @author : Service Informatique
 * @version : 2008-06-04
 * @copyright : Monné-Decroix (service informatique)
 */

/**
 * Retourne la largeur et la hauteur de la partie visible du navigateur
 * 
 * @return tableau des tailles width et height
 */
function getWindowInner(){
	var innerWidth = 0;
	var innerHeight = 0;
	if(typeof(window.innerWidth) == 'number'){
		//Non-IE
		innerWidth = window.innerWidth;
		innerHeight = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		//IE 6+ in 'standards compliant mode'
		innerWidth = document.documentElement.clientWidth;
		innerHeight = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		//IE 4 compatible
		innerWidth = document.body.clientWidth;
		innerHeight = document.body.clientHeight;
	}
	var result = new Array(innerWidth, innerHeight);
	return result;
}

/**
 * Retourne la largeur et la hauteur de la partie utilisable du navigateur
 * 
 * @return tableau des tailles width et height
 */
function getWindowAvail(){
	var availWidth = 0;
	var availHeight = 0;
	if(typeof(window.innerWidth) == 'number'){
		//Non-IE
		if(document.body.offsetHeight < window.innerHeight){
			availWidth = window.innerWidth;
			availHeight = window.innerHeight;
		} else {
			availWidth = document.body.offsetWidth;
			availHeight = document.body.offsetHeight;
		}
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		//IE 6+ in 'standards compliant mode'
		if(document.body.offsetHeight < document.documentElement.clientHeight){
			availWidth = document.documentElement.clientWidth;
			availHeight = document.documentElement.clientHeight;
		} else {
			availWidth = document.body.offsetWidth;
			availHeight = document.body.offsetHeight;
		}
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		//IE 4 compatible
		availWidth = document.body.clientWidth;
		availHeight = document.body.clientHeight;
	}
	var result = new Array(availWidth, availHeight);
	return result;
}
		
/**
 * Resize un Div
 *
 * @param id Id du div a resizer 
 */
function resizeDivOpaque(id){
	var result = getWindowAvail();
	var availWidth = result[0];
	var availHeight = result[1];
	
	document.getElementById(id).style.width = availWidth+'px';
	document.getElementById(id).style.height = availHeight+'px';
	
	var id_img = 'img_'+id;
	document.getElementById(id_img).style.width = availWidth+'px';
	document.getElementById(id_img).style.height = availHeight+'px';
}

/**
 * Affiche un Div
 *
 * @param id Id du div a afficher 
 */	
function showDivOpaque(id){
	document.getElementById(id).style.visibility = 'visible';
}

/**
 * Masque un Div
 *
 * @param id Id du div a masquer 
 */	
function hideDivOpaque(id){
	document.getElementById(id).style.visibility = 'hidden';
}

/**
 * Ecrit le calque à la fin du HTML
 *
 * @param id Id du div opaque
 * @param img_background Chemin de l'img servant de fond
 * @param content Contenu a afficher au dessus ducalque opaque
 */	
function writeDivOpaque(id, img_background, content){
	var htmlDiv = '<div id="'+id+'" style="position:absolute; top:0px; left:0px; z-index:1; visibility:hidden;" align="center">'+
	'<img id="img_'+id+'" src="'+img_background+'" style="position:absolute; left:0; top:0;" />'+content+
	'</div>';

	addHTMLAfterBody(document.body, htmlDiv);
	
	if(typeof(pngfix_include) != 'undefined' && pngfix_include != null && pngfix_include == true){
		pngfix();
	}
}