var menuselect="accueil";
var dossierselect="demo";

var interval_powerup=0;
var interval_poweroff=0;
//Detect browser for later use
browser = undefined;

if(navigator.userAgent.indexOf("MSIE")!=-1)
  browser = "IE";
else
  browser = "Mozilla";

var rand=0;
var btn_switch=1;

 var rand=0;
 var tab_juke=new Array('Demo','Creation','Production','Sound','Divers');
function random_jukebox(lancage)
{
  rand=Math.round((Math.random()*8 +5));
  var flag=0; 
  
  
  while(flag++ <= rand)
  {
    interval_juke=window.setTimeout("fadeOut('"+tab_juke[flag%5]+"',70,0)", 500+flag*150 );
  }
  
  
  if(lancage==true)
    window.setTimeout("changedossier('"+ tab_juke[flag%5] +"')", 500+(rand*150) );
  
  
  /*for (var i=0; i < tab_juke.length; ++i)
  {
    fadeOut(tab_juke[i],100);
  }
  */
  
}
function switch_click()
{
 
  if (btn_switch==1)
  {
    btn_switch=0;
    fadeOut('switch_on',100,1);
    power_off();
  }
  else
  {
   random_jukebox(1); 
    btn_switch=1;
    fadeIn('switch_on',0,100);
    power_up();
  }
 
}
function power_up()
{
  
  window.clearTimeout(interval_poweroff);
  var powerup= getOpacity('power_on');
  
  setOpacity('power_on',powerup+1);
  if(powerup< 100)
  {
    if (Math.ceil(powerup) == 50)
    {
      fadeIn('vu_metre50',0,100);
      
    }
    if (Math.ceil(powerup)== 99)
    {
      fadeOut('vu_metre50',100,0);
      fadeIn('vu_metre99',40,100);
    }    
    window.clearTimeout(interval_powerup);
    interval_powerup=window.setTimeout("power_up()", 100);
   }
  
}
function power_off()
{
 window.clearTimeout(interval_powerup);
  var poweroff= getOpacity('power_on');
  
  setOpacity('power_on',poweroff-1.01);
  if(poweroff > 0)
  {
    
    if (poweroff == 99)
    {
     
      fadeIn('vu_metre50',0,100);
      fadeOut('vu_metre99',100,0);
    }
    if (poweroff== 50)
    {
      fadeOut('vu_metre50',100,0);
      
    }    
    window.clearTimeout(interval_poweroff);
    interval_poweroff=window.setTimeout("power_off()", 50);
   }
  
   
  
}

function getOpacity(element)
{

  var opacity = null;
  
  //Get the opacity based on the current browser used
  if(browser=="IE") 
  {
    filter = document.getElementById(element).style.filter;
    if(filter) 
    {
        alpha = filter.split("alpha(opacity:");
        
        opacity = alpha[1].substr(0,(alpha[1].length-1));
    }
  }
  else
  {
    opacity = document.getElementById(element).style.opacity *100;
  }
  opacity=Math.ceil(opacity);
    //afficheur.value=(opacity)+" %";
  return opacity;
}



function random_moover()
{
  
  var flag=0; 
       
  while(flag++ <= 6)
  {
  rand=Math.round((Math.random()*4 +1));
    interval_moover=window.setTimeout("chg_moover("+rand+")", 800+flag*50*rand );
   }
  interval_moover_function=window.setTimeout("random_moover()",Math.round((Math.random()*10 +1 *8000+2000)));
  
  /*for (var i=0; i < tab_juke.length; ++i)
  {
    fadeOut(tab_juke[i],100);
  }
  */
  
}
function chg_moover(nbr)
{
   //fadeOut('moover',80,60);
   document.getElementById('moover').src="images/moover_"+nbr+".png";
   fadeIn('moover',00,40);
   
}
function menu_select(objid,state)
{

    if (state=="click")
    {
      menuselect=objid;
     
      setOpacity("accueil",0);
      setOpacity("studio",0);
      setOpacity("formation",0);
      setOpacity("services",0);
      setOpacity("medias",0);
      setOpacity("liens",0);
      setOpacity("contact",0);
      
      
      
      setOpacity(menuselect,100);
      
    }
    
    
    if (state=="in" && objid!=menuselect)
        fadeIn(objid,00,100);
      
    if (state=="out" && objid!=menuselect)
        fadeOut(objid,100,0);
 }

