/*

See the FAQtestSlideTime function for correction of slide speed in different browsers.

*/

//Select some default values. The actual string values are retrieved from Eprise input, delivered in a seperate
//javascript tag on the page using this loaded javascript.
if (gsFAQSlideMode == '') {
  gsFAQSlideMode = 'time';
  gsFAQSlideSpeed = 'normal';
}

var gbFAQConstSlideTime = false;
if (gsFAQSlideMode.toLowerCase() == 'time') {
  gbFAQConstSlideTime = true;
}

var giFAQSlideTimeFAST = 200; // Slide time in ms, fast
var giFAQSlideTimeNORMAL = 400; // Slide time in ms, normal
var giFAQSlideTimeSLOW = 600; // Slide time in ms, slow
var giFAQSlideTime;
eval('giFAQSlideTime = giFAQSlideTime' + gsFAQSlideSpeed.toUpperCase()); //Slide time in ms.
//alert(eval('giFAQSlideTime' + gsFAQSlideSpeed.toUpperCase()));
//alert('giFAQSlideTime' + gsFAQSlideSpeed.toUpperCase());

var giFAQSlideSpeedFAST = 800; //px per second, Fast
var giFAQSlideSpeedNORMAL = 400; //px per second, Normal
var giFAQSlideSpeedSLOW = 250; //px per second, slow
var giFAQConstSlideSpeed;
eval('giFAQConstSlideSpeed = giFAQSlideSpeed' + gsFAQSlideSpeed.toUpperCase()); //Slide speed px/ms
var gflFAQConstSlideAmount; //The calculated slide in px per slide to achieve the desired speed in px/sec

var gflFAQMaxSlideAmount; //To prevent extreme slide amounts and thus abrupt action, we calculate an accepted max. amount per slide


var giFAQMsPerSlide = 1; //Calculated time spent per slide operation; will be set to some other, probably higher, value when testing.

var giFAQslideInterval = 1; //Initial value that may be corrected after testing
var gsFAQGrpGroupID = '';
var gsFAQGrpQuestionID = '';
var gsFAQGrpGroupIDprev = '';
var gsFAQGrpQuestionIDprev = '';

var gbFAQGrpSlideOpen = false;
var gbFAQGrpSlideClose = false;
var gbFAQQuestionSlideOpen = false;
var gbFAQQuestionSlideClose = false;
var gbFAQSoftScrollOn = false;

var gtmFAQGroupSlideOpen, gtmFAQGroupSlideClose;       //For timers
var gtmFAQQuestionSlideOpen, gtmFAQQuestionSlideClose; //Do.
var gtmFAQGotoAnswer; //timer for inter answer links focus-the-other-answer functionallity
var giFAQGroupSlideOpen, giFAQGroupSlideClose;       //For slide amounts
var giFAQQuestionSlideOpen, giFAQQuestionSlideClose; //Do.
var giFAQGroupOpenCalcHeight = 0, giFAQGroupCloseCalcHeight = 0;       //For calculated heights
var giFAQQuestionOpenCalcHeight = 0, giFAQQuestionCloseCalcHeight = 0; //Do.

var giFAQTestSlideHeight = 15;
var gbFAQslideTest = true; //Initial value that prevents using the FAQ until the slide speed test is finished.
var gtmFAQtestSlide, gdtFAQSlideBegin, gdtFAQSlideEnd, gdtFAQslideTime;



/*
The FAQTestSlideTime, using FAQTestSlideAction, measures the fastest slide time, milliseconds spend for one
slide, that can be achieved on the site with the particular PC. This result is used for calculating slide
step length in px necessary to achieve the desired slide time or slide speed, always using a time interval
less than the minimum measured.
*/
function FAQtestSlideTime() {
var es;
  es = document.getElementById('faqtestslidediv');
  es.style.display = 'block';
  es.style.height = giFAQTestSlideHeight.toString() + 'px';
  gdtFAQSlideBegin = new Date();
  gtmFAQtestSlide = setInterval('FAQTestSlideAction()', giFAQslideInterval);
}

