//script de déplacement de l'imprimante / suit la page
//params
layerName = "printLayer"; //nom du calque
imgSrc    = "http://www.gersemploi.com/fiches-info/0imagesfiches/imprimante.png"; //fichier image
topStart  = 35; //positionnement de départ du calque (top)

function fnInsertPrint()
{
	// Création d'un div
	var oD = document.createElement('div');
	oD.setAttribute('id', layerName);
	oD.style.position="absolute";
	oD.style.height="18px";
	oD.style.width="18px";
	oD.style.left="0%";
	oD.style.top = topStart+"px";
	
	// Création d'un lien
	var oA = document.createElement('a');
	oA.setAttribute('href', '#print');
	
	// Création d'une image
	var oI = document.createElement('img');
	oI.setAttribute('src', imgSrc);
	oI.setAttribute('width',  16);
	oI.setAttribute('height', 16);
	oI.setAttribute('title', 'Imprimer cette page');
	oI.setAttribute('alt',   'Imprimer cette page');
	oI.style.border="0";
	
	oA.appendChild(oI);//ajoute le noeud img au lien
	oD.appendChild(oA);//ajoute le noeud lien au div
	
	// Affectation de la méthode print() au clic sur le lien
	oA.onclick = function() { window.print(); return false; }
	
	// Positionnement du lien dans la page
	/*
	if( document.getElementById('conteneur') )
		var oCont = document.getElementById('conteneur');  //ajoute le noeud div au conteneur (ici = BODY)
	else
		var oCont = document.getElementsByTagName('body')[0];	
	*/
	var oCont = document.getElementsByTagName('body')[0];
	
	if(!oCont) return;
	oCont.appendChild(oD); //ajoute le noeud div au conteneur (ici = BODY)
	//src: http://css.alsacreations.com/Tutoriels-JavaScript/bonnes-pratiques-javascript
	
	//fixe la transparence du png sur IE5.5-IE6 sur l'imprimante.
	pngFix();
	
	//lance de déplacement
	movePrinter();
}

//fixe la transparence du png sur image imprimante.
function pngFix() {
	/*
	Correctly handle PNG transparency in Win IE 5.5 & 6.
	http://homepage.ntlworld.com/bobosola.
	*/
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5 && version < 7) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
	return true;
}

//déplacement suit la page
function movePrinter()
{
	var div1 = document.getElementById( layerName ).style;

	if (navigator.appName=="Microsoft Internet Explorer")
		offsety = document.documentElement.scrollTop + document.body.scrollTop /* documentElement.scrollTop pour les DOCTYPE recents et body.scrollTop si aucun DOCTYPE ou mode Quirk, etc... Suivant le DOCTYPE, le 1er ou le 2nd sera égal à 0 */
	else 
		offsety = window.pageYOffset;
	
	div1.top = offsety + topStart +"px";
	tempo = setTimeout("movePrinter()",50);
}

// Lancement de la fonction fnInsertPrint()
window.onload = fnInsertPrint;

