
var timeoutcontent;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function menu
// Object : http request to display the required url
// FASTBOIL                     1.0         08/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function menu(url,innerhtml) {
  if (document.getElementById('dsdlf')) {
    clearTimeout(timeoutcontent);

    var xReq=getXmlHttpRequest();
    var obj=document.getElementById('dsdlf');
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,'dsdlf');};
    xReq.send(null);

    var xReqm=getXmlHttpRequest();
    var obj=document.getElementById('dsdlfm');
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReqm.open("GET",url.replace('dsdlf','dsdlfm'),true);
    xReqm.onreadystatechange=function(){fbEventGetUrlDiv(xReqm,'dsdlfm');};
    xReqm.send(null);
  }
}

// SlideShow - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var speed=4000;
var t;
var p;
var preLoad = new Array();
var pic = new Array()
var url = new Array();

var id1=0;
var id2=1;
var id3=2;

function initSlideShow() {

  var cpt=0;
  for(var i=0; i<arguments.length; i+=2) {
    pic[cpt]=arguments[i];
    url[cpt]=arguments[i+1];
    cpt++;
  }

  p=pic.length;
  if (p>0) {
    for (i=0;i<p;i++){
      preLoad[i] = new Image();
      preLoad[i].src = pic[i];
      if (i<3) {
        document.getElementById("topbarimg"+(i+1)).src = preLoad[i].src;
        document.getElementById("topbarurl"+(i+1)).href = url[i];
      }
    }
    t=setTimeout('runSlideShow(1)',speed);
  }
}

function runSlideShow(cId){
   var id=0;
   var cpt=0;
   var idOK=0;
   while((cpt<=10)&&(idOK==0)) {
      cpt++;
      id = Math.round(p*Math.random());
      if (id >= p) id=p-1; else if (p<0) id=0;
      if ((id!=id1)&&(id!=id2)&&(id!=id3)) idOK=1;
   }

   if (cId==1) {
      if (idOK==1){
         document.getElementById("topbarimg1").src = preLoad[id].src;
         document.getElementById("topbarurl1").href = url[id];
         id1=id;
      }
      cId=2;
   }
   else if (cId==2) {
      if (idOK==1){
         document.getElementById("topbarimg2").src = preLoad[id].src;
         document.getElementById("topbarurl2").href = url[id];
         id2=id;
      }
      cId=3;
   }
   else {
      if (idOK==1){
         document.getElementById("topbarimg3").src = preLoad[id].src;
         document.getElementById("topbarurl3").href = url[id];
         id3=id;
      }
      cId=1;
   }
   t=setTimeout('runSlideShow('+cId+')',speed);
}

// Slider text - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var slider = new Array();
          
// scroll the element vertically based on its width and the slider maximum value
function scrollVertical(value, element, nom) {
  element.scrollTop = Math.round(value*slider[nom].scrollMax);
}

function monter(nom) {
  slider[nom].setValueBy(-40/slider[nom].scrollMax);
}
          
function descendre(nom) {
  slider[nom].setValueBy(40/slider[nom].scrollMax);
}
          
// mouse wheel code from http://adomas.org/javascript-mouse-wheel/
function handle(delta,nom) {
  slider[nom].setValueBy(-(delta*60)/slider[nom].scrollMax);
}
      
function initSlider0(adiv) {
  var max = $(adiv+'_main').scrollHeight-$(adiv+'_main').offsetHeight;
  s = new Control.Slider('contentText_slider_ascenseur', 'contentText_slider_chemin', {
    axis: 'vertical',
    onSlide: function(v) { scrollVertical(v, $(adiv+'_main'), 'contentText');  },
    onChange: function(v) { scrollVertical(v, $(adiv+'_main'), 'contentText'); }
  });
  s.scrollMax = max;
  slider['contentText']=s;
}
      
function wheel0(event) { 
  var delta = 0;
  if (!event) /* For IE. */
    event = window.event;
  if (event.wheelDelta) { /* IE/Opera. */
    delta = event.wheelDelta/120;
  /** In Opera 9, delta differs in sign as compared to IE. */
  if (window.opera)
    delta = -delta;
  }
  else if (event.detail) { /** Mozilla case. */
    /** In Mozilla, sign of delta is different than in IE.
      * Also, delta is multiple of 3. */
    delta = -event.detail/3;
  }
      
/** If delta is nonzero, handle it.
  * Basically, delta is now positive if wheel was scrolled up,
  * and negative, if wheel was scrolled down. */
  if (delta)
    handle(delta,'contentText');
      
/** Prevent default actions caused by mouse wheel.
  * That might be ugly, but we handle scrolls somehow
  * anyway, so don't bother here..
  */
  if (event.preventDefault)
    event.preventDefault();
              
  event.returnValue = false;
}
          
function initMouseWheel0(adiv) {
  // mozilla
  Event.observe(adiv+'_main', 'DOMMouseScroll', wheel0);
  // IE/Opera
  Event.observe(adiv+'_main', 'mousewheel', wheel0);
}
      
