/*
Fonctions pour le site MaBule

Gaëtan Parel - Juin 2008
*/

/* Variables... Pour le menu de gauche et les carousels défilants.
   ATTENTION : Ne modifier que si vous êtes totalement sûr et certain de ce que vous faîtes !!! */
var p=new Array();
p['scroll']=new Array();
p['scroll']['width']=101;
p['scroll']['move']=new Array();
p['scroll']['speed']=70;
p['scroll']['delay']=35;
p['scroll']['numberOfItems']=4;

var tabMove=new Array();
function initAutoMove() {
	var n=1;
	while (document.getElementById('content-'+n) && n<=1) {
		if (p['scroll'][n]>p['scroll']['numberOfItems']) {
			tabMove.push(n);
		}
		n++;
	}
	setTimeout('autoMove()',6000);
}

var overCarousel=false;
var cptMoveCarousel=0;
function autoMove(cpt) {
	if (cpt!=cptMoveCarousel) return;
	if (overCarousel) return;
	for (var i=0 ; i<tabMove.length ; i++) {
		goRight(tabMove[i]);
	}
	cptMoveCarousel++;
	setTimeout('autoMove('+cptMoveCarousel+')',6000);
}
/* Pour les carousels. Fonction appelée lorsque l'on survole une flèche (gauche / droite) */
function overArrow(arrow) {
	arrow.className=arrow.className.replace('left','left-over');
	arrow.className=arrow.className.replace('right','right-over');
}

/* Pour les carousels. Fonction appelée lorsque l'on ne survole PLUS une flèche (gauche / droite) */
function outArrow(arrow) {
	arrow.className=arrow.className.replace('-over','');
}

function overTheCarousel() {
	overCarousel=true;
}

function outTheCarousel() {
	overCarousel=false;
	cptMoveCarousel++;
	setTimeout('autoMove('+cptMoveCarousel+')',6000);
}
/* Pour les carousels. Fonction appelée lorsque l'on a cliqué sur la flèche de gauche. Elle fait défiler les éléments
   contenus dans le carousels vers la gauche.*/
function goLeft(n,margin,targetMargin,speed) {
	if (typeof(margin)=='undefined') {
		if(typeof(p['scroll']['move'][n])=='undefined') p['scroll']['move'][n]=0;
		if (p['scroll']['move'][n]!=0) return;
		var margin=parseInt(getStyle('scroll-move-'+n,'margin-left'));
		var targetMargin=margin+(p['scroll']['width']*p['scroll']['numberOfItems']);
		speed=p['scroll']['speed'];
		p['scroll']['move'][n]=1;
	}
	var diff=targetMargin-margin;
	if (diff<160 && speed>5) {
		speed=speed-Math.round(speed/3+5);
		if (speed<5) speed=5;
	}
	margin=margin+speed;
	if (margin>0) {
		var a = document.getElementById('scroll-move-'+n).getElementsByTagName('a');
		var first=a[0];
		var last=a[a.length-1];
		document.getElementById('scroll-move-'+n).removeChild(a[a.length-1]);
		margin=margin-p['scroll']['width'];
		document.getElementById('scroll-move-'+n).insertBefore(last,first);
		targetMargin=targetMargin-p['scroll']['width'];
	}
	if (margin>targetMargin) margin=targetMargin;
	document.getElementById('scroll-move-'+n).style.marginLeft=margin+'px';
	if (margin<targetMargin) setTimeout('goLeft('+n+','+margin+','+targetMargin+','+speed+')',p['scroll']['delay']);
	else p['scroll']['move'][n]=0;
}

/* Pour les carousels. Fonction appelée lorsque l'on a cliqué sur la flèche de droite. Elle fait défiler les éléments
   contenus dans le carousels vers la droite.*/
function goRight(n,margin,targetMargin,speed) {
	if (typeof(margin)=='undefined') {
		if(typeof(p['scroll']['move'][n])=='undefined') p['scroll']['move'][n]=0;
		if (p['scroll']['move'][n]!=0) return;
		var margin=parseInt(getStyle('scroll-move-'+n,'margin-left'));
		var targetMargin=margin-(p['scroll']['width']*p['scroll']['numberOfItems']);
		speed=p['scroll']['speed'];
		p['scroll']['move'][n]=-1;
	}
	var maxMargin=(p['scroll'][n]-p['scroll']['numberOfItems'])*p['scroll']['width']*-1;
	var diff=targetMargin-margin;
	if (diff>-160 && speed>5) {
		speed=speed-Math.round(speed/3+5);
		if (speed<5) speed=5;
	}
	margin=margin-speed;
	if (margin<=maxMargin) {
		var a = document.getElementById('scroll-move-'+n).getElementsByTagName('a');
		var first=a[0];
		var last=a[a.length-1];
		document.getElementById('scroll-move-'+n).removeChild(a[0]);
		margin=margin+p['scroll']['width'];
		insertAfter(document.getElementById('scroll-move-'+n), first, last);
		targetMargin=targetMargin+p['scroll']['width'];
	}
	if (margin<targetMargin) {
		margin=targetMargin;
	}
	document.getElementById('scroll-move-'+n).style.marginLeft=margin+'px';
	if (margin>targetMargin) setTimeout('goRight('+n+','+margin+','+targetMargin+','+speed+')',p['scroll']['delay']);
	else p['scroll']['move'][n]=0;
}
function toggleAffichageCommentaires(){
	var formComment = document.getElementById('blockComment');
	if(formComment.style.display == 'block'){
		formComment.style.display = 'none';
	}
	else {
		formComment.style.display = 'block';
	}
}
function afficheNews(sid){
	if(document.getElementById('texte-'+sid).style.display == 'block'){
	document.getElementById('texte-'+sid).style.display = 'none';
	document.getElementById('titre-'+sid).className = 'titreClosed';
	}
	else {
		document.getElementById('texte-'+sid).style.display = 'block';
		document.getElementById('titre-'+sid).className = 'titreOpen';
	}
}
function closeNews(sid){
	document.getElementById('texte-'+sid).style.display = 'none';
	document.getElementById('titre-'+sid).className = 'titreClosed';
}
function playVideoRubrique(vid, cpt){
	loadVideos({'xobix_video_id': vid});
	if (cpt != 0){
		for(i=1; i < 7; i++){
			document.getElementById('vid-'+i).className = 'noselect';
		}
	document.getElementById('vid-'+cpt).className = 'selected';
	}
}







function overOutButtonPlay(act) {
	if (act==0) {
		document.getElementById('playerContentPlayButton').className='playerContentPlayButtonNormal';
	} else {
		document.getElementById('playerContentPlayButton').className='playerContentPlayButtonOver';
	}
}
function playFirstVideoTTC() {
	document.getElementById('playerContentPlayButton').style.display='none';
	document.getElementById('playContentPlayButtonBar').style.display='none';
	mainPlayer.playVideo(firstVideoTTCId);
}


