
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
// gabrieletgabriel.js
// Javascript functions for Gabriel&Gabriel website
//
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var minFullHeight = 500;
var minContentHeight = 300;
var delayStart = 1000;

var stepHide = 20;
var stepShow = 10;
var delay = 2;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

var currentcontent = -1;
var timeoutHide = Array();
var timeoutShow = Array();
var fullHeight;

window.onresize = function(){setLayout(-1);};

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setLayout(idPage) {
  if (self.innerHeight) // all except Explorer
    h = self.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
    h = document.documentElement.clientHeight;
  else if (document.body) // other Explorers
    h = document.body.clientHeight;

  fullHeight = h;
  if (fullHeight<minFullHeight) fullHeight = minFullHeight;
  setPostHeight();

  if (idPage>=0) {
    currentcontent = idPage;
    timeoutShow[idPage] = setTimeout('showcontent('+idPage+')',delayStart);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function setPostHeight() {
  postHeight = fullHeight;
  if (document.getElementById('header_o')) postHeight-=document.getElementById('header_o').offsetHeight;
  if (document.getElementById('content_o')) postHeight-=document.getElementById('content_o').offsetHeight;
  if (document.getElementById('footer_o')) postHeight-=document.getElementById('footer_o').offsetHeight;
  if (postHeight<0) postHeight = 0;
  document.getElementById('contentpost').style.height = postHeight+'px';
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function showcontent(idPage) {
  if (document.getElementById('content_o_'+idPage) && document.getElementById('content_i_'+idPage)) {
    rHeight = document.getElementById('content_i_'+idPage).offsetHeight;
    cHeight = document.getElementById('content_o_'+idPage).offsetHeight;
    if (rHeight<minContentHeight) rHeight=minContentHeight;
    //document.getElementById('content_o_'+idPage).style.height = rHeight+'px';
    currentcontent = idPage;
//hidediv('content_i_'+idPage);
//alert('showcontent: '+idPage+" - "+rHeight+" - "+cHeight);
    slideshowcontent(idPage,rHeight,cHeight);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function slideshowcontent(idPage,rHeight,cHeight) {
  cHeight+=stepShow;
  if (cHeight>=rHeight) {
    document.getElementById('content_o_'+idPage).style.height = rHeight+'px';
//showdiv('content_i_'+idPage);
//alert('show '+idPage);
    setPostHeight();
  }
  else {
    document.getElementById('content_o_'+idPage).style.height = cHeight+'px';
    setPostHeight();
    timeoutShow[idPage] = setTimeout('slideshowcontent('+idPage+','+rHeight+','+cHeight+')',delay);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function hidecontent(idPage) {
  if (document.getElementById('content_o_'+idPage)) {
    //document.getElementById('content_o_'+idPage).style.height = '0px';
    cHeight = document.getElementById('content_o_'+idPage).offsetHeight;
    if (cHeight>0) {
      currentcontent = -1;
//hidediv('content_i_'+idPage);
//alert('hide '+idPage);
      slidehidecontent(idPage,cHeight);
    }
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function slidehidecontent(idPage,cHeight) {
  cHeight-=stepHide;
  if (cHeight<=0) {
    document.getElementById('content_o_'+idPage).style.height = '0px';
    setPostHeight();
  }
  else {
    document.getElementById('content_o_'+idPage).style.height = cHeight+'px';
    setPostHeight();
    timeoutHide[idPage] = setTimeout('slidehidecontent('+idPage+','+cHeight+')',delay);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function menu(idPage) {
  clearTimeout(timeoutHide[idPage]);
  clearTimeout(timeoutShow[idPage]);
  clearTimeout(timeoutShow[currentcontent]);
  if (currentcontent==idPage)
    hidecontent(idPage);
  else {
    hidecontent(currentcontent);
    showcontent(idPage);
    if(pageTracker && arguments[arguments.length-1]!="") pageTracker._trackPageview(arguments[arguments.length-1]);
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function inArray(needle,arr) {
  for (key in arr) {
    if (arr[key] == needle) return true;
  }
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// function
// Object :
// FASTBOIL                     1.0         23/04/2010
// http://www.fastboil.net
// hot@fastboil.net
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function submenu(idPageTop,url,innerhtml) {
  fbGetUrlDivSlide(idPageTop,'content_i_'+idPageTop,url,innerhtml);
  if (currentcontent!=idPageTop) menu(idPageTop);
  if(pageTracker) pageTracker._trackPageview(url);
}

//============================================================================//
//                            Ajax                                            //
//============================================================================//

function fbGetUrlDivSlide(idPage,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(){fbEventGetUrlDivSlide(idPage,xReq,id);};
    xReq.send(null);
  }
}

function fbEventGetUrlDivSlide(idPage,xRequest,anId) {
    if (xRequest.readyState==4) {
        document.getElementById(anId).innerHTML=xRequest.responseText;
        showcontent(idPage);
    }
}

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;
    }
}

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 hidediv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
      if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'hidden';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layer[myId].visibility = 'hidden';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'hidden';
       }
    }
}

function showdiv(myId) {
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(myId)) document.getElementById(myId).style.visibility = 'visible';
    }
    else {
        if (document.layers) { // Netscape 4
          if (document.layer[myId]) document.layers[myId].visibility = 'visible';
        }
        else { // IE 4
          if (document.all[myId]) document.all[myId].style.visibility = 'visible';
        }
    }
}


