/*
* freepaper_spip-min.js
* franck ruzzin
* le 26/08/2008
*/

m_freepaper_swfUrl="plugins/freepaper/swf/freepaper.0.6.0.swf";	//obligatoire : chemin et nom vers le fichier swf "freepaper.swf"
m_freepaper_phpURL="plugins/freepaper/php/freepaper_spip.php";	//URL du script PHP freepaper.php
// m_freepaper_ExtractFromDOM : Boolean
//Si vrai, alors le noeud FreepapeR est isolé du DOM pour être affiché en pleine page, puis les noeuds de la page sont restaurés dans leur configurations initiales pour l'affichage en mode normal
m_freepaper_ExtractFromDOM=false;

freepaper={embedDoc:function(A,F,B){if(!F.width){F.width=600}if(!F.height){F.height=800}if(!B.altContentId){B.altContentId="freepaper1"}B.id=B.altContentId+"_ready";A.playerId=B.id;var D=document.getElementById(B.altContentId);D.style.height=F.height+"px";D.style.width=F.width+"px";var E=this.getXhr();if(!E){throw new Error("Impossible d'ouvrir une communication xhr.")}var C=this;E.onreadystatechange=function(){if(E.readyState==4){if(E.status==200){if(B.trace==true){alert(E.responseText)}var I=E.responseText.lastIndexOf("TRYING WITH -> ");if(I>0){var H=/IMG\/pdf/;A.pdfURL=A.pdfURL.replace(H,"IMG/swf")}C.display(A,F,B)}else{var G="Ouverture de "+m_freepaper_phpURL+"\n";G+="Erreur: "+E.status+" "+E.statusText;alert(G)}}};E.open("POST",m_freepaper_phpURL,true);E.setRequestHeader("Content-Type","application/x-www-form-urlencoded");E.send("docURL="+A.pdfURL+"&callerURL="+document.URL)},display:function(A,C,B){A.swfURL=A.pdfURL+".swf";A.pdfURL=null;B.styleclass="freepaper";swfobject.embedSWF(m_freepaper_swfUrl,B.altContentId,C.width,C.height,"8.0.0",false,A,C,B);setTimeout(freepaper.resetGetFlashPlayer_Proxy(B.altContentId),500)},resetGetFlashPlayer_Proxy:function(B){var A=this;return function(){A.resetGetFlashPlayer(B)}},resetGetFlashPlayer:function(C){var B=document.getElementById(C);if(B){B.style.backgroundImage="url(plugins/freepaper/images/empty.gif)";var A=B.getElementsByTagName("IMG")[0];A.style.display="block";alert("Téléchargez le plugin Flash !")}},getXhr:function(){var B=null;if(window.XMLHttpRequest){B=new XMLHttpRequest()}else{if(window.ActiveXObject){try{B=new ActiveXObject("Msxml2.XMLHTTP")}catch(A){B=new ActiveXObject("Microsoft.XMLHTTP")}}else{alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");B=false}}return B},fitToPage:function(B){if(fpdomutil.isIE6){alert("Fonction non disponible sous IE6");var A=document.getElementById(B);A.setPageState(false);return }if(typeof this.objectData!="undefined"){alert("il n'est pas possible d'afficher en pleine page plusieurs documents simultanément");var A=document.getElementById(B);A.setPageState(false);return }if(fpdomutil.isOpera){m_freepaper_ExtractFromDOM=true}setTimeout(this.initFullPageDisplay_proxy(document.getElementById(B)),100)},initFullPageDisplay_proxy:function(A){return function(){freepaper.initFullPageDisplay(A)}},initFullPageDisplay:function(B){this.objectData=new Object();this.objectData.nodeRef=B;this.objectData.bodyMarginTop=fpdomutil.getStyle(document.body,"margin-top","marginTop");if(!this.objectData.bodyMarginTop){this.objectData.bodyMarginTop=0}this.objectData.bodyMarginLeft=fpdomutil.getStyle(document.body,"margin-left","marginLeft");if(!this.objectData.bodyMarginLeft){this.objectData.bodyMarginLeft=0}this.objectData.bodyMarginRight=fpdomutil.getStyle(document.body,"margin-right","marginRight");if(!this.objectData.bodyMarginRight){this.objectData.bodyMarginRight=0}this.objectData.bodyMarginBottom=fpdomutil.getStyle(document.body,"margin-bottom","marginBottom");if(!this.objectData.bodyMarginBottom){this.objectData.bodyMarginBottom=0}this.objectData.width=fpdomutil.getObjectWidth(B);this.objectData.height=fpdomutil.getObjectHeight(B);this.objectData.marginLeft=parseInt(B.style.marginLeft);if(isNaN(this.objectData.marginLeft)){this.objectData.marginLeft=0}this.objectData.marginTop=parseInt(B.style.marginTop);if(isNaN(this.objectData.marginTop)){this.objectData.marginTop=0}this.objectData.marginBottom=parseInt(B.style.marginBottom);if(isNaN(this.objectData.marginBottom)){this.objectData.marginBottom=0}this.objectData.marginRight=parseInt(B.style.marginRight);if(isNaN(this.objectData.marginRight)){this.objectData.marginRight=0}if(m_freepaper_ExtractFromDOM){document.body.style.margin=0;myClone=B.cloneNode(true);this.objectData.nodeRef=myClone;this.objectData.newElem=document.createElement("div");var A=document.body.childNodes;while(A.length){this.objectData.newElem.insertBefore(A.item(0),null)}document.body.insertBefore(myClone,document.body.firstChild)}else{document.body.style.marginTop="-999999px";document.body.style.marginLeft="-999999px"}if(fpdomutil.isIE){setTimeout(this.refreshFitToPage,400)}else{this.refreshFitToPage()}},refreshFitToPage:function(){if(typeof freepaper.objectData=="undefined"){return }var C=freepaper.objectData.nodeRef;var A=20;myPlayer=C;var B=0;if(fpdomutil.isSafari){B=200}setTimeout(D,B);function D(){if(myPlayer.setPageState){myPlayer.setPageState(true)}else{if(A>0){A--;setTimeout(D,200)}}}deltaX=1;deltaY=1;if(m_freepaper_ExtractFromDOM){C.style.marginLeft="0px";C.style.marginTop="0px";deltaY=4}else{var F=fpdomutil.getObjectLeft(C)-fpdomutil.getScrollLeft();var E=fpdomutil.getObjectTop(C)-fpdomutil.getScrollTop();marginLeft=parseInt(C.style.marginLeft);if(isNaN(marginLeft)){marginLeft=0}C.style.marginLeft=(marginLeft-F)+"px";marginTop=parseInt(C.style.marginTop);if(isNaN(marginTop)){marginTop=0}C.style.marginTop=(marginTop-E)+"px";C.style.marginBottom="-968000px";C.style.marginRight="-999999px"}C.style.height=(fpdomutil.getNavigatorHeight()-deltaY)+"px";C.style.width=(fpdomutil.getNavigatorWidth()-deltaX)+"px"},addResizeEvent:function(A){if(typeof window.onresize!="function"){window.onresize=A}else{window.onresize=function(){onresize();A()}}},restoreDisplay:function(){setTimeout(this._restoreDisplayWithDelay,100)},_restoreDisplayWithDelay:function(){document.body.style.marginTop=freepaper.objectData.bodyMarginTop;document.body.style.marginLeft=freepaper.objectData.bodyMarginLeft;if(m_freepaper_ExtractFromDOM){document.body.style.marginRight=freepaper.objectData.bodyMarginRight;document.body.style.marginBottom=freepaper.objectData.bodyMarginBottom;document.body.removeChild(document.body.childNodes.item(0));var A=freepaper.objectData.newElem.childNodes;while(A.length){document.body.insertBefore(A.item(0),null)}}else{var B=freepaper.objectData.nodeRef;B.style.marginBottom=freepaper.objectData.marginBottom+"px";B.style.marginRight=freepaper.objectData.marginRight+"px";B.style.marginLeft=freepaper.objectData.marginLeft+"px";B.style.marginTop=freepaper.objectData.marginTop+"px";B.style.width=freepaper.objectData.width+"px";B.style.height=freepaper.objectData.height+"px"}delete (freepaper.objectData)}};freepaper.addResizeEvent(freepaper.refreshFitToPage);var fpdomutil={getObjectLeft:function(C){var B=(typeof (C)=="string")?document.getElementById(C):C;var A=0;A=B.offsetLeft;while(B.offsetParent){B=B.offsetParent;A+=B.offsetLeft}return parseInt(A)},getObjectTop:function(C){var B=(typeof (C)=="string")?document.getElementById(C):C;var A=0;A=B.offsetTop;while(B.offsetParent){B=B.offsetParent;A+=B.offsetTop}return parseInt(A)},getObjectWidth:function(C){var B=(typeof (C)=="string")?document.getElementById(C):C;var A=0;A=B.offsetWidth;return parseInt(A)},getObjectHeight:function(C){var B=(typeof (C)=="string")?document.getElementById(C):C;var A=0;A=B.offsetHeight;return parseInt(A)},getNavigatorHeight:function(){if(window.innerHeight){return window.innerHeight}else{if(document.body){if(document.body.parentElement&&document.body.parentElement.clientHeight){return document.body.parentElement.clientHeight}else{if(document.body.clientHeight){return document.body.clientHeight}}}}return 0},getNavigatorWidth:function(){if(window.innerWidth){return window.innerWidth}else{if(document.body){if(document.body.parentElement&&document.body.parentElement.clientWidth){return document.body.parentElement.clientWidth}else{if(document.body.clientWidth){return document.body.clientWidth}}}}return 0},getDocumentHeight:function(){return document.body.scrollHeight},getDocumentWidth:function(){return document.body.scrollWidth},getScrollTop:function(){if(window.innerWidth){return window.pageYOffset}else{return document.documentElement.scrollTop}},getScrollLeft:function(){if(window.innerWidth){return window.pageXOffset}else{return document.documentElement.scrollLeft}},addNewRule:function(B,A,D,C){if(document.styleSheets){if(document.styleSheets[B].cssRules){document.styleSheets[B].insertRule(A+"{"+D+";}",C)}else{if(document.styleSheets[B].rules){document.styleSheets[B].addRule(A,D,C)}}}},deleteRule:function(A,B){if(document.styleSheets){if(document.styleSheets[A].cssRules){document.styleSheets[A].deleteRule(B)}else{if(document.styleSheets[A].rules){document.styleSheets[A].removeRule(B)}}}},getCssRules:function(A){if(typeof (A)=="undefined"){A=0}if(document.styleSheets){if(document.styleSheets[A].cssRules){return document.styleSheets[A].cssRules}else{if(document.styleSheets[A].rules){return document.styleSheets[A].rules}}}},getScrollBarWidth:function(){var C=document.createElement("p");C.style.width="100%";C.style.height="200px";var D=document.createElement("div");D.style.position="absolute";D.style.top="0px";D.style.left="0px";D.style.visibility="hidden";D.style.width="200px";D.style.height="150px";D.style.overflow="hidden";D.appendChild(C);document.body.appendChild(D);var B=C.offsetWidth;D.style.overflow="scroll";var A=C.offsetWidth;if(B==A){A=D.clientWidth}document.body.removeChild(D);return(B-A)},getStyle:function(C,B,A){if(window.getComputedStyle){retVal=document.defaultView.getComputedStyle(C,null).getPropertyValue(B)}else{if(C.currentStyle){retVal=C.currentStyle[A]}}return retVal},isIE6:navigator.userAgent.toLowerCase().indexOf("msie 6")!=-1,isIE:navigator.userAgent.toLowerCase().indexOf("msie")!=-1,isFF3:navigator.userAgent.toLowerCase().indexOf("firefox/3")!=-1,isSafari:navigator.userAgent.toLowerCase().indexOf("safari")!=-1,isOpera:navigator.userAgent.toLowerCase().indexOf("opera")!=-1};