function FAQTestSlideAction() {
var es, h;
  es = document.getElementById('faqtestslidediv');
  h = es.offsetHeight - 1;
  if (h <= 0) {
    clearInterval(gtmFAQtestSlide);
    es.style.display = 'none';
    gdtFAQSlideEnd = new Date();
    gdtFAQslideTime = new Date(gdtFAQSlideEnd - gdtFAQSlideBegin);
    giFAQMsPerSlide = ((gdtFAQslideTime.getSeconds() * 1000) + gdtFAQslideTime.getMilliseconds()) / giFAQTestSlideHeight;
    //Here we adjust so sliding times is actually (almost) correct.
    //We have EI as reference and we check currently for use of FF as that exhibits quite deviating behaviour, speed-wise, during
    //speed test and actual slide.
    giFAQMsPerSlide = giFAQMsPerSlide * 0.5; //Adjust with a fixed value as I don't seem to be able to get the speed calculation right.
    switch (BrowserDetect.browser) { //The calculation is for IE and we correct for variations with other browsers
    case 'Firefox':
      giFAQMsPerSlide = giFAQMsPerSlide * 2; //The measurement shows that it is fast, but actually it's slower then IE(7).
      break;
    case 'Chrome':
      giFAQMsPerSlide = giFAQMsPerSlide * 2; //Should be much like FF
      break;
    }
    giFAQslideInterval = Math.max(1, (0.1 * giFAQMsPerSlide)); //Set interval to some smaller value for ensured max speed.
    gflFAQConstSlideAmount = (giFAQConstSlideSpeed / 1000) * giFAQMsPerSlide; // Constant slide amount px/slide
    gflFAQMaxSlideAmount = 3 * gflFAQConstSlideAmount;
    if (!gbFAQConstSlideTime) {
      giFAQGroupSlideOpen = gflFAQConstSlideAmount;
      giFAQGroupSlideClose = 2 * gflFAQConstSlideAmount;
      giFAQQuestionSlideOpen = gflFAQConstSlideAmount;
      giFAQQuestionSlideClose = 2 * gflFAQConstSlideAmount;
    }
    gbFAQslideTest = false; //Finished testing slide speed
    FAQgotoURLQA();
  }
  else {
    es.style.height = h.toString() + 'px';
  }
}


function FAQMaxSlideAmount(iH) {
  return Math.min(gflFAQMaxSlideAmount,(iH * giFAQMsPerSlide) / giFAQSlideTime);
}


function FAQSlidingOn () {
  //return (gbFAQGrpSlideOpen || gbFAQGrpSlideClose || gbFAQQuestionSlideOpen || gbFAQQuestionSlideClose);
  return (gbFAQGrpSlideOpen || gbFAQGrpSlideClose || gbFAQQuestionSlideOpen || gbFAQQuestionSlideClose || gbFAQSoftScrollOn); //Added check for window soft scroll
}


function FAQdoFunction(f, sTimerID){
  if (gsFAQSlideMode != 'instant') {
    switch (sTimerID) {
    case 'go':
      gtmFAQGroupSlideOpen = setInterval(f, giFAQslideInterval);
      break;
    case 'gc':
      gtmFAQGroupSlideClose = setInterval(f, giFAQslideInterval);
      break;
    case 'qo':
      gtmFAQQuestionSlideOpen = setInterval(f, giFAQslideInterval);
      break;
    case 'qc':
      gtmFAQQuestionSlideClose = setInterval(f, giFAQslideInterval);
    }
  }
  else {
    eval(f);
  }
}


