var activeMenu = -1;
var activeSubSubMenu = false;
var scrollies = new Array();
var hasInited = false;

function initPage() {
 initScrollies();
 initExternalLinks();
 setTimeout('holdYerHorses = false', 500);
 setTimeout('doResize()', 100);
 setTimeout('hasInited = true', 200);
}

function initExternalLinks() {
 allLinks = document.getElementsByTagName('a');
 for (i=0;i<allLinks.length;i++) {
  if (allLinks[i].href.indexOf('http://') > -1 && allLinks[i].href.indexOf('http://strivegroup.com') == -1 && allLinks[i].href.indexOf('http://www.strivegroup.com') == -1)
   allLinks[i].target="_blank";
 }
}


function doResize() {
//----- MOVE SUBMENUS
  oddPixelOffset = 0;
 for (i=0;document.getElementById('menu'+i);i++) {
  tmpW = document.getElementById('menu'+i).offsetWidth;
//----- SUBTRACT BORDERS
  if (navigator.userAgent.indexOf('Firefox') > -1 && document.getElementById('tableWrapper') && document.getElementById('tableWrapper').offsetLeft % 2 == 1) {
    oddPixelOffset = -1;
    if (i == 0)
     tmpW += 1;
  }

  if (navigator.userAgent.indexOf('Firefox') > -1 && i > 0 && oddPixelOffset == 0 && i < totalSubMenus - 1) {
   if (i % 2 == 1)
    tmpW += 1;
   else
    tmpW -= 1;
  }

  tmpW -= 2;

  document.getElementById('subMenu'+i).style.width = tmpW + 'px';
//----- AND DETECT WHICH MENU IS 'LIVE'
  if (document.getElementById('menu'+i).className == 'menuItemActive')
   activeMenu = i;
 }
 posArr = getPOS(document.getElementById('menu0'));
 var o = document.getElementById('subMenuHolder');
 posArr[1] += 52 + 19 + 10 + 1;
 posArr[0] += oddPixelOffset;
 o.style.left = posArr[0] + 'px';
 o.sBottom = posArr[1];
//----- SET UP VERTICAL POSITION ON INIT
 if (!o.sTop) {
  o.sTop = o.sBottom - o.offsetHeight - 2;
  o.style.top = o.sTop + 'px';
  o.curY = o.sTop;
  o.to = false;
 }


 for (i=0;document.getElementById('subMenuItem'+i);i++) {
  initSubSubMenu(i);
 }

}

function initSubSubMenu(nm) {
 var o = document.getElementById('subSubMenu'+nm);
 var p = document.getElementById('subSubMenuHolder'+nm);
 posArr = getPOS(document.getElementById('subMenuItem'+nm));
 posArr[0] += document.getElementById('subMenuItem'+nm).offsetWidth;
 p.style.left = posArr[0] + 'px';
 posArr[1] += document.getElementById('subMenuHolder').offsetHeight + 2;
 p.style.top = posArr[1] + 'px';
 tmpW = p.offsetWidth + 2;
 p.style.width = tmpW + 'px';
 p.width = tmpW;

 o.sRight = 0;
 o.sLeft = -2 - o.offsetWidth;
 o.curX = o.sLeft;
 o.style.left = o.sLeft + 'px';
 o.to = false;
}

function toggleSubMenu() {
 if (!hasInited)
  return;

 var o = document.getElementById('subMenuHolder');
 clearTimeout(o.to);
//----- HIDE CURRENT SUB SUB MENU
 if (activeSubSubMenu) {
  document.getElementById('subSubMenu'+activeSubSubMenu[0]).style.visibility = 'hidden';
  document.getElementById('subSubMenu'+activeSubSubMenu[0]).curX = document.getElementById('subSubMenu'+activeSubSubMenu[0]).sLeft;
  activeSubSubMenu[1].className = 'subMenuItem';
  activeSubSubMenu = false;
 }

 if (document.getElementById('subMenuHolder').style.visibility == 'hidden') {
  o.to = setTimeout('scrollV("subMenuHolder", '+o.sBottom+')', 50);
 } else {
  o.to = setTimeout('scrollV("subMenuHolder", '+o.sTop+')', 50);
  reallyHideSubSubMenu();
 }
}

