// JavaScript Document

Navigateur = navigator.appName;
function bbcode(txt1,txt2,id,consigne) {
	
	//je recupère le texte contenue dans mon champ
	var obj = document.getElementById(id), sel;
	obj.focus();
	
	//Dans le cas de internet explorer
	if(document.selection && document.selection.createRange){
		
		sel = document.selection.createRange();
		
		//if (sel.parentElement()==obj) {
			if (!sel.text&&consigne!="undefined"&&consigne) {
				var interieur = window.prompt(consigne);
				if (interieur!=null) {
					sel.text = txt1+interieur+txt2;
				}
			} else {
				//Je change le contenu de mon champ en : avantSelection+text1+ma selection+text2+le reste du champ
				sel.text = txt1+sel.text+txt2;
			}
			
		//}
	}
	//Dans le cas d'un autre navigateur
	else if(String(typeof obj.selectionStart)!="undefined"){
		
		//Je recup la position du début de la sélection
		sel = obj.selectionStart;
		//Je recup la fin de la sélection
		selFin=obj.selectionEnd;
		
		//il n'y a pas de selection
		if (sel==selFin&&consigne!="undefined"&&consigne) {
			var interieur = prompt(consigne);
			if (interieur!=null) {
				obj.value+=txt1+interieur+txt2;
				obj.focus();	
			}
		} else {
			//Je change le contenu de mon champ en : avantSelection+text1+ma selection+text2+le reste du champ
			obj.value = (obj.value).substring(0,sel)+txt1+(obj.value).substring(sel,selFin)+txt2+(obj.value).substring(selFin,obj.value.length);
		}
	}
	else
		//SIle les conditions d'avant ne fonctionne pas j'ajoute simplement txt1+text2 a la position du curseur
		
		if (consigne!="undefined"&&consigne) {
			var interieur = window.prompt(consigne);
			if (interieur!=null) {
				obj.value+=txt1+interieur+txt2;
				obj.focus();	
			}
		} else {
			//Je change le contenu de mon champ en : avantSelection+text1+ma selection+text2+le reste du champ
			obj.value+=txt1+txt2;
			obj.focus();
		}
		
}


var a = null;

function galerie_right(id){
if (parseInt(document.getElementById('center_contents').style.width) > 350){
  document.getElementById(id).className= "navig_right_hover";
  document.getElementById("left_galerie").className= "navig_left";
   if( - parseInt(document.getElementById('center_contents').style.marginLeft) > (parseInt(document.getElementById('center_contents').style.width) - 518) ){
 galerie_right_inactive()
  }else{ 
if(a!= null){ //cas ou le mouseup se fait, on remet supprime le setInterval du mousedown 
  clearTimeout(a);
  
  if(Navigateur == 'Microsoft Internet Explorer'){
  a = setInterval("decal_left(2)", 4);
  }else{
  a = setInterval("decal_left(3)", 7);
  }
  
}else{ //sinon on lance notre mouseover
  if(Navigateur == 'Microsoft Internet Explorer'){
  a = setInterval("decal_left(2)", 4);
  }
      else{
  a = setInterval("decal_left(3)", 7);
      }
   }
}
}
}
function galerie_right_off(id){
	document.getElementById(id).className= "navig_right";
	clearTimeout(a);
	 if( - parseInt(document.getElementById('center_contents').style.marginLeft) > (parseInt(document.getElementById('center_contents').style.width) - 518) ){
 galerie_right_inactive()
  }
}
function galerie_right_inactive(){
document.getElementById("right_galerie").className= "navig_right_inactive";
}
function galerie_right_fast(id){
if (parseInt(document.getElementById('center_contents').style.width)>350){

   if( -parseInt(document.getElementById('center_contents').style.marginLeft) > parseInt(document.getElementById('center_contents').style.width) - 518 ){
 galerie_right_inactive();
  }else{ 
  clearTimeout(a);
  
	document.getElementById(id).className= "navig_right";
	
  if(Navigateur == 'Microsoft Internet Explorer'){
  a = setInterval("decal_left(3)", 5);
  }else{
  a = setInterval("decal_left(8)", 3);
  }
}
  }
}