function FAQGroupSlide(gid) {
  if (gbFAQslideTest || FAQSlidingOn()) { //Do nothing if we are already sliding
    return;
  }
  if (gsFAQGrpGroupID != gid) { //Open new group and close any open one
    if (gsFAQGrpGroupID != '') { //Is there in fact an open group
      if (gsFAQGrpQuestionID != '') { //Is there an open question in the open group, then close it
        if (gsFAQGrpGroupID != '' && gsFAQGrpQuestionID != '') { //Save ID of last open answer
          gsFAQGrpGroupIDprev = gsFAQGrpGroupID;
          gsFAQGrpQuestionIDprev = gsFAQGrpQuestionID;
        }
        gbFAQQuestionSlideClose = true;
        FAQdoFunction('FAQQuestionClose(' + gsFAQGrpGroupID + ', ' + gsFAQGrpQuestionID + ')', 'qc');
        gsFAQGrpQuestionID = ''; //Reset open question value
      }
      gbFAQGrpSlideClose = true;
      FAQdoFunction('FAQGroupClose(' + gsFAQGrpGroupID + ')', 'gc');
      gsFAQGrpGroupID = ''; //reset open group value
    }
    //Set instant changes
    gsFAQGrpGroupID = gid; //Save the new group
    gbFAQGrpSlideOpen = true;
    FAQdoFunction('FAQGroupOpen(' + gsFAQGrpGroupID + ')', 'go')
  }
  else { //Just close the currently open group
    if (gsFAQGrpGroupID != '' && gsFAQGrpQuestionID != '') { //Save ID of last open answer
      gsFAQGrpGroupIDprev = gsFAQGrpGroupID;
      gsFAQGrpQuestionIDprev = gsFAQGrpQuestionID;
    }
    if (gsFAQGrpQuestionID != '') { //Close any open question as well
      gbFAQQuestionSlideClose = true;
      FAQdoFunction('FAQQuestionClose(' + gsFAQGrpGroupID + ', ' + gsFAQGrpQuestionID + ')', 'qc');
      gsFAQGrpQuestionID = ''; //Reset open question value
    }
    gbFAQGrpSlideClose = true;
    FAQdoFunction('FAQGroupClose(' + gsFAQGrpGroupID + ')', 'gc');
    gsFAQGrpGroupID = ''; //reset open group value
  }
}


function FAQGroupOpen(gid) {
var es, ec, h;
  //prepare slide div elements
  es = document.getElementById('faq_' + gid + '_0_s');
  //Begin slide (if possible. depending on browser (and domain - FF does not
  //handle the slide on oticon.com but does on the test files))
  if (gsFAQSlideMode != 'instant') {
    ec = document.getElementById('faq_' + gid + '_0_c');
    if ((es.offsetHeight < ec.offsetHeight) || (es.offsetHeight == 0 || gbFAQGrpSlideOpen)) {
      if (es.offsetHeight == 0) { //Establish the first peep
        FAQbeforeGroupOpen(gid);
        es.style.display = 'block';
        es.style.height = '1px';
        if (gbFAQConstSlideTime) {
          giFAQGroupSlideOpen = FAQMaxSlideAmount(ec.offsetHeight);
        }
        giFAQGroupOpenCalcHeight = 1;
      }
      else {
        h = giFAQGroupOpenCalcHeight + giFAQGroupSlideOpen;
        if (ec.offsetHeight <= h) {
          clearInterval(gtmFAQGroupSlideOpen);
          es.style.height = 'auto';
          gbFAQGrpSlideOpen = false;
        }
        else {
        /* Simultaneous question slide open currently blocked *
          if (gbFAQConstSlideTime) { //We need to calculate concurrently in case a question inside the group
                                     //is opened while sliding (possible at slow speeds)
            giFAQGroupSlideOpen = (ec.offsetHeight * giFAQMsPerSlide) / giFAQSlideTime;
          }
        /**/
          giFAQGroupOpenCalcHeight = h;
          es.style.height = Math.round(h).toString() + 'px';
        }
      }
    }
  }
  else {
    FAQbeforeGroupOpen(gid);
    es.style.height = 'auto'; ///////////////////////
    es.style.display = 'block';
    gbFAQGrpSlideOpen = false;
  }
}


