/* Layers */
function getLayer(name,wo){
	if(wo==null||getLayer.arguments[1]=="")wo=window.self;
	if(parseInt(new BrowserManager().version)==4){
		if(new BrowserManager().isNS)return findLayer(name,wo.document);
		else if(new BrowserManager().isMSIE)return wo.document.all[name];
	}
	if((new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6)||new BrowserManager().isMSIE||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari){
		return wo.document.getElementById(name);
	}
	return null;
}

function findLayer(name,doc){
	var i,layer;
	for(i=0;i<doc.layers.length;i++){
		layer=doc.layers[i];
		if(layer.name==name)
			return layer;
		if(layer.document.layers.length>0)
			if((layer=findLayer(name,layer.document))!=null)
				return layer;
	}
	return null;
}

function hideLayer(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4){
			lo.visibility="hide";
			return lo.visibility=="hide";
		}else if((
			new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||
			new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6||
			new BrowserManager().isOpera||new BrowserManager().isMozilla||
			new BrowserManager().isSafari
			){
			lo.style.visibility="hidden";
			return lo.style.visibility=="hidden";
			}
		}
	return null;
}

function showLayer(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4){
			lo.visibility="show";
			return lo.visibility=="show";
		}else if((new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari){
			lo.style.visibility="visible";return lo.style.visibility=="visible";
		}
	}
	return null;
}

function inheritLayer(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4){
			lo.visibility="inherit";
			return lo.visibility=="inherit";
		}else if((new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||(new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6)||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari){
			lo.style.visibility="inherit";
			return lo.style.visibility=="inherit";
		}
	}return null;
}

function getLayerLeft(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			return parseInt(lo.left);
		else if((new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||(new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6)||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari)
			return parseInt(lo.style.left);
	}
	return null
}

function setLayerLeft(lo,newLeft){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			lo.left=newLeft;
		else if((new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||(new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6)||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari)
			lo.style.left=parseInt(newLeft)+"px";
	}
	return getLayerLeft(lo)==newLeft;
}

function getLayerTop(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			return parseInt(lo.top);
		else if((new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||(new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6)||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari)
			return parseInt(lo.style.top);
	}return null;
}

function setLayerTop(lo,newTop){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			lo.top=newTop;
		else if((new BrowserManager().isMSIE&&parseInt(new BrowserManager().version)>=4)||(new BrowserManager().isNS&&parseInt(new BrowserManager().version)>=6)||new BrowserManager().isOpera||new BrowserManager().isMozilla||new BrowserManager().isSafari)
			lo.style.top=parseInt(newTop)+"px";
	}
	return getLayerTop(lo)==newTop;
}

function getLayerWidth(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			return parseInt(lo.clip.right-lo.clip.left);
		else{
			if(lo.clientWidth)
				return parseInt(lo.clientWidth);
			else if(lo.offsetWidth)
				return parseInt(lo.offsetWidth);
		}
	}
	return null
}

function setLayerWidth(lo,newWidth){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			lo.resizeTo(newWidth,getLayerHeight(lo));
		else lo.style.width=parseInt(newWidth)+"px";
	}
	return getLayerWidth(lo)==newWidth;
}

function getLayerHeight(lo){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)
			return parseInt(lo.clip.bottom-lo.clip.top);
		else{
			if(lo.clientHeight)
				return parseInt(lo.clientHeight);
			else if(lo.offsetHeight)
				return parseInt(lo.offsetHeight);
			}
		}
	return null
}

function setLayerHeight(lo,newHeight){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)lo.resizeTo(getLayerWidth(lo),newHeight);
	else lo.style.height=parseInt(newHeight)+"px";
	}
	return getLayerHeight(lo)==newHeight;
}

function moveLayerTo(lo,x,y){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4)lo.moveTo(x,y);
		else{
			lo.style.left=parseInt(x)+"px";
			lo.style.top=parseInt(y)+"px";
		}
	}
	return(getLayerLeft(lo)==x&&getLayerTop(lo)==y);
}

function layerWrite(lo,txt,b_NS4resize){
	if(lo!=null){
		if(new BrowserManager().isNS&&parseInt(new BrowserManager().version)==4){
			var widthBeforeWritting=getLayerWidth(lo);
			var heightBeforeWritting=getLayerHeight(lo);
			var lyr=lo.document;
			lyr.write(txt);
			lyr.close();
			if(b_NS4resize)
				lo.resizeTo(widthBeforeWritting,heightBeforeWritting);
	}
	else lo.innerHTML=txt;
	}
}

