// Présentation des news

function showPage(page){
	clearTimeout ( this.timer );
	if(this.curPage > -1){
		new Effect.Opacity(this.pages[this.curPage], { from: 1, to: 0, duration: 0.5 });
		setTimeout("tickersArr["+this.pos+"].noDisplay("+this.curPage+")",501);
		oldBtn=page-1;
		if(oldBtn<0)
			oldBtn=this.pages.length-1;
		document.getElementById("btn"+oldBtn).style.backgroundImage="url(http://www.bikerscup.eu/extension/dgsport/design/cup/images/fond_num.png)"
	}
	document.getElementById("title_detail").innerHTML=""
	document.getElementById("btn"+page).style.backgroundImage="url(http://www.bikerscup.eu/extension/dgsport/design/cup/images/fond_num_sel.png)"
	this.pages[page].style.display="block";
	new Effect.Opacity(this.pages[page], { from: 0, to: 1, duration: 1 });
	this.curPage=page;
	newPage=page+1;
	if(newPage >= this.pages.length){
		newPage=0;
	}
	if(this.pages.length>1)
		this.timer=setTimeout("tickersArr["+this.pos+"].showPage("+newPage+")",5000);
}
function noDisplay(id){
	this.pages[id].style.display="none";
}
function newsFeed(tickerId){
	this.pos=tickersArr.length;
	tickersArr[this.pos]=this;
	this.ticker=document.getElementById(tickerId);
	this.pages=new Array();
	this.curPage=-1;
	this.timer=0;
	this.showPage=showPage;
	this.noDisplay=noDisplay;
	var ti=this.ticker;
	var len=ti.childNodes.length;
	var cpt=0;
	for(var i=0 ; i<len ; i++){
		t=ti.childNodes.item(i);
		if(t.className=="page"){
			this.pages[cpt]=t;
			cpt++;
		}
	}
	if(cpt>0){
		var nav=document.createElement('div');
		nav.id="nav";
		nav.className="nav";
		this.nav=nav;
		this.ticker.appendChild(this.nav);
		for(i=0;i<cpt;i++){
			tmp=document.createElement('div');
			tmp.className="btn";
			tmp.id="btn"+i;
			tmp.innerHTML=i+1;
			tmp.ticker=this.pos;
			tmp.tPage=i;
			tmp.onclick= function () {
				tickersArr[this.ticker].showPage(this.tPage);
			};
			pageChilds=this.pages[i].childNodes;
			for(j=0;j<pageChilds.length;j++){
				child=pageChilds[j];
				if(child.className=="pageTitle"){
					tmp.title=child.innerHTML;
					tmp.onmouseover=function() {
						document.getElementById("title_detail").innerHTML= this.title;
					};
				}
			}
			nav.appendChild(tmp);
		}
		tmp=document.createElement('div');
		tmp.className="show_title";
		tmp.id="title_detail";
		nav.appendChild(tmp);
		this.showPage(0);
	}
}
var tickersArr=new Array();

/*Rotation de banni�res*/
function showBanner(page){
	clearTimeout ( this.timer );
	if(this.curPage > -1){
		new Effect.Opacity(this.pages[this.curPage], { from: 1, to: 0, duration: 0.5 });
		setTimeout("bannersArr["+this.pos+"].noDisplayBanner("+this.curPage+")",501);
	}
	this.pages[page].style.display="block";
	new Effect.Opacity(this.pages[page], { from: 0, to: 1, duration: 1 });
	this.curPage=page;
	newPage=page+1;
	if(newPage >= this.pages.length){
		newPage=0;
	}
	if(this.pages.length > 1){
		this.timer=setTimeout("bannersArr["+this.pos+"].showBanner("+newPage+")",5000);
	}
}

function noDisplayBanner(id){
	this.pages[id].style.display="none";
}

