var scPresMgr = scOnLoads[scOnLoads.length] = {

	next : function(pDontShift){
		if(this.fEditMode) this.saveEditedPage();
		if( ! pDontShift) this.fCurrStepIdx++;
		var vPg = this.getCurrPg();
		//En mode normal, on saute les pages hidden
		if( ! this.fEditMode) while(vPg.hiddenPg) {
			if( this.fCurrPgIdx < this.fPageList.length-1) {
				this.fCurrPgIdx++;
				this.fCurrStepIdx = 1;
				vPg = this.getCurrPg();
			} else {
				this.home();
				return;
			}
		}
		//Controle de chargement de la page
		if( ! ("fSteps" in vPg)) {
			this.setWait(true);
			this.fPendingTask = { execTask : function(){ scPresMgr.next(true);  return false;} };
			this.bindPgToSrcFrm(vPg);
			return;
		}
		//Controle des limites
		if( ! pDontShift && (this.fCurrStepIdx >= vPg.fSteps.length || this.fEditMode)) {
			//Page suivante
			if( this.fCurrPgIdx < this.fPageList.length-1) {
				this.fCurrPgIdx++;
				this.fCurrStepIdx = 1;
				this.next(true);
			} else {
				this.editMode(false);
				this.home();
			}
			return;
		}
		//Activation de la page trouvée
		if(this.fEditMode) {
			this.editPage(vPg);
		} else {
			this.activeStep(vPg);
		}
		this.redrawProgressBar();
	},
	
	prev : function(pDontShift){
		if(this.fEditMode) this.saveEditedPage();
		if(!pDontShift) {
			if(this.oViewHome == this.fCurrView) {
				return;
				//this.fCurrPgIdx = this.fPageList.length-1;
				//this.fCurrStepIdx = -1;
				//this.prev(true);
			}
			this.fCurrStepIdx--;
		}
		var vPg = this.getCurrPg();
		//En mode normal, on saute les pages hidden
		if( ! this.fEditMode) while(vPg.hiddenPg) {
			if( this.fCurrPgIdx > 0) {
				this.fCurrPgIdx--;
				this.fCurrStepIdx = -1;
				vPg = this.getCurrPg();
			} else {
				this.home();
				return;
			}
		}
		//Controle de chargement de la page
		if( ! ("fSteps" in vPg)) {
			this.setWait(true);
			this.fPendingTask = { execTask : function(){ scPresMgr.prev(true);  return false;} };
			this.bindPgToSrcFrm(vPg);
			return;
		}
		//Controle des limites
		if(this.fCurrStepIdx == 0 ||  (!pDontShift && this.fEditMode)) {
			//Page précédente
			if( this.fCurrPgIdx > 0) {
				this.fCurrPgIdx--;
				this.fCurrStepIdx = -1;
				this.prev(true);
			} else {
				this.home();
			}
			return;
		}
		//Activation de la page trouvée
		if(this.fEditMode) {
			this.editPage(vPg);
		} else {
			this.activeStep(vPg);
		}
		this.redrawProgressBar();
	},
	
	home : function(){
		if(this.fEditMode) this.editMode(false);
		this.fCurrPgIdx = -1;
		this.fCurrStepIdx = 0;
		this.setCurrentView(this.oViewHome, "");
		this.setWait(false);
		this.redrawProgressBar();
	},
	
	activeStep : function(pPage){
		//Recherche la Step à afficher
		var vStepIdx = (this.fCurrStepIdx < 0) ? pPage.fSteps.length + this.fCurrStepIdx : this.fCurrStepIdx;
		vStepIdx = Math.min(Math.max(vStepIdx, 1), pPage.fSteps.length-1);
		var vStep = pPage.fSteps[vStepIdx];
		//Affiche la Step
		vStep.show(pPage.fSteps, vStepIdx, this.fLastStep);
		//Finalise l'affichage
		this.fCurrStepIdx = vStepIdx;
		this.fLastStep = vStep;
		this.setWait(false);
		this.preload();
	},
	editPage : function(pPage){
		this.fEditedPageDirty = false;
		while(this.oEditor.hasChildNodes()) this.oEditor.removeChild(this.oEditor.lastChild);
		var vCh = pPage.fSrcFrm.contentWindow.document.body.firstChild;
		while(vCh) {
			scPresUt.importDeepNodeEdit(vCh, document, this.oEditor);
			vCh = vCh.nextSibling;
		}
		this.redrawTitleEditPage(pPage);
		this.hideAllSupWindows();
		this.setWait(false);
		this.preload();
	},
	redrawTitleEditPage : function(pPage){
		this.oEditorTitle.innerHTML = pPage.fTitlePg;
		this.oEditorTitle.className = (pPage.hiddenPg) ? "hiddenTitlePage" : "";
	},
	
	getCurrPg : function(){
		this.fCurrPgIdx = Math.min(Math.max(this.fCurrPgIdx, 0), this.fPageList.length-1);
		return this.fPageList[this.fCurrPgIdx];
	},
	getRealPg : function(){
		if(this.fCurrPgIdx >= 0 && this.fCurrPgIdx < this.fPageList.length) return this.fPageList[this.fCurrPgIdx];
		return null;
	},
	getBoundedStep : function(pPage){
		var vStepIdx = (this.fCurrStepIdx < 0) ? pPage.fSteps.length + this.fCurrStepIdx : this.fCurrStepIdx;
		vStepIdx = Math.min(Math.max(vStepIdx, 1), pPage.fSteps.length-1);
		this.fCurrStepIdx = vStepIdx;
		return pPage.fSteps[vStepIdx];
	},
	
	preload : function(){
		if( this.fCurrPgIdx < this.fPageList.length-1) {
			//Si courant Ok, on preload le suivant
			vPg = this.fPageList[this.fCurrPgIdx + 1];
			if( ! ("fSrcFrm" in vPg)) this.bindPgToSrcFrm(vPg);
		}
		if( this.fCurrPgIdx > 0){
			//On preload le précédent si nécessaire
			vPg = this.fPageList[this.fCurrPgIdx - 1];
			if( ! ("fSrcFrm" in vPg)) this.bindPgToSrcFrm(vPg);
		}
	},
	bindPgToSrcFrm : function(pPage){
		//Chargement en cours.
		if("fSrcFrm" in pPage) return;
		//TODO limiter le pool...
		this.fSrcFrmCount++;
		var vId = "srcFrm"+this.fSrcFrmCount;
		var vFrm = document.createElement("iframe");
		vFrm.setAttribute("id", vId);
		vFrm.setAttribute("name", vId);
		this.oPoolSrc.appendChild(vFrm);
		pPage.fSrcFrm = vFrm;
		vFrm.fPg = pPage;
		if(scCoLib.isIE) vFrm.onreadystatechange = this.onloadSrcFrm;
		else vFrm.onload = this.onloadSrcFrm;
		vFrm.src = pPage.getAttribute("href");
		return vFrm;
	},
	onloadSrcFrm : function(pEvent){
		try{
			if(scCoLib.isIE && this.readyState != "complete") return;
			scPresMgr.computeSrcFrm(this);
			scPresMgr.retryPendingTask();
		}catch(e){
			scCoLib.util.logError("Echec au chargement de la page.", e);
		}
	},
	computeSrcFrm : function(pSrcFrm){
		var vPage = pSrcFrm.fPg;
		pSrcFrm.contentWindow.fPg = vPage;
		var vBody = pSrcFrm.contentWindow.document.body;
		//Load des params...
		var vDataParams = scPresStor.getPageData(vPage.getAttribute("href"));
		// 1.Affectation des Bhv
		for(var i = 0; i < this.fBhvBinders.length; i++) this.fBhvBinders[i].bindNodes(vPage, vBody);
		// 2.Compute des Bhv
		var vCh = vBody.firstChild;
		while(vCh){
			var vIterChildren = false;
			if(vCh.nodeType == 1) vIterChildren = ("fBhv" in vCh) ? vCh.fBhv.computeParams(vPage, vDataParams) : true;
			if(vIterChildren && vCh.hasChildNodes()){
				vCh = vCh.firstChild;
				continue;
			}
			while( ! vCh.nextSibling) {
				vCh = vCh.parentNode;
				if(vCh == vBody) {
					vCh = null;
					break;
				}
			}
			if(vCh) vCh = vCh.nextSibling;	
		}
		// 3.Construction des Steps, 1er step à l'idx 1, 1er step à l'idx 1
		this.buidPageSteps(pSrcFrm);
	},
	buidPageSteps : function(pSrcFrm){
		var vPage = pSrcFrm.fPg;
		var vBody = pSrcFrm.contentWindow.document.body;
		// 3.Construction des Steps, 1er step à l'idx 1, 1er step à l'idx 1
		var vSteps = [null];
		var vCh = vBody.firstChild;
		while(vCh){
			var vIterChildren = false;
			if(vCh.nodeType == 1) vIterChildren = ("fBhv" in vCh) ? vCh.fBhv.buildSteps(vSteps) : true;
			if(vIterChildren && vCh.hasChildNodes()){
				vCh = vCh.firstChild;
				continue;
			}
			while( ! vCh.nextSibling) {
				vCh = vCh.parentNode;
				if(vCh == vBody) {
					vCh = null;
					break;
				}
			}
			if(vCh) vCh = vCh.nextSibling;	
		}
		if( ! vSteps[1]) {
			//Si aucun step, on suppr cette page.
			//this.setHiddenPg(vPage, true);
			
			//Si aucun step, on ajoute tout le doc.
			vSteps[1] = {
				fBody : vBody,
				show : function(pStepList, pThisStepIdx, pCurrentStep){
					var vView = scPresMgr.getFreeView();
					vView.innerHTML = this.fBody.innerHTML;
					scPresMgr.setCurrentView(vView);
				}
			}
		}
		//Affectation du tableau des steps, ce srcFrm est opérationnel.
		vPage.fSteps = vSteps;
	},
	retryPendingTask : function(){
		var vTask = this.fPendingTask;
		if(vTask) {
			this.fPendingTask = null;
			scTiLib.addTaskNow(vTask);
		}
	},
	
	getFreeView : function(){
		if(this.fCurrAnimTask) {
			this.fCurrAnimTask.terminate();
			this.fCurrAnimTask = null;
		}
		var vFreeView = (this.oView1 == this.fCurrView) ? this.oView2 : this.oView1;
		this.resetView(vFreeView);
		return vFreeView;
	},
	resetView : function(pView){
		var vCh;
		while(vCh = pView.lastChild) pView.removeChild(vCh);
	},
	setCurrentView : function(pView, pTitle){
		this.hideAllSupWindows();
		if(this.fCurrAnimTask) this.fCurrAnimTask.terminate();
		if(pTitle==null) {
			var vPg = this.getCurrPg();
			pTitle = vPg.fTitlePg;
		}
		var vChangeTitle = this.fCurrView.fTitle != pTitle;
		if(vChangeTitle) this.oTitle.innerHTML = pTitle;
		this.switchViewTask.initTask(this.fCurrView, pView, vChangeTitle);
		this.fCurrView = pView;
		this.fCurrView.fTitle = pTitle;
		this.fCurrAnimTask = this.switchViewTask;
		scSiLib.fireResizedNode(pView);
		scTiLib.addTaskNow(this.switchViewTask);
	},
	hideAllSupWindows : function() {
		scPresTools.hideOutline();
		this.displayZoom(false);
	},
	setOpacity: function(pNode, pRate){
		if(scCoLib.isIE) pNode.filters.item("DXImageTransform.Microsoft.Alpha").opacity = pRate*100;
		else pNode.style.opacity = pRate;
	},
	startOpacityEffect: function(pNode, pRate){
		if(scCoLib.isIE) pNode.style.filter = pRate==1 ? "progid:DXImageTransform.Microsoft.Alpha(opacity=100)" : "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
		else pNode.style.opacity = pRate;
		pNode.style.visibility = "";
	},
	endOpacityEffect: function(pNode, pRate){
		if(scCoLib.isIE) pNode.style.filter = "";
		if(scCoLib.isIE) pNode.style.backgroundColor = "";
		else pNode.style.opacity = pRate;
		if(pRate == 0) pNode.style.visibility = "hidden";
		else pNode.style.visibility = "";
	},
	switchViewTask : {
		fOldView: null,
		fNewView: null,
		fChangeTitle: false,
		fIdx: -1,
		fOldRate:  [".9", ".7", ".5", ".3", ".1", "0", "0", "0", "0"],
		fNewRate: ["0", "0", "0", "0", ".1", ".3", ".5", ".7", ".9"],
		execTask : function(){
			if (!scPresMgr.fEnableEffects) this.fIdx = this.fOldRate.length;
			while(this.fEndTime < (Date.now ? Date.now() : new Date().getTime()) && this.fIdx < this.fOldRate.length + 1) {
				this.fIdx++;
				this.fEndTime += 100;
			}
			this.fIdx++;
			this.fEndTime += 100;
			if(this.fIdx >= this.fOldRate.length) {
				scPresMgr.endOpacityEffect(this.fOldView, 0);
				if(scCoLib.isIE) this.fOldView.style.backgroundColor = "";
				scPresMgr.endOpacityEffect(this.fNewView, 1);
				if(scCoLib.isIE) this.fNewView.style.backgroundColor = "";
				if(this.fChangeTitle) scPresMgr.endOpacityEffect(this.oTitleFrm, 1);
				//this.callChildren(this.fNewView, "endAnim");
				return false;
			}
			scPresMgr.setOpacity(this.fOldView, this.fOldRate[this.fIdx]);
			scPresMgr.setOpacity(this.fNewView, this.fNewRate[this.fIdx]);
			if(this.fChangeTitle) scPresMgr.setOpacity(this.oTitleFrm, this.fNewRate[this.fIdx]);
			return true;
		},
		terminate : function(){
			this.fIdx = this.fOldRate.length;
			this.execTask();
		},
		initTask : function(pOldView, pNewView, pChangeTitle){
			this.fEndTime = ( Date.now  ? Date.now() : new Date().getTime() ) + 100;
			this.fChangeTitle = pChangeTitle;
			this.fOldView = pOldView;
			this.fNewView = pNewView;
			this.fNewView.style.display = "";
			this.fNewView.scrollTop = 0;
			//this.callChildren(this.fOldView, "startAnim");
			//this.callChildren(this.fNewView, "startAnim");
			scPresMgr.startOpacityEffect(this.fOldView, 1);
			if(scCoLib.isIE) this.fOldView.style.backgroundColor = "white";
			scPresMgr.startOpacityEffect(this.fNewView, 0);
			if(scCoLib.isIE) this.fNewView.style.backgroundColor = "white";
			if(this.fChangeTitle) scPresMgr.startOpacityEffect(this.oTitleFrm, 0);
			this.fIdx = -1;
		},
		callChildren : function(pRoot, pMethod) {
			var vCh = pRoot.firstChild;
			while(vCh) {
				if(pMethod in vCh) vCh[pMethod]();
				if(vCh.hasChildNodes()) {
					vCh = vCh.firstChild;
				} else {
					while( ! vCh.nextSibling) {
						vCh = vCh.parentNode;
						if(vCh === pRoot) return;
					}
					vCh = vCh.nextSibling;
				}	
			}
		}
	},
	getLastStep : function(){
		return this.fLastStep;
	},
	getCurrView : function(){
		return this.fCurrView;
	},
	
	listViews : function(){
		return [this.oViewHome, this.oView1, this.oView2];
	},
	
	editMode : function(pMode){
		if(this.fEditMode == pMode) return;
		if(pMode) {
			this.oContainer.style.display = "none";
			this.oEditorFrm.style.display = "";
			this.resetView(this.oView1);
			this.resetView(this.oView2);
		} else {
			//On prend en compte les modifs : reconstruit les steps de la page
			this.saveEditedPage();
			this.oEditorFrm.style.display = "none";
			this.oContainer.style.display = "";
		}
		this.fEditMode = pMode;
		this.fCurrStepIdx = 0;
		this.fLastStep = null;
		scPresTools.redrawEditStatus();
		this.next(true);
	},
	saveEditedPage : function(){
		if(this.fEditedPageDirty) {
			var vPg = this.getCurrPg();
			this.buidPageSteps(vPg.fSrcFrm);
			if(scPresStor.isStorageAuto()) {
				var vRootData = {};
				var vBody = vPg.fSrcFrm.contentWindow.document.body;
				var vCh = vBody.firstChild;
				while(vCh){
					if(vCh.nodeType == 1 && ("fBhv" in vCh) ) vCh.fBhv.saveParams(vRootData);
					if(vCh.hasChildNodes()){
						vCh = vCh.firstChild;
						continue;
					}
					while( ! vCh.nextSibling) {
						vCh = vCh.parentNode;
						if(vCh === vBody) {
							vCh = null;
							break;
						}
					}
					if(vCh) vCh = vCh.nextSibling;	
				}
				scPresStor.savePageData(vPg.getAttribute("href"), vRootData);
			}
			this.fEditedPageDirty = false;
		}
		if(this.fEditedOutlineDirty) {
			scPresStor.saveOutline();
			this.fEditedOutlineDirty = false;
		}
	},
	setEditedPageDirty : function(pStatus){
		this.fEditedPageDirty = pStatus;
	},
	setHiddenPg : function(pPg, pHidden){
		if(pHidden) {
			if(pPg.hiddenPg) return;
			pPg.hiddenPg = true;
			this.fCountVisiblePg--;
		} else {
			if(! pPg.hiddenPg) return;
			pPg.hiddenPg = false;
			this.fCountVisiblePg++;
		}
		this.redrawTitleEditPage(pPg);
		this.fEditedOutlineDirty = true;
	},
	getZoomContainer : function(){
		return this.oZoom;
	},
	isZoomDisplayed : function(){
		return this.fZoomOn;
	},
	displayZoom : function(pBoolean){
		if(this.fZoomOn == pBoolean) return;
		this.oZoomFrm.style.visibility = pBoolean ? "" : "hidden";
		if(! pBoolean) while(this.oZoom.hasChildNodes()) this.oZoom.removeChild(this.oZoom.lastChild);
		this.fZoomOn = pBoolean;
	},
	prepareOutline : function(){
		if(this.fEditMode) this.saveEditedPage();
		var vList = this.oOutline.getElementsByTagName("a");
		var vCurrPg = this.getRealPg();
		var vCurrUrl = vCurrPg ? vCurrPg.getAttribute("href"): "#home";
		for (var i = 0, l = vList.length; i < l; i++) {
			var vPg = vList[i];
			var vClass = vPg.className;
			var vOffsStatusClass = vClass.indexOf("scPresOutlineEntry");
			if(vOffsStatusClass>=0) vClass = vPg.className.substring(0, vOffsStatusClass);
			if(vPg.getAttribute("href") == vCurrUrl)  vClass += " scPresOutlineEntrySel";
			if( (vPg.fRealPg || vPg).hiddenPg) {
				if(this.fEditMode){
					vPg.className = vClass+" scPresOutlineEntryStroke";
				} else {
					if( ! this.fIsEntryFolder) this.fIsEntryFolder = scPaLib.compilePath("nsi:/des:a");
					var vChList = scPaLib.findNodes(this.fIsEntryFolder, vPg);
					var vEmpty = true;
					if(vChList) for(var ii=0, ll = vChList.length; ii < ll; ii++) {
						var vChPg = vChList[ii].fRealPg || vChList[ii];
						if( ! vChPg.hiddenPg) {
							vEmpty = false; 
							break;
						}
					}
					vPg.className = vClass + ( vEmpty ? " scPresOutlineEntryHidden" : " scPresOutlineEntryFolderNoLink");
				}
			} else {
				vPg.className = vClass;
			}
		}
	},
	onClickOutlineEntry : function(pEvent){
		try {
			if(this.className.indexOf("scPresOutlineEntryFolderNoLink")>=0) return false;
			var vPg = this.fRealPg || this;
			var vList = scPresMgr.fPageList;
			for (var i = 0, l = vList.length; i < l; i++) {
				if(vList[i] === vPg) {
					scPresMgr.fCurrPgIdx = i;
					scPresMgr.fCurrStepIdx = 0;
					scPresMgr.next(true);
					break;
				}
			}
		} catch(e) {
			scCoLib.util.logError("Echec au chargement de la page.", e);
		}
		return false;
	},
	
	
	onKeyPress : function(pEvent){
		var vEvent = pEvent || window.event;
		var vCharCode = vEvent.which || vEvent.keyCode;
		scCoLib.util.log("onKeyPress - vCharCode="+vCharCode);
		switch(vCharCode){
			case 32://space
			case 34://pge dwn
			case 39://right
				scPresMgr.next();
				return false;
			case 8://bckspace
			case 33://pge up
			case 37://left
				scPresMgr.prev();
				return false;
			case 112://p
			case 80://P
				scPresTools.toggleOutline();
				return false;
			case 27://escape
				scPresMgr.hideAllSupWindows();
				return false;
			case 116://t
			case 84://T
				scPresTools.toggleToolsBar();
				return false;
			case 101://e
			case 69://E
				scPresTools.toggleEditPage();
				return false;
			case 102://f
			case 70://F
				scPresMgr.toggleEffects();
				return false;
			case 38://up
				scrollTiTask.step( - $('container').offsetHeight/5);
				return false;
			case 40://down
				scrollTiTask.step($('container').offsetHeight/5);
				return false;
		}
	},
	
	setWait : function(pStatus) {
		scPresMgr.oWait.style.display = pStatus ? "" : "none";
	},
	
	enableEffects : function(pEnable) {
		this.fEnableEffects = pEnable;
		document.cookie = "enableEffects=" + pEnable;
	},
	
	toggleEffects : function() {
		this.enableEffects(!this.fEnableEffects);
	},
	
	redrawProgressBar : function() {
		var vTd = this.oProgressBarTr.firstChild;
		var vAfterCurrent = (this.fCurrPgIdx < 0);
		for(var i = 0, l = this.fPageList.length; i < l; i++) {
			var vPg = this.fPageList[i];
			if(this.fEditMode || ! vPg.hiddenPg) {
				if( ! vTd) {
					vTd = this.oProgressBarTr.appendChild(document.createElement("td"));
					vTd.onclick = this.onClickProgressBarTd;
				}
				vTd.fIdxPg = i;
				vTd.title = vPg.fTitlePg;
				if(vAfterCurrent) {
					vTd.className = vPg.hiddenPg ? "scPresPrBarAfter scPresPrBarHidden" : "scPresPrBarAfter";
					while(vTd.lastChild) vTd.removeChild(vTd.lastChild);
				} else if(i == this.fCurrPgIdx){
					vTd.className = vPg.hiddenPg ? "scPresPrBarCurrent scPresPrBarHidden" : "scPresPrBarCurrent";
					vAfterCurrent = true;
				} else {
					vTd.className = vPg.hiddenPg ? "scPresPrBarBefore scPresPrBarHidden" : "scPresPrBarBefore";
					while(vTd.lastChild) vTd.removeChild(vTd.lastChild);
				}
				if (i == 0) vTd.className = vTd.className + " scPresPrBarFirst";
				else if (i == l - 1) vTd.className = vTd.className + " scPresPrBarLast";
				vTd = vTd.nextSibling;
			}
		}
		while(vTd) {
			var vNext = vTd.nextSibling;
			this.oProgressBarTr.removeChild(vTd);
			vTd = vNext;
		}
	},
	onClickProgressBarTd : function(pEvent){
		scPresMgr.fCurrPgIdx = this.fIdxPg;
		scPresMgr.fCurrStepIdx = 0;
		scPresMgr.next(true);
	},
	
	fBhvBinders : [],
	addBhvBinder : function(pBhvBinder){
		this.fBhvBinders[this.fBhvBinders.length] = pBhvBinder;
	},
	
	loadPages : function(pDataOutline){
		var vList = this.oOutline.getElementsByTagName("a");
		var vData;
		var i = 0;
		var vPg = vList[i];
		if(scPaLib.containWord(vPg.className, "home")) {
			//Page de garde
			vPg.onclick = function(){scPresMgr.home(); return false;};
			vPg.href = "#home"; //key pour gestion de l'item sel de l'outline.
			vPg = vList[++i];
		}
		vPg.onclick = this.onClickOutlineEntry;
		vPg.fTitlePg = vPg.getAttribute("title") || vPg.textContent || vPg.innerText;
		vPg.hiddenPg = (pDataOutline && (vData = pDataOutline[vPg.getAttribute("href")]) && vData.hiddenPg);
		this.fPageList = [vPg];
		this.fCountVisiblePg = 1;
		var vPrevHref = vPg.getAttribute("href");
		//Suppr des folders without content (dont l'url pointe sur la 1ère page fille).
		for (i++, l = vList.length; i < l; i++) {
			vPg = vList[i];
			vPg.onclick = this.onClickOutlineEntry;
			vPg.fTitlePg = vPg.getAttribute("title") || vPg.textContent || vPg.innerText;
			var vHref = vPg.getAttribute("href");
			if(vHref != vPrevHref) {
				this.fPageList[this.fPageList.length] = vPg;
				vPg.hiddenPg = (pDataOutline && (vData = pDataOutline[vHref]) && vData.hiddenPg);
				this.fCountVisiblePg++;
				vPrevHref = vHref;
			} else {
				//On pointe la Pg qui sert de ref pour cette url.
				vPg.fRealPg = vList[i-1];
				while(vPg.fRealPg.fRealPg) vPg.fRealPg = vPg.fRealPg.fRealPg;
			}
		}
	},
	
	initPresMgr : function(){
		//Liste des pages
		this.loadPages(scPresStor.getOutline());
		//Index de la page courante
		this.fCurrPgIdx = -1;
		//Index de l'étape courante. Idx premier step = 1.
		this.fCurrStepIdx = 0;
		//Nb de SrcFrm chargées (ou en cours).
		this.fSrcFrmCount = 0;
		
		//Vue active (viewHome, view1 ou view2)
		this.fCurrView = this.oViewHome;
		//Dernière Step affichée
		this.fLastStep = null;
		//Task d'animation en cours.
		this.fCurrAnimTask = null;
		
		//Mode édition actif
		this.fEditMode = false;
		this.fEditedPageDirty = false;
		this.fEditedOutlineDirty = false;
		
		//Zoom
		this.fZoomOn = false;
		
		//Effets 
		this.fEnableEffects = !(document.cookie.indexOf("enableEffects=false") != -1);

		this.redrawProgressBar();
		this.fPendingTask = { execTask : function(){ scPresMgr.setWait(false); return false;} };
		this.preload();
		
		//Abonnement auc events claviers
		document.onkeyup = this.onKeyPress;
	},
	
	onLoad : function(){
	try{
		this.oTitle = $("title");
		this.switchViewTask.oTitleFrm= $("titleFrm");
		this.oDecor = $("decor");
		this.oContainer = $("container");
		this.oViewHome = $("viewHome");
		this.oView1 = $("view1");
		this.oView2 = $("view2");
		this.oEditorFrm = $("editorFrm");
		this.oEditorTitle = $("editorTitle");
		this.oEditor = $("editor");
		this.oWait = $("wait");
		this.oOutline = $("outline");
		this.oPoolSrc = $("poolSrc");
		this.oProgressBarTr = $("progressBarTr");
		this.oZoomFrm = $("zoomFrm");
		this.oZoom = $("zoom");
		this.initPresMgr();
	}catch(e){
		scCoLib.util.logError("Echec au chargement de la présentation.", e);
	}
	},
	
	onLoadSortKey: "pres"
}