function FAQGroupClose(gid) {
var es, ec, h;
  es = document.getElementById('faq_' + gid + '_0_s');
  if (gsFAQSlideMode != 'instant') {
    ec = document.getElementById('faq_' + gid + '_0_c');
    if (giFAQGroupCloseCalcHeight == 0) { // We only calculate the first time as we otherwise slow down if
                                          // a large question has been open and is now concurrently closing.
                                          // This can happen when changing groups.
      if (gbFAQConstSlideTime) {
        giFAQGroupSlideClose = FAQMaxSlideAmount(ec.offsetHeight);
      }
      giFAQGroupCloseCalcHeight = ec.offsetHeight;
    }
    h = giFAQGroupCloseCalcHeight - giFAQGroupSlideClose;
    if (h <= 0) {
      clearInterval(gtmFAQGroupSlideClose);
      es.style.height = 0;
      es.style.display = 'none';
      giFAQGroupCloseCalcHeight = 0;
      FAQafterGroupClose(gid);
      gbFAQGrpSlideClose = false;
    }
    else {
      giFAQGroupCloseCalcHeight = h;
      h = Math.max(0, Math.round(h));
      es.style.height = h.toString() + 'px';
      if (h == 0) {
        giFAQGroupCloseCalcHeight = -1; // Set to a value that will stop the loop and do NOT trigger a new loop
        es.style.display = 'none'; // If we do not do this, a height set to 0px may trigger stange visual behaviour.
      }
    }
  }
  else {
    es.style.height = 'auto';
    es.style.display = 'none';
    FAQafterGroupClose(gid);
    gbFAQGrpSlideClose = false;
  }
}


function FAQQuestionSlide(gid, qid) {
  if (FAQSlidingOn()) { //Do nothing if we are already sliding
    return;
  }
  if (gsFAQGrpQuestionID != qid) { //Is another question possibly open?
    if (gsFAQGrpGroupID != '' && gsFAQGrpQuestionID != '') { //Save ID of last open answer
      gsFAQGrpGroupIDprev = gsFAQGrpGroupID;
      gsFAQGrpQuestionIDprev = gsFAQGrpQuestionID;
    }
    if (gsFAQGrpQuestionID != '') { //If a question actually is open...
      gbFAQQuestionSlideClose = true;
      FAQdoFunction('FAQQuestionClose(' + gid + ', ' + gsFAQGrpQuestionID + ')', 'qc');
    }
    gsFAQGrpQuestionID = qid; //Save new open question to be; as we do this here and now, there is no reason to clear it beforehand.
    gbFAQQuestionSlideOpen = true;
    FAQdoFunction('FAQQuestionOpen(' + gid + ', ' + qid + ')', 'qo');
  }
  else {
    if (gsFAQGrpGroupIDprev != '' && gsFAQGrpQuestionIDprev != '') { //Save ID of last open answer
      gsFAQGrpGroupIDprev = gid;
      gsFAQGrpQuestionIDprev = qid;
    }
    gbFAQQuestionSlideClose = true;
    FAQdoFunction('FAQQuestionClose(' + gid + ', ' + qid + ')', 'qc');
    gsFAQGrpQuestionID = ''; //Reset open question value
  }
}


function FAQQuestionOpen(gid, qid) {
var es, ec, h;
  es = document.getElementById('faq_' + gid + '_' + qid + '_s'); //Get the sliding element
  if (gsFAQSlideMode != 'instant') {
    ec = document.getElementById('faq_' + gid + '_' + qid + '_c'); //Get the content element
    if ((es.offsetHeight < ec.offsetHeight) || (es.offsetHeight == 0 || gbFAQQuestionSlideOpen)) {
      if (es.offsetHeight == 0) {
        FAQbeforeQuestionOpen(gid, qid); //Set instant elements
        es.style.height = '1px'; //As soon one tiny bit is visible we can measure the internal height
        es.style.display = 'block';
        if (gbFAQConstSlideTime) {
          giFAQQuestionSlideOpen = FAQMaxSlideAmount(ec.offsetHeight);
        }
        giFAQQuestionOpenCalcHeight = 1;
      }
      else {
        h = giFAQQuestionOpenCalcHeight + giFAQQuestionSlideOpen;
        if (ec.offsetHeight <= h) {
          clearInterval(gtmFAQQuestionSlideOpen);
          es.style.height = 'auto';
          gbFAQQuestionSlideOpen = false;
        }
        else {
          giFAQQuestionOpenCalcHeight = h;
          h =  Math.round(h);
          es.style.height = h.toString() + 'px';
        }
      }
    }
  }
  else {
    FAQbeforeQuestionOpen(gid, qid); //Set instant elements
    es.style.height = 'auto'; //////////////////////////
    es.style.display = 'block';
    gbFAQQuestionSlideOpen = false;
  }
}


