// @TRONC /Kaley/Kaley.Fx.js
 
 
function ZoomInIcon(icon){   
  if (icon.tmr!=null)
    window.clearInterval(icon.tmr);
  if (icon.z==null) 
    icon.z = 0;
  icon.tmr = window.setInterval("_ZoomInIcon('"+icon.id+"')", 20);
}
 
function _ZoomInIcon(idIcon){
  var icon = document.getElementById(idIcon);
  icon.z += 4;
  if (icon.z>15) icon.z = 15;
  icon.style.backgroundPosition = "0px "+ (-(icon.z*72))+"px"; 
  if (icon.z>=15) { 
    window.clearInterval(icon.tmr);
    icon.tmr = null;
  }
}
 
function ZoomOutIcon(icon){
   if (icon.tmr!=null)
     window.clearInterval(icon.tmr);
   icon.tmr = window.setInterval("_ZoomOutIcon('"+icon.id+"')", 30);
}
 
 
function _ZoomOutIcon(idIcon){
   var icon = document.getElementById(idIcon); 
   icon.style.backgroundPosition =  "0px "+ (-(icon.z*72))+"px"; 
   icon.z -= 1; 	
   if (icon.z<0) icon.z = 0;
   if (icon.z<=0) { 
     icon.style.backgroundPosition =  "0px 0px"; 
     window.clearInterval(icon.tmr);
     icon.tmr = null;
   }
}

                              // 0..1
function SetAlpha(element,factor)
{
    if (factor>1) factor = 1;
    else
    if (factor<0) factor = 0;

    try {
      if (element.style.filter=="")
         element.style.filter = "Alpha(opacity="+Math.floor(factor*100)+")"; 
         else
         element.filters.alpha.opacity=Math.floor(factor*100);
    } catch (e) {
    }

   // FF   
   element.style.MozOpacity=factor;
   
   // Autre
   element.style.opacity=factor;

}


function DropDownShutter(idShutter, startPos, endPos){ 
  var shutter = document.getElementById(idShutter);   
  if (shutter.tmr!=null)
    window.clearInterval(shutter.tmr);
  if (shutter.z==null) 
    shutter.z = 0;    
  shutter.style.display = "block";    
  shutter.startPos = startPos;
  shutter.endPos = endPos;
  shutter.lengthPos = endPos-startPos;              
  shutter.tmr = window.setInterval("_DropDownShutter('"+shutter.id+"')", 10);
}
 
 
function _DropDownShutter(idShutter){
  var shutter = document.getElementById(idShutter);
  
  shutter.z += 4;

  var factor = Number((1/shutter.lengthPos)*shutter.z);
  SetAlpha(shutter,factor); 
                       
  shutter.style.top = (shutter.startPos+(shutter.z))+"px";
     
  if (shutter.z>=shutter.lengthPos) { 
    window.clearInterval(shutter.tmr);
    shutter.tmr = null;
    shutter.style.top = shutter.endPos+"px";
  }
}



function DropUpShutter(idShutter, startPos, endPos){ 
  var shutter = document.getElementById(idShutter);   
  if (shutter.tmr!=null)
    window.clearInterval(shutter.tmr);
  shutter.tmr = window.setInterval("_DropUpShutter('"+shutter.id+"')", 10);
}
 
function _DropUpShutter(idShutter){
  var shutter = document.getElementById(idShutter);
  shutter.z -= 3;
  var factor = Number((1/shutter.lengthPos)*shutter.z);
  SetAlpha(shutter,factor);          
  shutter.style.top = (shutter.startPos+(shutter.z))+"px";
  if (shutter.z<=0) { 
    window.clearInterval(shutter.tmr);
    shutter.tmr = null;
    shutter.style.top = shutter.startPos+"px";
    shutter.style.display = "none";
  }
}








function _FlashElement(idElement){
    var element = document.getElementById(idElement);
    if (element == null) return;
    element.z += 1;
    SetAlpha( element, 1- (1/16*element.z) );     
    if (element.z>=16) { 
      window.clearInterval(element.tmr);
      element.tmr = null;
      element.id = null;
      element.style.display = "none";
    }
}
 