/** #################### */

var scPresUt = {};
/** Remonte la hiérarchie en important dans la Dst tous les noeuds visibles. */
scPresUt.importAncestorsBhv = function(pEltSrc, pEltDst, pRootDst){
	var vDocDst = pEltDst.ownerDocument;
	var vCurr = pEltSrc;
	var vParent = pEltSrc.parentNode;
	var vBody = pEltSrc.ownerDocument.body;
	if("fBhv" in pEltSrc) for(var i = 0, l = pEltSrc.fBhv.cutBefore; vParent != vBody && i < l; i++) {
		var vCuttedParent = this.importElt(vParent, vDocDst);
		vCuttedParent.appendChild(pEltDst);
		pEltDst = vCuttedParent;
		vCurr = vParent;
		vParent = vParent.parentNode;
	}
	if(vParent!= vBody) {
		var vParentDst = this.importElt(vParent, vDocDst);
		for(var vSib = vCurr.previousSibling; vSib; vSib = vSib.previousSibling) {
			vDocDst.importStopped = false;
			this.importDeepNodeBhv(vSib, vDocDst, vParentDst, true);
		}
		vParentDst.appendChild(pEltDst);
		this.importAncestorsBhv(vParent, vParentDst, pRootDst);
	} else {
		pRootDst.appendChild(pEltDst);
	}
}
scPresUt.importDeepNodeBhv = function(pEltSrc, pDocDst, pParentDst, pDontCheckRootStop){
	if("fBhv" in pEltSrc) {
		var vBhv = pEltSrc.fBhv;
		if( ! pDontCheckRootStop) if(vBhv.cutBefore>0 || vBhv.tempoBefore) {
			pDocDst.importStopped = true;
			 return null;
		}
		if(vBhv.hidden) return null;
		return vBhv.importBlock(pDocDst, pParentDst);
	} else {
		switch(pEltSrc.nodeType){
			case 1 : 
				var vElt = this.importElt(pEltSrc, pDocDst, pParentDst);
				for(var vCh = pEltSrc.firstChild; vCh; vCh = vCh.nextSibling) {
					this.importDeepNodeBhv(vCh, pDocDst, vElt);
					if(pDocDst.importStopped) break;
				}
				return vElt;
			case 3 : 
				var vElt = pDocDst.createTextNode(pEltSrc.nodeValue);
				if(pParentDst) pParentDst.appendChild(vElt);
				return vElt;
		}
	}
}
scPresUt.importNextsBhv = function(pEltSrc, pDocDst, pParentDst, pRootDst){
	var vEltSrc = pEltSrc;
	var vBodySrc = pEltSrc.ownerDocument.body;
	var vParentDst = pParentDst;
	pDocDst.importStopped = false;
	while(vEltSrc) {
		//Publication des noeuds suivants
		while( ! vEltSrc.nextSibling) {
			vEltSrc = vEltSrc.parentNode;
			if(vParentDst != pRootDst) vParentDst = vParentDst.parentNode;
			if(vEltSrc == vBodySrc) return;
		}
		if(vEltSrc) {
			vEltSrc = vEltSrc.nextSibling;
			scPresUt.importDeepNodeBhv(vEltSrc, pDocDst, vParentDst);
			if(pDocDst.importStopped) return;
		}
	}
}
scPresUt.importDeepNodeEdit = function(pEltSrc, pDocDst, pParentDst){
	if("fBhv" in pEltSrc) {
		return pEltSrc.fBhv.editBlock(pDocDst, pParentDst);
	} else {
		switch(pEltSrc.nodeType){
			case 1 : 
				var vElt = this.importElt(pEltSrc, pDocDst, pParentDst);
				for(var vCh = pEltSrc.firstChild; vCh; vCh = vCh.nextSibling) this.importDeepNodeEdit(vCh, pDocDst, vElt);
				return vElt;
			case 3 : 
				var vElt = pDocDst.createTextNode(pEltSrc.nodeValue);
				if(pParentDst) pParentDst.appendChild(vElt);
				return vElt;
		}
	}
}
scPresUt.isFilled = function(pElt){
	switch(pElt.nodeType) {
		case 1 : 
			if(("fBhv" in pElt) &&  pElt.fBhv.hidden) return false;
			var vNm = pElt.nodeName;
			if(vNm == "IMG" || vNm == "OBJECT" || vNm == "EMBED") return true;
			for(var vCh = pElt.firstChild; vCh; vCh = vCh.nextSibling) if(this.isFilled(vCh)) return true;
			break;
		case 3 :
			return (/\S/.test(pElt.nodeValue));
	}
	return false;
}
scPresUt.isFirstElt = function(pElt){
	var vPrev = pElt.previousSibling;
	while(vPrev) {
		if( ! (("fBhv" in vPrev) &&  vPrev.fBhv.hidden) && this.isFilled(vPrev)) return false;
		vPrev = vPrev.previousSibling;
	} 
	return true;
}
scPresUt.getRelativePath = function(pRoot, pChild){
	var vRes = "";
	var vCursor = pChild;
	while(vCursor != pRoot) {
		var vOffset = 0;
		var vPrev = vCursor.previousSibling;
		while(vPrev!=null) {
			vOffset++;
			vPrev = vPrev.previousSibling;
		}
		vRes+= ","+vOffset;
		vCursor = vCursor.parentNode;
	}
	return vRes;
}
scPresUt.getChildFromRelativePath = function(pRoot, pRelativePath){
	var vCh = pRoot;
	var vList = pRelativePath.split(",");
	for(var i = vList.length-1; i >=0 ; i--) {
		var vNext = vCh.firstChild;
		var vOffset = vList[i];
		while(vCh && vOffset>0) {
			vOffset--;
			vNext = vNext.nextSibling;
		}
		if(vNext) vCh = vNext;
		else return null;
	}
	return vCh;
}
scPresUt.deserialiseObjJs = function(pString){
	if(!pString) return {};
	var vVal;
	eval("vVal="+pString);
	return vVal;
};
scPresUt.escapeJs = function(pChar){
	switch(pChar) {
		case '\t' : return "\\t";
		case '\n' : return "\\n";
		case '\r' : return "\\r";
		case '\'' : return "\\\'";
		case '\"' : return "\\\"";
	} 
	return "";
}