function showSubMenu() {
 if (!hasInited)
  return;

 var o = document.getElementById('subMenuHolder');
 o.keepMe = true;

 if (document.getElementById('subMenuHolder').style.visibility == 'hidden') {
  clearTimeout(o.to);
  o.to = setTimeout('scrollV("subMenuHolder", '+o.sBottom+')', 50);
 }
}
function hideSubMenu() {
 var o = document.getElementById('subMenuHolder');
 o.keepMe = false;
 setTimeout('reallyHideSubMenu()', 100);
}
function reallyHideSubMenu() {
 var o = document.getElementById('subMenuHolder');
 if (!o.keepMe) {
  clearTimeout(o.to);
  o.to = setTimeout('scrollV("subMenuHolder", '+o.sTop+')', 50);
  reallyHideSubSubMenu();
 }
}


function toggleSubSubMenu(nm, p) {
 if (!hasInited)
  return;

 var o = document.getElementById('subSubMenu'+nm);
 clearTimeout(o.to);
 if (o.style.visibility == 'hidden') {
  o.to = setTimeout('scrollH("subSubMenu'+nm+'", '+o.sRight+')', 100);
  p.className = 'subMenuItemActive';
  activeSubSubMenu = new Array(nm, p);
 } else {
  o.to = setTimeout('scrollH("subSubMenu'+nm+'", '+o.sLeft+')', 100);
  p.className = 'subMenuItem';
  activeSubSubMenu = false;
 }
}

function showSubSubMenu(nm, p) {
 if (!hasInited)
  return;

 var o = document.getElementById('subSubMenu'+nm);
 if (!o.to) {
  clearTimeout(o.to);
  o.keepMe = true;
  if (o.style.visibility == 'hidden') {
   o.to = setTimeout('scrollH("subSubMenu'+nm+'", '+o.sRight+')', 50);
   p.className = 'subMenuItemActive';
   activeSubSubMenu = new Array(nm, p);
  }
 }
}
function hideSubSubMenu() {
 if (activeSubSubMenu[1]) {
  var o = document.getElementById('subSubMenu'+activeSubSubMenu[0]);
  o.keepMe = false;

  setTimeout('reallyHideSubSubMenu()', 100);
 }
}
function reallyHideSubSubMenu() {
 if (activeSubSubMenu[1]) {
  var p = activeSubSubMenu[1];
  var o = document.getElementById('subSubMenu'+activeSubSubMenu[0]);
  if (!o.keepMe && !o.to) {
   o.to = setTimeout('scrollH("subSubMenu'+activeSubSubMenu[0]+'", '+o.sLeft+')', 50);
   p.className = 'subMenuItem';
   activeSubSubMenu = false;
  }
 }
}



function scrollV(id, endY) {
 if (!hasInited)
  return;

 var o = document.getElementById(id);
 clearTimeout(o.to);

 tmpY = Math.round((o.curY + endY)/2);
 if (Math.abs(tmpY - endY) < 2)
  tmpY = endY;

 clipTop = o.sBottom - tmpY;
 o.style.clip = 'rect('+clipTop+'px,1100px,2000px,0px)';

 if (o.style.visibility = 'hidden')
  o.style.visibility = 'visible';

 o.style.top = tmpY + 'px';
 o.curY = tmpY;

 if (tmpY != endY)
  o.to = setTimeout('scrollV("'+id+'", '+endY+')', 50);
 else if (endY == o.sTop)
  o.style.visibility = 'hidden';
}

function scrollH(id, endX) {
 if (!hasInited)
  return;

 var o = document.getElementById(id);
 clearTimeout(o.to);

 tmpX = Math.round((o.curX + endX)/2);
 if (Math.abs(tmpX - endX) < 2)
  tmpX = endX;

 if (o.style.visibility = 'hidden')
  o.style.visibility = 'visible';
 if (id == 'subSubMenu0')
  document.getElementById('subSubMenuHolder0').style.visibility = 'visible';

 o.style.left = tmpX + 'px';
 o.curX = tmpX;

 if (tmpX != endX) {
  o.to = setTimeout('scrollH("'+id+'", '+endX+')', 50);
 } else if (endX == o.sLeft) {
  o.style.visibility = 'hidden';
 if (id == 'subSubMenu0')
  document.getElementById('subSubMenuHolder0').style.visibility = 'hidden';

  o.to = false;
 } else {
  o.to = false;
 }
}



function hilightMenu(nm) {
 if (!hasInited)
  return;

  document.getElementById('subMenuHolder').keepMe = true;
  for (i=0;document.getElementById('menu'+i);i++) {
   if (nm == i)
    document.getElementById('menu'+i).className = 'menuItemActive';
   else
    document.getElementById('menu'+i).className = 'menuItem';
 }
}
function unhilightMenu(nm) {
 if (!hasInited)
  return;

  document.getElementById('subMenuHolder').keepMe = false;
  hCount = 0;
  for (i=0;document.getElementById('menu'+i);i++) {
   if (nm == i)
    document.getElementById('menu'+i).className = 'menuItem';
   else if (document.getElementById('menu'+i).className == 'menuItemActive')
    hCount++;
  }
  if (hCount == 0 && document.getElementById('menu'+activeMenu))
   document.getElementById('menu'+activeMenu).className = 'menuItemActive';
}