function FAQQuestionClose(gid, qid) {
var es, ec, h;
  if (qid != '') {
    es = document.getElementById('faq_' + gid + '_' + qid + '_s'); //Get the sliding element
    if (gsFAQSlideMode != 'instant') {
      ec = document.getElementById('faq_' + gid + '_' + qid + '_c'); //Get the content element
      if (giFAQQuestionCloseCalcHeight == 0) { // We only calculate the first time as we otherwise slow down if
                                               // a large question has been open and is now concurrently closing.
        if (gbFAQConstSlideTime) {
          giFAQQuestionSlideClose = FAQMaxSlideAmount(ec.offsetHeight);
        }
        giFAQQuestionCloseCalcHeight = ec.offsetHeight;
      }
      h = giFAQQuestionCloseCalcHeight - giFAQQuestionSlideClose;
      if (h <= 0) {
        clearInterval(gtmFAQQuestionSlideClose);
        es.style.height = 0;
        es.style.display = 'none';
        giFAQQuestionCloseCalcHeight = 0;
        FAQafterQuestionClose(gid, qid)
        gbFAQQuestionSlideClose = false;
      }
      else {
        giFAQQuestionCloseCalcHeight = h;
        h = Math.max(0, Math.round(h));
        es.style.height = h.toString() + 'px';
        if (h == 0) {
          giFAQQuestionCloseCalcHeight = -1; // Set to a value that will stop the loop and do NOT trigger a new loop.
          es.style.display = 'none'; // If we do not do this, a height set to 0px may trigger stange visual behaviour.
        }
      }
    }
    else {
      es.style.height = 'auto'; //////////////////////////
      es.style.display = 'none';
      FAQafterQuestionClose(gid, qid)
      gbFAQQuestionSlideClose = false;
    }
  }
}


function FAQbeforeGroupOpen(gid) {
var ei;
  ei = document.getElementById('faq_' + gid + '_0_i');
  ei.src = gsFAQImageFolder+ 'arrow_down_l1_848b95.gif';
  ei = document.getElementById('faq_' + gid + '_0_g');
  ei.className = 'FAQtopicsGroupSel';
}

function FAQafterGroupClose(gid) {
var ei;
  ei = document.getElementById('faq_' + gid + '_0_i');
  ei.src = gsFAQImageFolder + 'arrow_right_l1_989ea6.gif';
  ei = document.getElementById('faq_' + gid + '_0_g');
  ei.className = 'FAQtopicsGroup';
}

function FAQbeforeQuestionOpen(gid, qid) {
var ei;
  ei = document.getElementById('faq_' + gid + '_' + qid + '_i');
  ei.src = gsFAQImageFolder + 'arrow_down_l3_6aafc7.gif';
  ei = document.getElementById('faq_' + gid + '_' + qid + '_t');
  ei.className = 'FAQQuestionSel';
}

function FAQafterQuestionClose(gid, qid) {
var ei;
  ei = document.getElementById('faq_' + gid + '_' + qid + '_i');
  ei.src = gsFAQImageFolder + 'arrow_right_l2_848b95.gif';
  ei = document.getElementById('faq_' + gid + '_' + qid + '_t');
  ei.className = 'FAQQuestion';
}