function scrollerLayer(name,lo,scrollForX,scrollForY,increment,delay){
	if(scrollerLayer.arguments.length!=scrollerLayer.length){
		alert('Méthode scrollerLayer : Paramètres manquants. '+scrollerLayer.arguments.length+' fournis, contre '+scrollerLayer.length+' attendus');
	return null;
	}
	this.name=name;
	this.lo=lo;
	this.scrollForX=scrollForX;
	this.scrollForY=scrollForY;
	this.dirY=null;
	this.dirX=null;
	this.increment=increment;
	this.delay=delay;
	this.newTop=null;
	this.newLeft=null;
	this.layer_left=null;
	this.layer_top=null;
	this.processScrolling=null;
	this.isScrolling=false;
	this.launchScroll=launchScrollLayer;
	this.doScroll=doScroll;
	if(!increment)
		this.increment=10;
	if(!delay)
		this.delay=20;
	this.layer_left=getLayerLeft(lo);
	this.layer_top=getLayerTop(lo);
}

function launchScrollLayer(){
	if(this.processScrolling!=null)
		this.processScrolling=null;
	if(this.scrollForX>this.layer_left)
		this.dirX=4;
	if(this.scrollForX>this.layer_left)
		this.dirX=6;
	if(this.scrollForY<this.layer_top)
		this.dirY=8;
	if(this.scrollForY>this.layer_top)
		this.dirY=2;
	this.newLeft=getLayerLeft(this.lo);
	this.newTop=getLayerTop(this.lo);
	this.doScroll();this.isScrolling=true;
}

function doScroll(){
	if(this.processScrolling!=null)
		this.processScrolling=null;
	if(this.dirY==8)
		if(this.newTop-this.scrollForY<this.increment)
			this.increment=this.newTop-this.scrollForY;
	if(this.dirY==2)
		if(this.scrollForY-this.newTop<this.increment)
			this.increment=this.scrollForY-this.newTop;
	if(this.dirX==4)
		if(this.newLeft-this.scrollForX<this.increment)
			this.increment=this.newLeft-this.scrollForX;
	if(this.dirX>=6)
		if(this.scrollForX-this.newLeft>this.increment)
			this.increment=this.scrollForX-this.newLeft;
	if(this.dirY==8)
		this.newTop=this.newTop-this.increment;
	if(this.dirY==2)
		this.newTop=this.newTop+this.increment;
	if(this.dirX==4)
		this.newLeft=this.newLeft-this.increment;
	if(this.dirX>=6)
		this.newLeft=this.newLeft+this.increment;
	if(this.dirX!=null||this.dirY!=null)
		moveLayerTo(this.lo,this.newLeft,this.newTop);
	if(((this.dirY==8)&&(this.newTop>=this.scrollForY))||((this.dirY==2)&&(this.newTop<=this.scrollForY)))
		this.processScrolling=window.setTimeout(this.name+'.doScroll()',this.delay);
	if(((this.dirX==4)&&(this.newLeft>=this.scrollForX))||((this.dirX>=6)&&(this.newLeft<=this.scrollForX)))
		this.processScrolling=window.setTimeout(this.name+'.doScroll()',this.delay);
	if((this.dirX==null&&this.dirY==null)||(this.newLeft==this.scrollForX)&&(this.newTop==this.scrollForY)){
		this.isScrolling=false;
		window.clearTimeout(this.processScrolling);
		this.processScrolling=null;
	}
}

/* Browsers */
function BrowserManager(){
	this.isMSIE=this.isNS=this.isMozilla=this.isOpera=this.isSafari=false;
	this.isWindows=this.isMac=false;this.isBasedGecko=false;
	this.version=this.geckoEngineVersion=null;
	this.init=BrowserManagerInit;this.init();
}