function galerie_left(id){

if (parseInt(document.getElementById('center_contents').style.width)>350){
document.getElementById("right_galerie").className= "navig_right";
 if(parseInt(document.getElementById('center_contents').style.marginLeft) >= 0){

  galerie_left_inactive();
  }else{  
  document.getElementById(id).className= "navig_left_hover";
 
  if(a!= null){ //cas ou le mouseup se fait, on remet supprime le setInterval du mousedown 
  clearTimeout(a);
  
  if(Navigateur == 'Microsoft Internet Explorer'){
  a = setInterval("decal_right(2)", 4);
  }else{
  a = setInterval("decal_right(3)", 7);
  }
  
   }  
      else{ //sinon on lance notre mouseover 
   
   
   
  if(Navigateur == 'Microsoft Internet Explorer'){
  a = setInterval("decal_right(2)", 4);
  }else{
  a = setInterval("decal_right(3)", 7);
  }
     }
}
 }
}
function galerie_left_off(id){
   document.getElementById(id).className= "navig_left";
   clearTimeout(a);
   if(parseInt(document.getElementById('center_contents').style.marginLeft) >= 0){
   galerie_left_inactive();
   }
}
function galerie_left_inactive(){
document.getElementById("left_galerie").className= "navig_left_inactive";
}

function galerie_left_fast(id){
if (parseInt(document.getElementById('center_contents').style.width)>350){   
   if(parseInt(document.getElementById('center_contents').style.marginLeft) >= 0){
  galerie_left_inactive();
  }else{
   clearTimeout(a);   
   document.getElementById(id).className= "navig_left";   
  if(Navigateur == 'Microsoft Internet Explorer'){
  a = setInterval("decal_right(3)", 5);
  }else{
  a = setInterval("decal_right(8)", 3);
  }
     }
}
}



function decal_right(valeur){
 if(parseInt(document.getElementById('center_contents').style.marginLeft) >= 0){
   galerie_left_inactive();
  }else{  
   document.getElementById('center_contents').style.marginLeft=(parseInt(document.getElementById('center_contents').style.marginLeft)+valeur)+'px';
  }
}
function decal_left(valeur){
 if( -parseInt(document.getElementById('center_contents').style.marginLeft) > parseInt(document.getElementById('center_contents').style.width) - 518 ){
 galerie_right_inactive();
  }else{ 
  document.getElementById('center_contents').style.marginLeft=(parseInt(document.getElementById('center_contents').style.marginLeft)-valeur)+'px';
  }
}

function change_image(id){
   document.getElementById(id).className= "active_img";
}

function desactive_image(id){
   document.getElementById(id).className= "";
}

function centrer_img(id,hauteur){
	
	
	document.getElementById(id).style.marginTop=(200-hauteur)/2+"px";
	
}

function centrer_img_gd(id,hauteur){
	
	
	document.getElementById(id).style.marginTop=(330-hauteur)/2+"px";
	
}




function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher. 
   { 

  if (Navigateur=="Microsoft Internet Explorer") {

   for(var i=0; i<document.images.length; i++) 
      { 
   var img = document.images[i] 
   var imgName = img.src.toUpperCase() 
   if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
      { 
   var imgID = (img.id) ? "id='" + img.id + "' " : "" 
   var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
   var imgStyle = "display:inline-block;" + img.style.cssText  
   if (img.align == "left") imgStyle = "float:left;" + imgStyle 
   if (img.align == "right") imgStyle = "float:right;" + imgStyle 
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
   var strNewHTML = "<span " + imgID + imgClass + imgTitle 
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
   img.outerHTML = strNewHTML 
   i = i-1 
      } 
      } 
      }
   } 
//Fonction qui gère les évenements
function addEvent(source, type, callback) {
  // fonction d'abstraction pour enregistrer un gestionnaire d'evenement
  // comprend le DOM standard, la syntaxe prorietaire MSIE, l'ancien modele HTML
  // source : objet sur lequel ajouter le gestionnaire d'evenement
  // type : type d'evenement
  // callback : fonction qui traitera l'evenement
  if (source.addEventListener){		// code standard DOM
    source.addEventListener(type, callback, false);
    return true;
  } else if (source.attachEvent){ 	// code propriétaire MSIE
    var r = source.attachEvent("on"+type, callback);
    return r;
  } else {        	// code navigateur sans support DOM-event
    eval('source.on' + type + '= callback') ;
  }
}

function gestionEvent() {
  correctPNG();
  creerBoiteApercu();
}

addEvent(window,"load",gestionEvent) 