if(scCoLib.isIE) {
	scPresUt.serialiseObjJs = function(pObj){
		var vBuf="";
		if(pObj) for (var vKey in pObj){
			var vObj = pObj[vKey];
			if(vObj) {
				switch(typeof vObj) {
					case "object" : 
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':"+this.serialiseObjJs(vObj);
						break;
					case "string" : 
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':'"+vObj.replace(/[\t\n\r'"]/g, this.escapeJs)+"'";
						break;
					case "number" :
					case "boolean" :
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':"+vObj;
						break;
					default : 
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':'"+vObj.toString().replace(/[\t\n\r'"]/g, this.escapeJs)+"'";
						break;
				}
			}
		}
		return "{"+vBuf+"}";
	};
	scPresUt.importElt = function(pEltSrc, pDocDst, pParentDst, pChildDst) {
		try {
			var vWrapper;
			var vDeep = false;
			switch(pEltSrc.nodeName) {
				case "TBODY" :
				case "TR" :
					vRes = pDocDst.createElement(pEltSrc.nodeName);
					//TODO gestion attributs : pEltSrc.cloneNode(false).outerHTML + regEpx pour extraire les attr  ou parseXml ou gestion en dur
					if(pParentDst) pParentDst.appendChild(vRes);
					if(pChildDst) vRes.appendChild(pChildDst);
					return vRes;
				case "TD" :
					vWrapper = pDocDst.createElement("TR");
					break;
				case "OPTION" :
					vWrapper = pDocDst.createElement("SELECT");
					break;
				case "OBJECT" :
					//Cas particulier : on clone Objet et param d'un coup.
					vWrapper = pDocDst.createElement("DIV");
					vDeep = true;
					break;
				case "PARAM" :
					//Cas particulir déjà traité/
					return null;
				default :
					vWrapper = pDocDst.createElement("DIV");
			}
			vWrapper.innerHTML = vDeep ? pEltSrc.outerHTML : pEltSrc.cloneNode(false).outerHTML;
			var vRes = vWrapper.firstChild;
			while(vRes && vRes.nodeType!=1) vRes = vRes.nextSibling;
			if(vRes) {
				if(pParentDst) pParentDst.appendChild(vRes);
				if(pChildDst) vRes.appendChild(pChildDst);
			}
			return vRes;
		} catch(e){}
	}
	scPresUt.importNode = function(pEltSrc, pDocDst, pParentDst) {
		switch(pEltSrc.nodeType){
			case 1 : 
				return this.importElt(pEltSrc, pDocDst, pParentDst);
			case 3 : 
				var vElt = pDocDst.createTextNode(pEltSrc.nodeValue);
				if(pParentDst) pParentDst.appendChild(vElt);
				return vElt;
		}
	}
	scPresUt.importDeepNode = function(pEltSrc, pDocDst, pParentDst) {
		switch(pEltSrc.nodeType){
			case 1 : 
				var vElt = this.importElt(pEltSrc, pDocDst, pParentDst);
				for(var vCh = pEltSrc.firstChild; vCh; vCh = vCh.nextSibling) this.importDeepNode(vCh, pDocDst, vElt);
				return vElt;
			case 3 : 
				var vElt = pDocDst.createTextNode(pEltSrc.nodeValue);
				if(pParentDst) pParentDst.appendChild(vElt);
				return vElt;
		}
	}
} else if (scCoLib.userAgent.indexOf("safari")!=-1) {
	scPresUt.serialiseObjJs = function(pObj){
		var vBuf="";
		if(pObj) for (var vKey in pObj){
			var vObj = pObj[vKey];
			if(vObj) {
				switch(typeof vObj) {
					case "object" : 
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':"+this.serialiseObjJs(vObj);
						break;
					case "string" : 
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':'"+vObj.replace(/[\t\n\r'"]/g, this.escapeJs)+"'";
						break;
					case "number" :
					case "boolean" :
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':"+vObj;
						break;
					default : 
						vBuf+=( vBuf!="" ? ",'" : "'")+vKey+"':'"+vObj.toString().replace(/[\t\n\r'"]/g, this.escapeJs)+"'";
						break;
				}
			}
		}
		return "{"+vBuf+"}";
	};
	scPresUt.importElt = function(pEltSrc, pDocDst, pParentDst, pChildDst) {
		var vRes = pDocDst.importNode(pEltSrc, false);
		if(pParentDst) pParentDst.appendChild(vRes);
		if(pChildDst) vRes.appendChild(pChildDst);
		return vRes;
	}
	scPresUt.importNode = scPresUt.importElt;
	scPresUt.importDeepNode = function(pEltSrc, pDocDst, pParentDst) {
		var vElt = pDocDst.importNode(pEltSrc, true);
		if(pParentDst) pParentDst.appendChild(vElt);
		return vElt;
	}
} else {
	scPresUt.serialiseObjJs = function(pObj){return (pObj) ? pObj.toSource() : null;}
	scPresUt.importElt = function(pEltSrc, pDocDst, pParentDst, pChildDst) {
		var vRes = pDocDst.importNode(pEltSrc, false);
		if(pParentDst) pParentDst.appendChild(vRes);
		if(pChildDst) vRes.appendChild(pChildDst);
		return vRes;
	}
	scPresUt.importNode = scPresUt.importElt;
	scPresUt.importDeepNode = function(pEltSrc, pDocDst, pParentDst) {
		var vElt = pDocDst.importNode(pEltSrc, true);
		if(pParentDst) pParentDst.appendChild(vElt);
		return vElt;
	}
}

