function getElementsByClassName(className)
{
   return getSousElementsByClassName(document,className);
}
function getSousElementsByClassName(elt,className,tag)
{
   if(typeof(tag)=='undefined')
       var elts=elt.getElementsByTagName('*');
   else
       var elts=elt.getElementsByTagName(tag);
   var classArray=new Array();
   for(var j=0;j<elts.length;++j)
   {
       if(fcthasClass(elts[j],className))
           classArray.push(elts[j]);
   }
   return classArray;
}
function fcthasClass(element,className)
{
 return (
   element.className &&
   element.className.match( new RegExp( "\\b"+className+"\\b" ) )
 ) ? true : false;
} 


function stripslashes(str)
{	return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');	}

function addClass(element,ma_classe)
{
	delClass(element,ma_classe);
	if(element.className)
		element.className+=' '+ma_classe;
	else
		element.className=ma_classe;
}
function delClass(element,ma_classe)
{
	if(element.className.indexOf(' ')>0)
		element.className=element.className.replace(' '+ma_classe,'');
	else
		element.className=element.className.replace(ma_classe,'');
}

// MEDIATHEQUE
var pagination_current = 1;
function pagination_mediatheque(element,nb_pagination,num_pagination)
{
	tab_ul=getSousElementsByClassName(element.parentNode.parentNode.parentNode,'mediatheque','UL');
	if(tab_ul.length>0)
	{
		tab_li=tab_ul[0].getElementsByTagName('LI');
		for(cpt_li=0;cpt_li<tab_li.length;cpt_li++)
		{			
			if(cpt_li>=((num_pagination-1)*nb_pagination)&&cpt_li<(num_pagination*nb_pagination))
				delClass(tab_li[cpt_li],'cache_img_mediatheque');
			else
				addClass(tab_li[cpt_li],'cache_img_mediatheque');	
		}	
	}

	tab_li_page=document.getElementById('pagination'+num_pagination).parentNode.parentNode.getElementsByTagName('LI');
	for(cpt_li_page=0;cpt_li_page<tab_li_page.length;cpt_li_page++){
		delClass(tab_li_page[cpt_li_page],'pagination_sel');
	}
	addClass(document.getElementById('pagination'+num_pagination),'pagination_sel');
	pagination_current = num_pagination;
}


// LoLo
var cpt_flow = (new Date()).getTime();
function ouvrir_lecteur(div_id,flv,w,h,legende){
	if(document.getElementById('minilogo_rouge'))
		document.getElementById('minilogo_rouge').style.zIndex='2';
	if(document.getElementById('conteneur'))
	document.getElementById('conteneur').style.zIndex='3';
	document.getElementById(div_id).style.display = 'block';
	document.getElementById(div_id).style.visibility = 'visible';
	
	document.getElementById(div_id).onclick = function(e){
		ferme_lecteur_video_flv(e,div_id);
	};
	
	flowplayer(div_id,
	{
		src:"images/players/flowplayer-3.1.5.swf?toto="+cpt_flow, 
		width:w, 
		height:h
	},
	{
		clip:{
		 	autoPlay:true, 
			autoBuffering:true,
			url:flv
		},
	   onLoad: function(){
			centrer_lecteur(div_id,w,h,legende);
		}
	});
}

function centrer_lecteur(div_id,w,h,legende){
	
	if(document.getElementById(div_id)){
		var div = document.getElementById(div_id);
		div.style.marginLeft = '0px';
		div.style.marginRight = '0px';
	}
	
	var objects = document.getElementById(div_id).getElementsByTagName('OBJECT');
	if(objects.length > 0){
		
		var player = objects[0];
		player.style.marginLeft = '-' + Math.floor(w/2) + 'px';
		player.style.marginTop = '-' + Math.floor(h/2) + 'px';
		
		if(legende.length > 0){
			var legend = document.createElement('DIV');
			legend.innerHTML = legende;
			legend.setAttribute('class','legende');
			div.appendChild(legend);
			legend.id = div_id + '_legende';
			legend.style.width = w - 30 + 'px';
			legend.style.marginTop = Math.floor(h/2) + 'px';
			legend.style.marginLeft = '-' + Math.floor(w/2) + 'px';
			legend.innerHTML += '<img class="fermer_lecteur" onclick="ferme_lecteur_video_flv(\''+div_id+'\');" title="fermer" alt="fermer" src="images/closelabel.gif"/>';
		}
	}
	
	document.getElementById(div_id+'_api').style.left = '50%';
	document.getElementById(div_id).style.visibility = 'visible';
}
function ferme_lecteur_video_flv(e,div_id){
	
	if(e)
		var target=e.target?e.target:e.srcElement;
	else
		var target=event.target?event.target:event.srcElement;
	
	if(target){
		if(target.id != div_id+'_legende'){
			document.getElementById(div_id).style.visibility='hidden';
			
			flowplayer(div_id).stop();
			flowplayer(div_id).close();
			
			document.getElementById(div_id+'_api').style.left = '5000px';
			if(document.getElementById('minilogo_rouge'))
				document.getElementById('minilogo_rouge').style.zIndex='3';
			if(document.getElementById('conteneur'))
				document.getElementById('conteneur').style.zIndex='1';
		}
	}
}
function ferme_lecteur_video(div_id){
	document.getElementById(div_id).style.display='none';
}

function pagination_precedente(element,nb_pagination){
	if(pagination_current > 1)
		pagination_mediatheque(element,nb_pagination,pagination_current-1);
}
function pagination_suivante(element,nb_pagination){
	if(document.getElementById('pagination'+(pagination_current+1)))
		pagination_mediatheque(element,nb_pagination,pagination_current+1);
}

var all = new Array();
all.push('menu_accueil_maison');
all.push('menu_musee');
all.push('menu_territoire');
all.push('menu_reunion');
all.push('menu_boutique');
all.push('menu_contact');
all.push('menu_accueil_institut');
all.push('menu_institut');
all.push('menu_boeuf');
all.push('menu_mouton');
all.push('menu_filiere');
all.push('menu_recherche');

function menuhover(color,id){
	
	for(var i=0;i<all.length;i++){
		if(document.getElementById(all[i])){
			delClass(document.getElementById(all[i]),'fleche'+color+'_sel');
			addClass(document.getElementById(all[i]),'fleche'+color);
		}
	}
	
	if(document.getElementById(id)){
		delClass(document.getElementById(id),'fleche'+color);
		addClass(document.getElementById(id),'fleche'+color+'_sel');
	}
}
function selectMenu(color,id){
	if(document.getElementById(id)){
		addClass(document.getElementById(id),'fleche'+color+'_sel');
	}
}

function add_links_target(){
	/*
	var tab_para = document.getElementsByClassName('para_float');
	for(var i=0;i<tab_para.length;i++){
		var tab_links = tab_para[i].getElementsByTagName('A');
		for(var j=0;j<tab_links.length;j++){
			tab_links[j].target='_blank';
		}
	}
	*/
}