function FAQHighLow(e, mode) {
  if (mode == 1) { //Over
    e.style.color = '#FFFFFF';
  }
  else { //Out
    e.style.color='#E8E8E8';
  }
}


function FAQSlide(gid, qid) { //Used for sliding from "outside" e.g. a search function. You supply the group and question ID
                              //and the necessary slide in and slide out is handled automatically. "Impossible" and repeated
                              //(open an already displyed question) slides are ignored.
                              //If the question ID is 0 (zero) only the group is opened.
var sSlideMode = gsFAQSlideMode;
var sGrpID = gsFAQGrpGroupID;
var sQstID = gsFAQGrpQuestionID;
  if (gbFAQslideTest || FAQSlidingOn()) { //Do nothing if we are already sliding
    return;
  }
  if (qid == '0') { //Is it a group only request?
    //faq_0_0_g
    if (!document.getElementById('faq_' + gid + '_' + qid + '_g')) { //Check if the we can honor the request
      return;
    }
  }
  if (qid != '0') {
    if(!document.getElementById('faq_' + gid + '_' + qid + '_a')) { //Check if the we can honor the request
      return;
    }
  }
  if (gsFAQGrpGroupID != gid) {
    if (gsFAQGrpGroupID != '') { //A group is open
      if (gsFAQGrpQuestionID != '') { //Is the an open question in the open group
        FAQQuestionSlide(gsFAQGrpGroupID, gsFAQGrpQuestionID); //Close previous question
        gbFAQQuestionSlideClose = false; //Enable further sliding
        FAQGroupSlide(gsFAQGrpGroupID); //Close previous group
        gbFAQGrpSlideClose = false; //Enable further sliding
        if (qid != '0') { //If we are to open aquestion, not only the group
          gsFAQSlideMode = 'instant'; //Enable instant opening to achieve the full height of question for slide calculation
          FAQQuestionSlide(gid, qid); //Open new question - instantly!
          gsFAQSlideMode = sSlideMode; //Reset slide mode
        }
        FAQGroupSlide(gid); //Open new group; slide on full height of group + question.
      }
      else {
        FAQGroupSlide(gsFAQGrpGroupID); //Close previous group
        gbFAQGrpSlideClose = false; //Enable further sliding
        if (qid != '0') { //If we are to open aquestion, not only the group, see above.
          gsFAQSlideMode = 'instant'; //See above
          FAQQuestionSlide(gid, qid); //Open new question, see above
          gsFAQSlideMode = sSlideMode; //See above
        }
        FAQGroupSlide(gid); //Open new group, see above
      }
    }
    else {
      if (qid != '0') { //See above
        gsFAQSlideMode = 'instant'; //See above
        FAQQuestionSlide(gid, qid); //Open new question
        gsFAQSlideMode = sSlideMode; //See above
      }
      FAQGroupSlide(gid); //Open new group
    }
  }
  else { //We are in the same, already open, group
    if (gsFAQGrpQuestionID != '') { //Is the an open question in the open group
      if (gsFAQGrpQuestionID != qid) { //Is it a different question
        FAQQuestionSlide(gsFAQGrpGroupID, gsFAQGrpQuestionID); //Close previous question
        if (qid != '0') { //Open new question
          gbFAQQuestionSlideClose = false; //Enable further sliding
          FAQQuestionSlide(gid, qid); //Open new question
        }
      }
    }
    else {
      if (qid != '0') {
        FAQQuestionSlide(gid, qid); //Open question
      }
    }
  }
  // Move to the placement
  if (FAQSlidingOn()) { //If we have an actual slide aka change of question
    //if (qid == '') {
    //  qid = '0';
    //}
    gtmFAQGotoAnswer = setInterval('GotoAnswer(' + gid + ', ' + qid + ')', 100);
    if (sGrpID != '' && sQstID != '' && (gsFAQGrpGroupIDprev != sGrpID || gsFAQGrpQuestionIDprev != sQstID)) {
    //Only save if we have genuine values and at least one of them is different from the current.
      gsFAQGrpGroupIDprev = sGrpID;
      gsFAQGrpQuestionIDprev = sQstID;
    }
  }
}