/** ################### */
var scPresTools = scOnLoads[scOnLoads.length] = {
	fCloseToolsBar : false,
	setToolsBar : function(pOn){
		this.fCloseToolsBar = ! pOn;
		if(pOn) {
			if(this.oToolsZ.className != "") this.oToolsZ.className = "";
		} else {
			if(this.oToolsZ.className == "") this.oToolsZ.className = "toolsHidden";
		}
	},
	toggleToolsBar : function(){
		this.setToolsBar(this.oToolsZ.className=="toolsHidden");
	},
	closeToolsBarAfter : function(pMs){
		this.fCloseToolsBar = true;
		if( ! this.fCloseToolsBarProcess) this.fCloseToolsBarProcess = window.setTimeout(scPresToolsCloseToolBar, pMs);
	},
	toggleEditPage : function(){
		scPresMgr.editMode( ! scPresMgr.fEditMode);
	},
	redrawEditStatus : function(){
		this.oEditBtn.className = scPresMgr.fEditMode ? "editOn" : "editOff";
	},
	fOutlineShown : false,
	showOutline : function(){
		scPresMgr.prepareOutline();
		this.oOutlineFrm.style.display = "";
		this.fOutlineShown = true;
	},
	hideOutline : function(){
		if(this.fOutlineShown) {
			this.oOutlineFrm.style.display = "none";
			this.fOutlineShown = false;
		}
	},
	toggleOutline : function(){
		if(this.fOutlineShown) this.hideOutline();
		else this.showOutline();
	},
	onLoad : function(){
		this.oToolsZ = $("toolsZ");
		this.oMainZ = $("mainZ");
		this.oEditBtn = $("editBtn");
		this.oOutlineFrm = $("outlineFrm");
	},
	onLoadSortKey: "presTools"
}
function scPresToolsCloseToolBar(){
	scPresTools.fCloseToolsBarProcess = 0;
	if(scPresTools.fCloseToolsBar) scPresTools.setToolsBar(false);
}