function doMenuHover(o) {
 for (i=0;i<totalSubMenus;i++) {
  document.getElementById('menu'+i).style.background = '#ffffff';
  document.getElementById('menu'+i).style.color = '';
 }
 o.style.background = '#cbcbcb';
 o.style.color = '#000000';
}
function doMenuUnhover(o) {
 for (i=0;i<totalSubMenus;i++) {
  document.getElementById('menu'+i).style.background = '#ffffff';
  document.getElementById('menu'+i).style.color = '';
 }
}

var totalSubMenus = 5;
var subMenuIsVisible = false;
var subMenuTO = false;
var subMenuY = 0;
var subMenuH = 0;
var subMenuDoHide = false;
var holdYerHorses = true;
var subMenuBottom = -45;




function getPOS(o) {
 var posArr = new Array(o.offsetLeft, o.offsetTop);
 while (o.offsetParent) {
  o = o.offsetParent;
  posArr[0] += o.offsetLeft;
  posArr[1] += o.offsetTop;
 }
 return(posArr);
}



var scrollNewsTO = false;
var scrollNewsPOS = 0;
function showNews() {
 clearTimeout(scrollNewsTO);
 scrollNewsTO = setTimeout('animScrollNews(382);', 50);
}
function hideNews() {
 clearTimeout(scrollNewsTO);
 scrollNewsTO = setTimeout('animScrollNews(0);', 50);
}
function animScrollNews(endPOS) {
 clearTimeout(scrollNewsTO);

 tmpPOS = Math.round((endPOS + scrollNewsPOS)/2);
 if (Math.abs(tmpPOS - endPOS) < 3)
  tmpPOS = endPOS;

 document.getElementById('newsScroll').style.left = tmpPOS + 'px';
 scrollNewsPOS = tmpPOS;

 if (scrollNewsPOS != endPOS)
  scrollNewsTO = setTimeout('animScrollNews('+endPOS+')', 50);
}





caseStudyTO = false;
function showNextImage() {
 if (!caseStudyTO) {
  curImg++;
  if (curImg >= imgArr.length)
   curImg = 0; 

  document.getElementById('mainImg').style.background = "URL('"+imgArr[curImg]+"') no-repeat top center";

  caseStudyTO = setTimeout('animateCaseStudy(100);', 50);
 }
}

function showPrevImage() {
 if (!caseStudyTO) {
  curImg--;
  if (curImg < 0)
   curImg = imgArr.length - 1;

  document.getElementById('mainImg').style.background = "URL('"+imgArr[curImg]+"') no-repeat top center";
  caseStudyTO = setTimeout('animateCaseStudy(100);', 50);
 }
}

function animateCaseStudy(nm) {
 clearTimeout(caseStudyTO);

 newAlpha = nm - 10;
 if (newAlpha < 0)
  newAlpha = 0;

 o = document.getElementById('overDiv');
 o.style['filter'] = 'alpha(opacity='+newAlpha+')';
 tmpOpac = newAlpha / 100;
 o.style['-moz-opacity'] = tmpOpac;
 o.style['-khtml-opacity'] = tmpOpac;
 o.style['opacity'] = tmpOpac;

 if (newAlpha > 0) {
  caseStudyTO = setTimeout('animateCaseStudy('+newAlpha+');', 50);
 } else {
  o.style.background = document.getElementById('mainImg').style.background;
  newAlpha = 100;
  o.style['filter'] = 'alpha(opacity='+newAlpha+')';
  tmpOpac = newAlpha / 100;
  o.style['-moz-opacity'] = tmpOpac;
  o.style['-khtml-opacity'] = tmpOpac;
  o.style['opacity'] = tmpOpac;
  caseStudyTO = false;
 }
}

function showArrows() {
 document.getElementById('arrowL').style.visibility = 'visible';
 document.getElementById('arrowR').style.visibility = 'visible';
}
function hideArrows() {
 document.getElementById('arrowL').style.visibility = 'hidden';
 document.getElementById('arrowR').style.visibility = 'hidden';
}