function bannerRotate(bannerId){
	this.pos=bannersArr.length;
	bannersArr[this.pos]=this;
	this.banner=document.getElementById(bannerId);
	this.pages=new Array();
	this.curPage=-1;
	this.timer=0;
	this.showBanner=showBanner;
	this.noDisplayBanner=noDisplayBanner;
	var ba=this.banner;
	var len=ba.childNodes.length;
	var cpt=0;
	for(var i=0 ; i<len ; i++){
		t=ba.childNodes.item(i);
		if(t.className=="banner_swap"){
			this.pages[cpt]=t;
			cpt++;
		}
	}
	if(cpt>0){
		this.showBanner(0);
	}
}
var bannersArr=new Array();

/* Menu et sous-menu */

function showMenu(item){
	if(menuToHide[item]){
		clearTimeout(menuToHide[item]);
		menuToHide[item]=0;
	}
	else{
		menu=document.getElementById(item);
		menu.style.display="block";
		new Effect.Opacity(menu, { from: 0, to: 1, duration: 0.2 });
	}
}
function hideMenuTiming(item){
	menuToHide[item]=0;
	menu=document.getElementById(item);
	menu.style.display="none";
	new Effect.Opacity(menu, { from: 1, to: 0, duration: 0 });
}
function hideMenu(item){
	menuToHide[item]=setTimeout("hideMenuTiming('"+item+"')",50);
}
var menuToHide=new Array();

/* Animation des circuits */

cornerTimer=-1;
cornerTimerUnsel=-1;

function selCorner(cornerId){
	if(cornerTimer != -1)
		clearTimeout (cornerTimer);
	if(cornerTimerUnsel != -1)
		clearTimeout (cornerTimerUnsel);
	cornerTimer=setTimeout("showCorner("+cornerId+")",500);
}

function unselCorner(){
	if(cornerTimer != -1)
		clearTimeout (cornerTimer);
	if(cornerTimerUnsel != -1)
		clearTimeout (cornerTimerUnsel);
	cornerTimerUnsel=setTimeout("showOriginalDetail()",2000);
}

function showCorner(cornerId){
	document.getElementById('detail').src=imgPath+cornerId+'.jpg';
}

function showOriginalDetail(){
	document.getElementById('detail').src=origDetail;
}
/*Les sponsors*/
function showSponsors(page){
	clearTimeout ( this.timer );
	if(this.curPage > -1){
		new Effect.Opacity(this.pages[this.curPage], { from: 1, to: 0, duration: 0.5 });
		setTimeout("sponsArr["+this.pos+"].noDisplaySponsor("+this.curPage+")",501);
	}
	this.pages[page].style.display="block";
	new Effect.Opacity(this.pages[page], { from: 0, to: 1, duration: 1 });
	this.curPage=page;
	newPage=page+1;
	if(newPage >= this.pages.length){
		newPage=0;
	}
	if(this.pages.length > 1){
		this.timer=setTimeout("sponsArr["+this.pos+"].showSponsors("+newPage+")",5000);
	}
}

function noDisplaySponsor(id){
	this.pages[id].style.display="none";
}

function sponsorRotate(bannerId){
	ba=document.getElementById(bannerId);
	ch=ba.childNodes;
	gCh=new Array();
	cpt=0;
	maxHeight=0
	for(i=0;i<ch.length;i++){
		c=ch[i];
		if(c.tagName=="TABLE"){
			gCh[cpt]=c;
			if(c.clientHeight>maxHeight){
				maxHeight=c.clientHeight;
			}
			cpt++;
		}
	}
	ba.style.height=maxHeight+"px";
	
	this.pos=sponsArr.length;
	sponsArr[this.pos]=this;
	this.banner=document.getElementById(bannerId);
	this.pages=new Array();
	this.curPage=-1;
	this.timer=0;
	this.showSponsors=showSponsors;
	this.noDisplaySponsor=noDisplaySponsor;
	var ba=this.banner;
	var len=ba.childNodes.length;
	var cpt=0;
	for(var i=0 ; i<len ; i++){
		t=ba.childNodes.item(i);
		if(t.className=="sponsor_swap"){
			this.pages[cpt]=t;
			t.style.display="none";
			cpt++;
		}
	}
	if(cpt>0){
		this.showSponsors(0);
	}
}
var sponsArr=new Array();