function GotoAnswer(gid, qid) {
  if (!FAQSlidingOn()) {
    //document.location = '#' + 'faq_' + gid + '_' + qid;
    clearInterval(gtmFAQGotoAnswer);
    gbFAQSoftScrollOn = true;
    SoftScrollToElement('faq_' + gid + '_' + qid + '_q');
  }
}


function FAQgotoURLQA() { //Find a "faq=gNqN" query param and open that question if successful.
                          //Format is ...?faq=gIqJ where I  and J are two numbers, e.g. "faq=g11q3" (group 11, question 3)
var sURL = location.href;
//sURL = 'http://www.oticon.com/children/com/ParentsAndRelatives/Resources/Glossary/Glossary_FAQ?23&x=y&faq=g10q5&45&a=b'
var sURLquery, aParams, sParam, iI;
var sGrpAndQst, sGrp, sQst
  if (sURL.indexOf('?') != -1) { //Any query params?
    sURLquery = sURL.split('?')[1].toLowerCase(); //The pararms
    if (sURLquery != '') { //Really, any query params?
      aParams = sURLquery.split('&');
      for (iI = 0; iI < aParams.length; iI++) { //Run through each param set (sets like a=1 is expected)
        sParam = aParams[iI];
        if (sParam.indexOf('=') != -1) { //Found any param sets?
          var sKey = sParam.split('=')[0];
          if (sKey == 'faq') {
            sGrpAndQst = sParam.split('=')[1];
            sGrp = sGrpAndQst.split('q')[0].substr(1); //Split using the presumed format and remove the "g"
            sQst = sGrpAndQst.split('q')[1];
            iI = aParams.lengh; //Exit the loop
          }
        }
      }
      if (sGrp != '' && sQst != '') {
        FAQSlide(sGrp, sQst);
      }
    }
  }
}


//  Window soft scroller. Based on:
/*--------------------------------------------------------------------------
 *  Smooth Scroller Script, version 1.0.1
 *  (c) 2007 Dezinerfolio Inc. <midart@gmail.com>
 *
 *  For details, please check the website : http://dezinerfolio.com/
/*--------------------------------------------------------------------------*/
// Modified for general use with any element with a unique ID, for element
// onclick event activation and for optional faster settling.

var giCurrentScrollY; //Holds the current scroll position for when-to-stop reference.
var gtmScroll; //timer

function GetWinY (e) { // Returns the Y position with respect to the window of the item through any level of parent elements
  y = e.offsetTop;
  if (e.offsetParent) {
    while (e = e.offsetParent) {
      y += e.offsetTop;
    }
  }
  return y;
}

// Returns the current scroll position. Sniffs the DOM implementation to return the correct value.
function ScrollTop(){
var body = document.body;
var d = document.documentElement;
  if (body && body.scrollTop) return body.scrollTop;
  if (d && d.scrollTop) return d.scrollTop;
  if (window.pageYOffset) return window.pageYOffset;
  return 0;
}

function SoftScrollTo(y, sID){ //Move the scroll bar to the particular element.
var iScroolSpeed = 15; //Less is more (speed that is)
var iScrollSettler = 3; //For faster settling at the end, use a higher number
var e = document.getElementById(sID);
var i = (window.innerHeight || document.documentElement.clientHeight);
var h = document.body.scrollHeight;
var a = ScrollTop();
  if (y > a) { //If the item is placed lower than the scroll top (Y-coordinate of visible top)
    a += (Math.ceil((y - a) / iScroolSpeed)) + iScrollSettler;
  }
  else {
    a = a + ((y - a) / iScroolSpeed) - iScrollSettler;
    a = Math.ceil(a);
    if (a < y) { //Stop the upwards scroll once we pass the anker point
      a = y;
    }
  }
  window.scrollTo(0, a);
  if (a == y || e.offsetTop == a || a == giCurrentScrollY) {
    clearInterval(gtmScroll);
    gbFAQSoftScrollOn = false;  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Added for securing only one timer slide/scroll at the time
                                //                                        Only relevant for the FAQ slide stability
  }
  giCurrentScrollY = a;
}