function dossier_select(objid,state)
{

    if (state=="click")
    {
      dossierselect=objid;
       setOpacity("Demo",0);
      setOpacity("Creation",0);
      setOpacity("Production",0);
      setOpacity("Sound",0);
      setOpacity("Divers",0);
      
      
      setOpacity(dossierselect,100);
      
    }
      
    if (state=="in" && objid!=dossierselect)
        fadeIn(objid,00,100);
      
    if (state=="out" && objid!=dossierselect)
       fadeOut(objid,100,0);
       
}
  function changedossier(dossier)
  {
     //document.getElementById(dossierselect).src='images/star.gif';
     dossierselect=dossier;
     fadeIn(dossier,0);
     var monswf =document.playermp3; 
     monswf.LoadMovie(0,"music/playermp3.swf?dossier="+dossier+"&playauto=1");
     
  }
  
    
   	function changesrc(id,state)
    {
       if (state=="on")
          document.getElementById(id).src=document.getElementById(id).src.replace("off","on");
        
       if (state=="off")
            document.getElementById(id).src=document.getElementById(id).src.replace("on","off");
        
    }
   function change_lecteur()
   {
      var lecteur=document.getElementById('lecteur');
    if(lecteur.style.visibility=='visible')
    {
     changesrc('player','off'); 
     lecteur.style.visibility='hidden';
    }
    else
    {
          changesrc('player','on'); 
          lecteur.style.visibility='visible';
    } 
  }

function preloadImages() 
{
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
  var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
  function ouvrir_menu(url,titre,img_width,img_height)
 {
    var widthMax=800;
    var heightMax=400;
    
    var monImage = new Image();
    document.getElementById("menuimg").src="images/spacer.gif";
    
    
  
    var tailleW = img_width;
    var tailleH = img_height;
    
    if(tailleH >heightMax)
    {      
      tailleW=tailleW /(tailleH/heightMax);
      tailleH=heightMax;
    } 
    if(tailleW >widthMax)
    { 
     
      tailleH=tailleH /(tailleW/widthMax);
      tailleW=widthMax;
     } 
    document.getElementById("menuimg").src=url;
    document.getElementById("menuimg").style.width = tailleW+ "px";
    document.getElementById("menuimg").style.height = tailleH +"px";
    document.getElementById("menu_context").style.display = "block"; 
    
    var position_x = 0;//(document.body.clientWidth -tailleW )/2 -100;
    var position_y = (document.body.scrollTop+00) ;
    document.getElementById("menu_context").style.top = position_y;
    document.getElementById("menu_context").style.left = position_x;
    
    fadeIn('menu_context',-50);
   
  }
   function fermer_menu()
  {
     document.getElementById("menuimg").src="images/spacer.gif";
    document.getElementById("menu_context").style.display = "none";
  //activ_pop = setTimeout("ouvrir_menu()",30000)
  }
  
function change_img(img)
{
  TEMP.location="temp.php?img="+img;
  bannerup.src=img;
}
function initImage() 
{
  imageId = 'thephoto';
  image = document.getElementById(imageId);
  setOpacity(imageId, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
function spanload(nom)
{
   document.getElementById(nom).style.background='white no-repeat top center';
  
}
function setOpacity(objid, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
   document.getElementById(objid).style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  document.getElementById(objid).style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  document.getElementById(objid).style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  document.getElementById(objid).style.opacity = opacity/100;
}


var fadeInT=1;
function fadeIn(objId,opacity,opacity2,over) 
{
  
  if(opacity2==undefined)
  {
    opacity2=100;
  }
  
  if (document.getElementById)
  {
    obj = document.getElementById(objId);

 
    if (opacity <= opacity2)
    {
      setOpacity(objId, opacity);
      opacity += 10;
      fadeInT=window.setTimeout("fadeIn('"+objId+"',"+opacity+","+opacity2+")", 10);
    }
  }
}
function fadeOut(objId,opacity,opacity2) 
{

  //clearTimeout(fadeInT);
  if(opacity2==undefined)
  {
    opacity2=00;
  }
  

  if (document.getElementById)
  {
    obj = document.getElementById(objId);
    if (opacity >= opacity2)
    {
      setOpacity(objId, opacity);
      opacity += -10;
      window.setTimeout("fadeOut('"+objId+"',"+opacity+","+opacity2+")", 10);
    }
  }
}
function PlaySound(soundobj)
{
 var thissound= eval("document."+soundobj);
 thissound.Play();
}
function StopSound(soundobj)
{
 var thissound= eval("document."+soundobj);
 thissound.Stop();
}

 
  function tailleimg(id,url)
  {
     var heightMax=170;
     var widthMax=170;
     
      monImage = new Image;
      monImage.src = document.getElementById(id).src;
      var tailleW = monImage.width
      var tailleH = monImage.height 
      if(tailleH >heightMax)
      {      
        tailleW=tailleW /(tailleH/heightMax);
        tailleH=heightMax;
      } 
      if(tailleW >widthMax)
      {      
        tailleH=tailleH /(tailleW/widthMax);
        tailleW=widthMax;
      } 
     
     
      
     // alert(position_x +" - " +position_y);
      //document.getElementById(id).src=url;
      document.getElementById(id).width = tailleW;
      document.getElementById(id).height = tailleH;
     
  }
  
  function showorhide(id)
  {
    if(document.getElementById(id).style.display=="none")
      document.getElementById(id).style.display="block";
    else  
      document.getElementById(id).style.display="none";
  }
  function changeImg(obj,obj2,url,txt)
  {
  //alert(txt);
    document.getElementById(obj).src="../admin/"+url;
    //document.getElementById(obj2).innertext=txt;
  }