var tnPOS = 0;
var totalTNs = 7;
var tnW = totalTNs * 192;
var minTNPOS = totalTNs * -192;
var scrollTO = false;
function scrollTNLeft() {
 if (!scrollTO) {
  endPOS = tnPOS + 192;
  scrollTNs(endPOS);
 }
}
function scrollTNRight() {
 if (!scrollTO) {
  endPOS = tnPOS - 192;
  scrollTNs(endPOS);
 }
}
function scrollTNs(endPOS) {
 clearTimeout(scrollTO);

 tmpPOS = Math.round((endPOS + tnPOS)/2);
 if (Math.abs(endPOS - tnPOS) < 4)
  tmpPOS = endPOS;

 if (tmpPOS < minTNPOS) {
  tmpPOS += tnW;
  endPOS += tnW;
 } else if (tmpPOS > 0) {
  tmpPOS -= tnW;
  endPOS -= tnW;
 }

 tnPOS = tmpPOS;
 document.getElementById('tns').style.left = tnPOS + 'px';

 if (tnPOS != endPOS)
  scrollTO = setTimeout('scrollTNs('+endPOS+');', 50);
 else
  scrollTO = false;
}


var origFooterY = 0;


function initScrollies() {
 for (i=0;document.getElementById('scrollie'+i);i++) {
  var o = document.getElementById('scrollie'+i);
  o.scH = o.offsetHeight;
  o.scW = o.offsetWidth;
  o.curY = o.scH;
  o.sTO = false;
  o.sID = i;
  scrollies[scrollies.length - 1] = o;
  o.style.position = 'relative';
  o.style.top = o.curY + 'px';
  o.style.visibility = 'visible';
 }
}

function showScrollie(nm) {
 if (!hasInited)
  return;

 hideSubMenu();
 var o = document.getElementById('scrollie'+nm);
 clearTimeout(o.sTO);
 o.sTO = setTimeout('animScrollie('+o.sID+', '+o.curY+', 0)', 50);
}

function hideScrollie(nm) {
 if (!hasInited)
  return;

 var o = document.getElementById('scrollie'+nm);
 clearTimeout(o.sTO);
 var tmpY = o.scH;
 o.sTO = setTimeout('animScrollie('+o.sID+', '+o.curY+', '+tmpY+')', 50);
}

function animScrollie(nm, curY, endY) {
 var o = document.getElementById('scrollie'+nm);
 clearTimeout(o.sTO);
 var tmpY = Math.round((curY + endY + endY)/3);
 if (Math.abs(tmpY - endY) < 3)
  tmpY = endY;

 o.style.top = tmpY + 'px';
 o.curY = tmpY;

 if (o.curY != endY)
  o.sTO = setTimeout('animScrollie('+nm+', '+o.curY+', '+endY+')', 50);
}





var mainFadeTO = false;
var mainFadeNum = 0;
function initMainFade() {
//----- STUPID IE 7
 isIE7 = (navigator.appVersion.indexOf('MSIE 7.')==-1) ? false : true;
 if (isIE7) {
  window.attachEvent('onresize', doMainIEResize);
  doMainIEResize();
 }
 startMainFade();
}
function doMainIEResize() {
 tmpW = document.getElementsByTagName('body')[0].offsetWidth;
 if (tmpW < 1151)
  tmpW = 1151;

 document.getElementById('mainBottom').style.display = 'inline';
 document.getElementById('mainTop').style.display = 'inline';

 document.getElementById('mainBottom').style.width = tmpW+'px';
 document.getElementById('mainTop').style.width = tmpW+'px';
}
function startMainFade() {
 mainFadeNum++;
 if (mainFadeNum >= mainImgArr.length)
  mainFadeNum = 0;

 document.getElementById('mainBottom').src = mainImgArr[mainFadeNum].src;
 mainFadeTO = setTimeout('animateMainFade(100)', 6000);
}

function animateMainFade(nm) {
 clearTimeout(mainFadeTO);
 newAlpha = nm - 10;
 if (newAlpha < 0)
  newAlpha = 0;

 o = document.getElementById('mainTop');
 o.style['filter'] = 'alpha(opacity='+newAlpha+')';
 tmpOpac = newAlpha / 100;
 o.style['-moz-opacity'] = tmpOpac;
 o.style['-khtml-opacity'] = tmpOpac;
 o.style['opacity'] = tmpOpac;

 if (newAlpha > 0) {
  mainFadeTO = setTimeout('animateMainFade('+newAlpha+');', 50);
 } else {
  o.src = document.getElementById('mainBottom').src;
  newAlpha = 100;
  o.style['filter'] = 'alpha(opacity='+newAlpha+')';
  tmpOpac = newAlpha / 100;
  o.style['-moz-opacity'] = tmpOpac;
  o.style['-khtml-opacity'] = tmpOpac;
  o.style['opacity'] = tmpOpac;
  mainFadeTO = false;
  startMainFade();
 }
}