function SoftScrollToElement(sID) {
var e = document.getElementById(sID);
var y = GetWinY(e);
  giCurrentScrollY = ScrollTop();
  gtmScroll = setInterval('SoftScrollTo(' + y + ', \'' + sID + '\')', 10);
}

/* End of window soft scroller */




/*
Browser name: BrowserDetect.browser
Browser version: BrowserDetect.version
OS name: BrowserDetect.OS
*/
var BrowserDetect = {
  init: function () {
    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
    this.version = this.searchVersion(navigator.userAgent)
      || this.searchVersion(navigator.appVersion)
      || "an unknown version";
    this.OS = this.searchString(this.dataOS) || "an unknown OS";
  },
  searchString: function (data) {
    for (var i=0;i<data.length;i++)  {
      var dataString = data[i].string;
      var dataProp = data[i].prop;
      this.versionSearchString = data[i].versionSearch || data[i].identity;
      if (dataString) {
        if (dataString.indexOf(data[i].subString) != -1)
          return data[i].identity;
      }
      else if (dataProp)
        return data[i].identity;
    }
  },
  searchVersion: function (dataString) {
    var index = dataString.indexOf(this.versionSearchString);
    if (index == -1) return;
    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
  },
  dataBrowser: [
    {
      string: navigator.userAgent,
      subString: "Chrome",
      identity: "Chrome"
    },
    {   string: navigator.userAgent,
      subString: "OmniWeb",
      versionSearch: "OmniWeb/",
      identity: "OmniWeb"
    },
    {
      string: navigator.vendor,
      subString: "Apple",
      identity: "Safari"
    },
    {
      prop: window.opera,
      identity: "Opera"
    },
    {
      string: navigator.vendor,
      subString: "iCab",
      identity: "iCab"
    },
    {
      string: navigator.vendor,
      subString: "KDE",
      identity: "Konqueror"
    },
    {
      string: navigator.userAgent,
      subString: "Firefox",
      identity: "Firefox"
    },
    {
      string: navigator.vendor,
      subString: "Camino",
      identity: "Camino"
    },
    {    // for newer Netscapes (6+)
      string: navigator.userAgent,
      subString: "Netscape",
      identity: "Netscape"
    },
    {
      string: navigator.userAgent,
      subString: "MSIE",
      identity: "Explorer",
      versionSearch: "MSIE"
    },
    {
      string: navigator.userAgent,
      subString: "Gecko",
      identity: "Mozilla",
      versionSearch: "rv"
    },
    {     // for older Netscapes (4-)
      string: navigator.userAgent,
      subString: "Mozilla",
      identity: "Netscape",
      versionSearch: "Mozilla"
    }
  ],
  dataOS : [
    {
      string: navigator.platform,
      subString: "Win",
      identity: "Windows"
    },
    {
      string: navigator.platform,
      subString: "Mac",
      identity: "Mac"
    },
    {
      string: navigator.platform,
      subString: "Linux",
      identity: "Linux"
    }
  ]

};
BrowserDetect.init();

/*
Currently we trust that instant mode (no slide) is not necessary in any case so
we have skipped this part of the browser detection.

var gbFAQIsMSIE = (BrowserDetect.browser == 'Explorer');
var gbFAQIsMSIE = true;
if (gbFAQIsMSIE && gsFAQSlideMode != 'instant') {
}
else {
  gbFAQslideTest = false;
  gsFAQSlideMode = 'instant';
}
*/


FAQtestSlideTime(); //Do a test of the current browser speed.
if (gbFAQSingleGroup) { //We need to flag that group 1 - the only one - is already open. It stays so.
                        //The gbFAQSingleGroup is set from the small portion of javascript that is written
                        //when creating the actual HTML (just after the HTML) and present at the loading
                        //of this current script.
  gsFAQGrpGroupID = '1';
}