/** Storage */

scPresStor = {
	isStorageAuto : function(){
		return (scServices.storage && scServices.storage.isStorageActive());
	},
	getPageData : function(pUrl) {
		try{
			if(scServices.storage && scServices.storage.isStorageActive()) {
				var vData = scServices.storage.getStorage().getItem(scServices.storage.getRootKey()+pUrl);
				return scPresUt.deserialiseObjJs(vData);
			}
		}catch(e){}
		return null;
	},
	savePageData : function(pUrl, pRootData) {
		if(scServices.storage && scServices.storage.isStorageActive()) {
			scServices.storage.getStorage().setItem(scServices.storage.getRootKey()+pUrl, scPresUt.serialiseObjJs(pRootData));
		}
	},
	getOutline : function() {
		try{
			if(scServices.storage && scServices.storage.isStorageActive()) {
				var vData = scServices.storage.getStorage().getItem(scServices.storage.getRootKey()+"#outline");
				//console.log("deserialise:::"+vData);
				if(vData) return scPresUt.deserialiseObjJs(vData);
			}
		}catch(e){}
		return null;
	},
	saveOutline : function() {
		if(scServices.storage && scServices.storage.isStorageActive()) {
			var vOutlineData = {};
			for(var i = 0, l=scPresMgr.fPageList.length; i < l; i++) {
				var vPg = scPresMgr.fPageList[i];
				if(vPg.hiddenPg) vOutlineData[vPg.getAttribute("href")] = {hiddenPg:true};
			}
			//console.log("serialise:::"+scPresUt.serialiseObjJs(vOutlineData));
			scServices.storage.getStorage().setItem(scServices.storage.getRootKey()+"#outline", scPresUt.serialiseObjJs(vOutlineData));
		}
	},
	
	resetData : function() {
		if(scServices.storage && scServices.storage.isStorageActive()) {
			if(confirm("Souhaitez-vous vraiment supprimer toute la personnalisation de votre pr\u00E9sentation ?")) {
				scServices.storage.resetData(scServices.storage.getRootKey());
				document.location.reload();
			}
		}
	}
	
}