function initAscenseur(adiv) {
  if ($(adiv+'_main').scrollHeight > $(adiv+'_main').offsetHeight) {
    $(adiv+'_slider').style.display='block';
    divTexte = $(adiv+'_main');
    largeur = divTexte.offsetWidth;
    largeur2 = largeur-10;
    divTexte.style.width = largeur2+'px';
    initSlider0(adiv);
    initMouseWheel0(adiv);
  }
}

// Ajax - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function fbGetUrlDiv(id,url,innerhtml) {
  if (document.getElementById(id)) {
    var xReq=getXmlHttpRequest();
    var obj=document.getElementById(id);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);
    xReq.open("GET",url,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDiv(xRequest,anId) {
  if (xRequest.readyState==4) {
    document.getElementById(anId).innerHTML=xRequest.responseText;

    var c = document.getElementsByTagName("body")[0].getElementsByTagName("*");
    for (var i=0;i<c.length;i++){
      if ((c[i].nodeName=='DIV') && (c[i].id.substring(0,9)=='slideshow')){
        var reg=new RegExp("[-]+", "g");
        var arr=c[i].id.split(reg);
        if (arr.length==4) scriptSlideShow(arr[1],arr[2],arr[3]);
      }
    }
  }
}

function fbShowWaiting(obj,innerhtml) {
    obj.innerHTML=innerhtml;
}

function getXmlHttpRequest() {
    if (window.XMLHttpRequest) // Firefox
    {
       return(new XMLHttpRequest());
    }
    else if (window.ActiveXObject) // Internet Explorer
    {
        try
        {
            return(new ActiveXObject("Msxml2.XMLHTTP"));
        } 
        catch (e)
        {
            try
            {
                return(new ActiveXObject("Microsoft.XMLHTTP"));
            }
            catch (e)
            {
                alert("Your browser does not support XMLHTTPRequest...");
            }
        }
    }
    else
    { // XMLHttpRequest non supporté par le navigateur
       alert("Your browser does not support XMLHTTPRequest...");
    }
}

function fbSendAjaxFormTargetDiv(idForm,baseurl,targetId,innerhtml) {

    var xReq=getXmlHttpRequest();
    var i;
    var url="";
    var myForm=document.getElementById(idForm);

    if (myForm) {
        var first=true;
        for(i=0;i<myForm.elements.length;i++) {
            var elmt=myForm.elements[i];
            var type=elmt.nodeName.toLowerCase();
            var ok=true;

            if (type=="input") {
                switch (elmt.type.toLowerCase()) {
                case "radio":
                case "checkbox":
                    if (!elmt.checked) ok=false;
                    break;

                case "submit":
                case "image":
                    ok=false;
                    break;
                }
            }
            else if ((type!="select") && (type!="textarea")) ok=false;
            if (ok) {
                if (first) first=false;
                else url+="&";
                url+=elmt.name+"="+elmt.value.replace(/%/g,"%25").replace(/&/g,"%26").replace(/=/g,"%3D").replace(/ /g,"%20");
            }
        }
    }

    var obj=document.getElementById(targetId);
    if (innerhtml != '') fbShowWaiting(obj,innerhtml);

    xReq.open("POST",baseurl,true);
    xReq.onreadystatechange=function(){fbEventGetUrlDiv(xReq,targetId);};
    xReq.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
    xReq.send(url);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function scriptSlideShow
// Object : wrtiting slideshow
// FASTBOIL                     1.0         01/02/2009
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function scriptSlideShow(id,ssWidth,ssHeight) {
  var hasProductInstall = DetectFlashVer(6, 0, 65);
  var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
  if ( hasProductInstall && !hasRequestedVersion ) {
    var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
    var MMredirectURL = window.location;
      document.title = document.title.slice(0, 47) + " - Flash Player Installation";
      var MMdoctitle = document.title;
    AC_FL_RunContent(
      "src", "playerProductInstall",
      "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
      "width", ssWidth,
      "height", ssHeight,
      "align", "middle",
      "id", "FlexSlideShow",
      "quality", "high",
      "name", "FlexSlideShow",
      "allowScriptAccess","sameDomain",
      "type", "application/x-shockwave-flash",
      "pluginspage", "http://www.adobe.com/go/getflashplayer",
      "id","slideshow"+id,
      "wmode", "transparent"
    );
  } else if (hasRequestedVersion) {
    AC_FL_RunContent(
        "src", "FlexSlideShow",
        "width", ssWidth,
        "height", ssHeight,
        "align", "middle",
        "id", "FlexSlideShow",
        "quality", "high",
        "name", "FlexSlideShow",
        "allowScriptAccess","sameDomain",
        "type", "application/x-shockwave-flash",
        "pluginspage", "http://www.adobe.com/go/getflashplayer",
//        "FlashVars","dataprovider=default.php?fct=slideshow-"+id+"-"+ssWidth+"-"+ssHeight,
        "FlashVars","dataprovider=slideshow"+id+"-"+ssWidth+"-"+ssHeight,
        "id","slideshow"+id,
        "wmode", "transparent"
    );
  } else {
    var alternateContent = 'This content requires the Adobe Flash Player. '
     + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
  //document.write(alternateContent);
  document.getElementById("slideshow"+id).innerHTML = alternateContent;
  }
}