function FlashElement(element){   
   if (element.tmr!=null)
     window.clearInterval(element.tmr);           
     
   var cadre = document.createElement("div");
   cadre.style.position = "absolute";
   cadre.style.left = "0px";
   cadre.style.right = "0px";
   cadre.style.top = "0px";
   cadre.style.bottom = "0px";
 
   cadre.style.backgroundColor = "lemonchiffon";
   cadre.id = element.id+"_cadre";
   
   cadre.style.width = element.offsetWidth+"px";
   cadre.style.height = element.offsetHeight+"px";
 
   element.appendChild(cadre);
    
   cadre.z = 0;
   cadre.tmr = window.setInterval("_FlashElement('"+cadre.id+"')", 20);
}








function OpenAlphaBlendElement(element){ 
  
  if (IsIe()){
    element.style.filter="blendTrans(duration=0.3)";
    element.filters.blendTrans.apply();
    element.style.display = "block";   
    element.style.visibility = "visible";   
    element.filters.blendTrans.play();
  } else {    
      if (element.style.display=="block") return;                    
      if (element.tmr!=null)
        window.clearInterval(element.tmr);
      if (element.z==null) 
        element.z = 0;  
      SetAlpha(element,0); 
      element.style.display = "block";     
      element.tmr = window.setInterval("_OpenAlphaBlendElement('"+element.id+"')", 10);
  }
}


function _OpenAlphaBlendElement(idElement){
  var element = document.getElementById(idElement);
  element.z += 0.1;    
  if (element.z>1) element.z = 1;
  SetAlpha(element,element.z); 
  if (element.z>=1) { 
    window.clearInterval(element.tmr);
    element.tmr = null;
  }
}


function CloseAlphaBlendElement(element){  
  
  if (element.style.display=="none") return; 
  if (IsIe()){             
    element.style.filter=""; 
    element.style.filter="blendTrans(duration=0.3)";
    element.filters.blendTrans.apply();
    element.style.visibility = "hidden";   
    element.filters.blendTrans.play();
  } else {
      if (element.tmr!=null)
        window.clearInterval(element.tmr);
      if (element.z==null) 
        element.z = 1;    
      element.style.display = "block";    
      element.tmr = window.setInterval("_CloseAlphaBlendElement('"+element.id+"')", 10);
  }
}
 
 
function _CloseAlphaBlendElement(idElement){
  var element = document.getElementById(idElement);
  element.z -= 0.1;    
  if (element.z<0) element.z = 0;
  SetAlpha(element,element.z); 
  if (element.z<=0) { 
    window.clearInterval(element.tmr);
    element.tmr = null;
    element.style.display = "none";
  }
}










function AddListElement(idElement){
  var element = document.getElementById(idElement);
  element.style.visibility="hidden";
  element.style.position = "absolute";
  element.style.display="block";
  
  var height = element.offsetHeight;    
  element.style.height = "0px";
  element.style.position = "relative";
  if (element.tmr!=null)
    window.clearInterval(element.tmr);
  if (element.z==null) 
    element.z = 0;  
  element.tmr = window.setInterval("_AddListElement('"+element.id+"',"+height+")", 10);
}


function _AddListElement(idElement, finalHeight){
  var element = document.getElementById(idElement);
  element.z += 3;    
  if (element.z>finalHeight) element.z = finalHeight;
  element.style.height = element.z+"px";
  if (element.z>=finalHeight) { 
    window.clearInterval(element.tmr);
    element.tmr = null;
    element.style.visibility="inherit";
    FlashElement(element);
  }
}






function RemoveListElement(idElement){
  var element = document.getElementById(idElement);
  if (element!=null){
      element.style.visibility = "hidden";
      if (element.tmr!=null)
        window.clearInterval(element.tmr);
      if (element.z==null) 
        element.z = element.offsetHeight-3;  
      element.tmr = window.setInterval("_RemoveListElement('"+element.id+"')", 10);
  }
}

function _RemoveListElement(idElement){
  var element = document.getElementById(idElement);
  element.z -= 3;    
  if (element.z<0) element.z = 0;
  element.style.height = element.z+"px";
  if (element.z<=0) { 
    window.clearInterval(element.tmr);
    element.tmr = null;
    element.style.display="none";
  }
}