// JavaScript Document version 1.05
function vIE(){return (navigator.appName=='Microsoft Internet Explorer')?parseFloat((new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})")).exec(navigator.userAgent)[1]):-1;}

function lecteur(id){
	//var sizes =  (document.location.href.indexOf('actu.php')!=-1)?"&L=150&H=150":"&L=278&H=205";
	var sizes = "&L=278&H=205";
	var obj;
	obj = new Player(id, 'inc/php/image.php?image=', tab_img, 1,sizes);
	obj.initPrec('bouton_prec');
	obj.initSuiv('bouton_suiv');
	obj.initZoom('agrandir_image', 'images/', 'medias/close.gif');
	obj.initLoading('loading', '<img src="medias/loading1.gif" alt="" />');
	obj.info('nb_images');
	obj.reset(id);
	obj.writeImg(0);
}

function init_galerie(className){
	var tab=new Array();
	tab = getElementsByClassName(className);
	nb_tab=tab.length;
	for(var i=0; i<nb_tab; i++){
		tab[i].onclick=function(){
			openDiv(this.href, 'medias/close.gif');
			return false;
		}
	}
}



function swapImg(item,img){
	item.src = 'medias/'+img+'.png';
}

function getCssStyleValue (element /*element html*/, style/*style recherché*/){
  if(element.currentStyle){
    return element.currentStyle[style];
  }
  else{
    return window.getComputedStyle(element,null).getPropertyValue(style);
  }
}
///////////////////////
function centerPopUp (file,w,h,scrollbar,name){
var cx = Math.round ((screen.availWidth / 2) - (w / 2));
var cy = Math.round ((screen.availHeight / 2) - (h / 2));
scrollbar=(scrollbar == "undefined")?'no':scrollbar;
name=(name == "undefined")?'popUp':name;
window.open(file, name, 'height='+ h +', width='+ w +', top='+ cy +', left='+ cx +', toolbar=no, menubar=yes, location=no, toolbar = no,resizable=yes, scrollbars='+scrollbar+', status=no');
}
function openPop (file,w,h,scrollbar,name){
scrollbar=(scrollbar == "undefined")?'no':scrollbar;
name=(name == "undefined")?'popUp':name;
window.open(file, name, 'height='+ h +', width='+ w +', top=0, left=0, toolbar=no, menubar=yes, location=no, toolbar = no,resizable=yes, scrollbars='+scrollbar+', status=no');
}
////////////////////////////// messages d'alertes simple
function simpleAlert(msg){
	var al = new Alert_window();
	//al.setCloseButton("X","Fermer");
	al.create(msg);
}


function pop_up(){	
fenetre=window.open('','popup','toolbar=0, location=0, directories=0, status=0,  resizable=1, scrollbars=1, height=650,width=650');
}

function pop_up2(){	
fenetre2=window.open('','popup2','toolbar=0, location=0, directories=0, status=0,  resizable=1, scrollbars=1, height=650,width=650');
}
//////////////////////////////////////////////////////popup centrage et redim
function pop_redim(nx,ny) {
	xall = (screen.availWidth / 2);
	yall = (screen.availHeight / 2);
	window.resizeTo(nx,ny);
	self.moveTo(xall - (nx / 2), yall - (ny / 2));
	self.focus();
}

///////////////////////////////////fermer pop ou fenetre
function pop_fermer() { 
	opener=self; 
	self.close(); 
} 

function ouvre_ferme_inline(id) {
	var d = document.getElementById(id);
	
	if(d){
		if (d.style.display=='inline') d.style.display='none'; 			
		else d.style.display='inline';
	}
			
}

function ouvre_ferme_block(id) {
	var d = document.getElementById(id);
	if(d){
		if (d.style.display=='block') d.style.display='none'; 			
		else d.style.display='block';
	}
}







///////////////////////////////////////////////////////////////////
// JavaScript Document
function getViewSize() { //// renvoie taille de la zone d'affichage
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  /// pr enlever espace occupé par scrollbars
  if(typeof(window.innerHeight) == 'number'){
	 if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ){
		myWidth=myWidth-Math.max((window.innerWidth - document.documentElement.clientWidth),0);
		myHeight=myHeight-Math.max((window.innerHeight - document.documentElement.clientHeight),0);
	}
	/*else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ){
		myWidth=myWidth-(window.innerWidth - document.body.clientWidth);
		myHeight=myHeight-(window.innerHeight - document.body.clientHeight);
	 }*/
  }  
   return [ myWidth, myHeight ];
}

