/*
* freepaper_spip.js
* franck ruzzin
* le 07/12/2008
*/

m_freepaper_swfUrl="plugins/freepaper/swf/freepaper.0.7.0.swf";	//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;
// m_freepaper_OpenInNewWindow : Boolean
//Si vrai, le lecteur Freepaper est ouvert dans une nouvelle fenêtre lors de la visualisation pleine page
m_freepaper_OpenInNewWindow=false;

freepaper={swfArray:new Array(),xmlArray:new Array(),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;if(!this.swfArray[B.altContentId+"_ready"]){this.swfArray[B.altContentId+"_ready"]=A.swfURL;this.xmlArray[B.altContentId+"_ready"]=A.xmlDataPath}B.styleclass="freepaper";swfobject.embedSWF(m_freepaper_swfUrl,B.altContentId,C.width,C.height,"8.0.0",false,A,C,B);setTimeout(this.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},isDocumentLoaded:Boolean,documentLoaded:function(){isDocumentLoaded=true},fitToPage:function(B){var A=document.getElementById(B);if(fpdomutil.isIE6){alert("Fonction non disponible sous IE6");A.setPageState(false);return }if(m_freepaper_OpenInNewWindow){this.openInNewWindow(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");A.setPageState(false);return }if(fpdomutil.isOpera){m_freepaper_ExtractFromDOM=true}isDocumentLoaded=false;setTimeout(this.initFullPageDisplay_proxy(document.getElementById(B)),100)},openInNewWindow:function(G){var E=window.open("","","menubar=no,resizable=yes,scrollbars=no","false");var C=screen.availWidth;var H=screen.availHeight;E.moveTo(0,0);E.resizeTo(C,H);var B=window.location+"";if(B.charAt(B.length-1)!="/"){var A=B.lastIndexOf("/");if(A>-1){B=B.substr(0,A+1)}}var D="swfURL="+B+this.swfArray[G]+"&xmlDataPath="+B+this.xmlArray[G]+"&noFitButton=true";var F=m_freepaper_swfUrl+"?"+D;E.location=F},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;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";var A=20;myPlayer=C;var B=0;setTimeout(D,B);function D(){if(myPlayer.setPageState&&isDocumentLoaded){myPlayer.setPageState(true)}else{if(A>0){A--;setTimeout(D,200)}}}},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)}var E=freepaper.objectData.nodeRef;var B=document.getElementById(E.id);var D=B.parentNode;D.replaceChild(E,B);E.style.width=freepaper.objectData.width+"px";E.style.height=freepaper.objectData.height+"px"}else{var C=freepaper.objectData.nodeRef;C.style.marginBottom=freepaper.objectData.marginBottom+"px";C.style.marginRight=freepaper.objectData.marginRight+"px";C.style.marginLeft=freepaper.objectData.marginLeft+"px";C.style.marginTop=freepaper.objectData.marginTop+"px";C.style.width=freepaper.objectData.width+"px";C.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};