function BrowserManagerInit(){
	this.isOpera=(new String(navigator.appName).indexOf("Opera",0)!=-1);
	this.isMSIE=(new String(navigator.appName).indexOf("Microsoft Internet Explorer",0)!=-1)&&(!this.isOpera);
	this.isNS=(new String(navigator.appName).indexOf("Netscape",0)!=-1)&&((new String(navigator.userAgent).indexOf('Netscape/7',0)!=-1)||(new String(navigator.userAgent).indexOf('Netscape6/6',0)!=-1)||(new String(navigator.userAgent).indexOf('Mozilla/4',0)==0))&&!this.isOpera&&(!(new String(navigator.userAgent).indexOf('Opera',0)!=-1));
	this.isSafari=(new String(navigator.userAgent).indexOf('Safari/',0)!=-1);this.isMozilla=(new String(navigator.userAgent).indexOf('Mozilla/',0)!=-1)&&((navigator.userAgent.indexOf('Gecko/',0)!=-1)||(navigator.userAgent.indexOf('Opera',0)!=-1))&&((!this.isNS)&&(!this.isMSIE));
	if(!this.isMSIE)
		this.isBasedGecko=(new String(navigator.userAgent).indexOf('Gecko',0)!=-1);
	if(this.isMSIE)
		this.version=parseFloat(new String(navigator.userAgent).substring(new String(navigator.userAgent).indexOf("MSIE")+5,new String(navigator.userAgent).indexOf("MSIE")+9));
	else if(this.isNS){
		this.version=parseFloat(navigator.appVersion);
	if(this.version==5){
		this.version=parseFloat(new String(navigator.userAgent).substring(new String(navigator.userAgent).lastIndexOf('/')+1,new String(navigator.userAgent).length));
	}
	}else if(this.isOpera){
		this.version=parseFloat(navigator.appVersion);
	}else if(this.isMozilla){
		this.version=parseFloat(navigator.appVersion);
	}else if(this.isSafari){
		this.version=parseFloat(navigator.appVersion);
	}if(this.isBasedGecko){
		this.geckoEngineVersion=new String(navigator.userAgent).substring(new String(navigator.userAgent).indexOf('rv:')+3,new String(navigator.userAgent).indexOf(')',new String(navigator.userAgent).indexOf('rv:')+3));
		if(this.isSafari)this.geckoEngineVersion='non déterminable'
	}
	this.isMac=navigator.appVersion.indexOf("Mac")!=-1;
	if(this.isMSIE||this.isOpera)
		this.isWindows=navigator.appVersion.indexOf("Windows")!=-1;
	else if(this.isNS)
		this.isWindows=navigator.appVersion.indexOf("Win")!=-1;
}


/* News */
var scrollerObject=null;

function News(runTimePath,areaNewsMask,areaNewsContent,dataNews,dataRefreshDelay,movingIncrement,movingDelay){
	if(News.arguments.length!=News.length){
		alert('Methode News : Paramètres manquants. '+News.arguments.length+' fournis, contre '+News.length+' attendus');
		return false;
	}
	this.runTimePath=runTimePath;
	this.layerMask=areaNewsMask;
	this.layerContent=areaNewsContent;
	this.dataNews=dataNews;
	this.dataRefreshDelay=dataRefreshDelay;
	this.movingIncrement=movingIncrement;
	this.movingDelay=movingDelay;
	this.actualNews=0;
	this.masterProcess=null;
	this.scrollProcess=null;
	this.init=NewsInit;
	this.showNextNews=NewsShowNextNews;
	this.killProcess=NewskillProcess;
}
function NewsInit(){
	var content=this.dataNews[this.actualNews];
	//this.layerMask.onclick=new Function(this.runTimePath+".killProcess();return true;");
	var startTable='';
	var endTable='';
	if(new BrowserManager().isNS&&new BrowserManager().version>=4&&new BrowserManager().version<=5){
		content=startTable+this.dataNews[this.actualNews]+endTable;
	}
	layerWrite(this.layerContent,content,true);
	this.masterProcess=window.setTimeout(this.runTimePath+".showNextNews()",this.dataRefreshDelay);
}
var cpt=0;

function NewsShowNextNews(waitAction1,waitAction2){
	if(waitAction1!=true&&waitAction2!=true){
		if(this.actualNews<this.dataNews.length-1)
			this.actualNews=this.actualNews+1;
		else 
			this.actualNews=0;
		scrollerObject=new scrollerLayer('scrollerObject',this.layerContent,getLayerLeft(this.layerContent),getLayerHeight(this.layerMask),this.movingIncrement,this.movingDelay);
		scrollerObject.launchScroll();
		this.showNextNews(true,false);
	}
	if(waitAction1){
		if(scrollerObject.isScrolling){
			this.masterProcess=window.setTimeout(this.runTimePath+".showNextNews(true, false)",10);
		}else{
			var content=this.dataNews[this.actualNews];
			var startTable='<table cellpadding="0" cellspacing="0" border="0"><tr><td>';
			var endTable='</td></tr></table>';
			if(new BrowserManager().isNS&&new BrowserManager().version>=4&&new BrowserManager().version<=5){
				content=startTable+this.dataNews[this.actualNews]+endTable;
			}
			layerWrite(this.layerContent,content,true);
			setLayerTop(this.layerContent,(0-getLayerHeight(this.layerMask)));
			scrollerObject=new scrollerLayer('scrollerObject',this.layerContent,getLayerLeft(this.layerContent),0,this.movingIncrement,this.movingDelay);
			scrollerObject.launchScroll();
			this.masterProcess=window.setTimeout(this.runTimePath+".showNextNews(false, true)",10);
		}
	}else if(waitAction2){
		if(scrollerObject.isScrolling)
			this.masterProcess=window.setTimeout(this.runTimePath+".showNextNews(false, true)",10);
		else{
			this.masterProcess=window.setTimeout(this.runTimePath+".showNextNews()",this.dataRefreshDelay);
		}
	}
}
		
function NewskillProcess(){
	window.clearTimeout(this.masterProcess);
	this.masterProcess=null;
}