function initPositionDiv(elem){
	var tab = new Array();
	tab = getScrollXY();
	elem.style.top=tab[1]+'px';
	elem.style.left=tab[0]+'px';
	elem.style.height=getViewSize()[1]+'px';
	window.setTimeout(function(){initPositionDiv(elem)}, 10);
}

function openDiv(urlImg, urlFermer){
	//, elemFlash
	var newDiv=document.createElement("div");
	var opa=0.6;
	newDiv.style.position="absolute";
	newDiv.style.zIndex=100;
	//newDiv.style.top=0;
	initPositionDiv(newDiv);
	newDiv.style.width='100%';
	newDiv.style.backgroundColor='#000000';
	newDiv.style.opacity=opa;
	newDiv.style.filter = "alpha(opacity=" + (opa*100) + ")"; /// pr IE
	document.body.appendChild(newDiv);
	
	
	
	var img = new Image();
	img.src=urlImg;
	
	var img2 = new Image();
	img2.src=urlFermer;
	

	chargementFini=function(){	
		var newDiv2=document.createElement("div");
		newDiv2.style.position="absolute";
		newDiv2.style.zIndex=200;
		newDiv2.style.textAlign='right';
		newDiv2.style.width=img.width+'px';
		newDiv2.style.border='10px solid white';
		newDiv2.style.backgroundColor='#ffffff';
		newDiv2.style.left='50%';
		
		newDiv2.style.cursor='hand';
		if(newDiv2.style.cursor=='')newDiv2.style.cursor='pointer';
		/*
		var top=Math.round((img.height+20)/2);
		newDiv2.style.marginTop='-'+top+'px';
		newDiv2.style.top='50%';
		*/
		
		var daWidth=img.width;
		var daHeight=img.height;
		
		img=document.createElement("img");
		img.src=urlImg;
		
		img2=document.createElement("img");
		img2.src=urlFermer;
		img2.style.marginTop='10px';
		
		//newDiv2.style.top='100px';
		newDiv2.style.marginLeft='-'+Math.round((daWidth+20)/2)+'px';
		
		newDiv2.appendChild(img);
		newDiv2.appendChild(img2);		
		
		
		document.body.appendChild(newDiv2);
		
		var temp=getViewSize()[1]-newDiv2.offsetHeight;
		if(temp>0){newDiv2.style.top=getScrollXY()[1]+(temp/2)+'px';}
		else{newDiv2.style.top=getScrollXY()[1]+'px';}
		
		
		var IE6=vIE();
		if(IE6<=6 && IE6>0){
			var Iframe=document.createElement("iframe");
			Iframe.style.position="absolute";
			Iframe.style.zIndex=100;
			Iframe.style.border='none';
			Iframe.style.backgroundColor='#ffffff';
			
			Iframe.style.width=newDiv2.offsetWidth;
			Iframe.style.height=newDiv2.offsetHeight;
			Iframe.style.top=newDiv2.style.top;
			Iframe.style.marginLeft=newDiv2.style.marginLeft;
			
/*			Iframe.style.width=(daWidth+10)+'px';
			Iframe.style.height=(daHeight+10)+'px';
			Iframe.style.left='50%';
			Iframe.style.marginLeft='-'+Math.round((daWidth+20)/2)+'px';
*/			
			document.body.appendChild(Iframe);
			
/*			var temp=getViewSize()[1]-Iframe.offsetHeight;
			if(temp>0){Iframe.style.top=getScrollXY()[1]+(temp/2)+'px';}
			else{Iframe.style.top=getScrollXY()[1]+'px';}
*/		}
		
		/*
		var flash=elemFlash.innerHTML;
		elemFlash.innerHTML='';
		*/
		//, elemFlash, flash
		newDiv2.onclick=function(){closeDiv(newDiv, newDiv2); if(Iframe){document.body.removeChild(Iframe);}}
	}
	
	verifChargement(img);
	

	
}

function closeDiv(elem, elem2){
	//, elemFlash, flash
	document.body.removeChild(elem);
	document.body.removeChild(elem2);
	//elemFlash.innerHTML=flash;
}

function verifChargement (img){	
	if(img.complete == true ){
		if(chargementFini){chargementFini();}
	}
	else{
		if(img.complete == undefined){
			if(chargementFini) {
				img.onload = function(){chargementFini()};
			}
		}
		else{
			window.setTimeout(function(){verifChargement(img)}, 10);
		}
	}
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};
