var clients = new Array();
var industries = new Array();
var categories = new Array();
var currentTopSection = null;
var currentMenu = null;
var currentNode = null;
var lastMenuSection = null;
var mainMenuArrow = null;
var nodeThumbNailBox = null;
var thumbNailBox = null;
var thumbNailImgBox = null;
var thumbNailBracketBox = null;
var thumbNailArrowBox = null;
var thumbNailHeaderBox = null;
var thumbNailSliderBox = null;
var thumbNailDirections = null;
var rpb = null;
var lpb = null;
var caseStudyBox = null;
var caseStudyTextBox = null;
var caseStudyTextCol1 = null;
var caseStudyTextCol2 = null;
var caseStudyImgCounterBox = null;
var caseStudyImgCaptionBox = null;
var caseStudyImgDirectionsBox = null;
var caseStudyImgBox = null;
var caseStudyHeaderBox = null;
var currentContactSection = "fone";

//load main page images
function loadMainPage() {
  cbeNewImage('childMenuArrowOn', '../images/main/menu/child_menu_arrow_on.gif');
  cbeNewImage('childMenuArrowOff', '../images/main/menu/child_menu_arrow_off.gif');
  cbeNewImage('contactFoneInfo', '../images/main/contact_fone_info.gif');
  cbeNewImage('contactEmailInfo', '../images/main/contact_email_info.gif');
  cbeNewImage('contactFone', '../images/main/contact_fone.gif');
  cbeNewImage('contactEmail', '../images/main/contact_email.gif');
  cbeNewImage('resumeWebOn', '../images/main/web_resume_active.gif');
  cbeNewImage('resumeWebOff', '../images/main/web_resume_hover.gif');
  cbeNewImage('resumePrintOn', '../images/main/print_resume_active.gif');
  cbeNewImage('resumePrintOff', '../images/main/print_resume_hover.gif');
  cbeNewImage('resumeFooter', '../images/main/resume_footer.gif');
  cbeNewImage('leftBracket', '../images/casestudy/icon_bracket_left.gif');
  cbeNewImage('rightBracket', '../images/casestudy/icon_bracket_right.gif');
  cbeNewImage('thumbNailArrow', '../images/casestudy/current_thumb_nail_arrow.gif');
  cbeNewImage('caseStudyDirections', '../images/casestudy/case_study_img_directions.gif');
  cbeNewImage("caseStudyImgArrow", "../images/casestudy/current_img_arrow.gif");
  cbeNewImage("caseStudyImgLine", "../images/casestudy/img_line.gif");
  cbeNewImage('resume', '../images/main/resume_off.gif');
  cbeNewImage('categoryOff', '../images/main/menu/category_off.gif');
  cbeNewImage('categorySelected2', '../images/main/menu/category_selected.gif');
  cbeNewImage('categoryUnselected2', '../images/main/menu/category_unselected.gif');
  cbeNewImage('clientOff', '../images/main/menu/client_off.gif');
  cbeNewImage('clientSelected2', '../images/main/menu/client_selected.gif');
  cbeNewImage('clientUnselected2', '../images/main/menu/client_unselected.gif');
  cbeNewImage('industryOff', '../images/main/menu/industry_off.gif');
  cbeNewImage('industrySelected2', '../images/main/menu/industry_selected.gif');
  cbeNewImage('industryUnselected2', '../images/main/menu/industry_unselected.gif');
  cbeNewImage('thumbNailDirections', '../images/casestudy/thumb_nail_directions.gif');
  cbeNewImage('toolbarDirections', '../images/main/menu/menu_directions.gif');
  cbeNewImage('pushButtonArrowRight', '../images/main/right_push_button_arrow.gif');
  cbeNewImage('pushButtonArrowLeft', '../images/main/left_push_button_arrow.gif');
  cbeNewImage('pushButtonArrowRightPressed', '../images/main/right_push_button_arrow_pressed.gif');
  cbeNewImage('pushButtonArrowLeftPressed', '../images/main/left_push_button_arrow_pressed.gif');
  cbeNewImage('topBorder', '../images/main/menu/top.gif');
  cbeNewImage('menuFooter', '../images/main/menu/footer.gif');
  cbeNewImage('dropMenu', '../images/main/menu/drop_box.gif');
  cbeNewImage('menuArrowNormal', '../images/main/menu/menu_arrow_normal.gif');
  cbeNewImage('menuArrowPressed', '../images/main/menu/menu_arrow_pressed.gif');
  cbeNewImage('mainCar', '../images/main/car.gif');
  cbeNewImage('mainFlame', '../images/main/flame.gif');
}

//set the main page images.
function initMainPage() {
  nodeThumbNailBox = cbeGetElementById('menu.thumbnail.box');
  thumbNailDirections = cbeGetElementById('thumbnail.directions');
  thumbNailDirections.cbe.resizeTo(261, 16);
  thumbNailDirections.cbe.zIndex(4);
  thumbNailDirections.cbe.moveTo(((673/2)-(261/2)), 0);
  thumbNailBox = cbeGetElementById('thumbnail.thumbNailBox');
  thumbNailBox.cbe.moveTo(28, 18);
  thumbNailBox.cbe.resizeTo(616, 72);
  thumbNailBox.cbe.zIndex(1);
  thumbNailImgBox = cbeGetElementById('thumbnail.imgBox');
  thumbNailBracketBox = cbeGetElementById('thumbnail.bracketBox');
  thumbNailArrowBox = cbeGetElementById('thumbnail.arrowBox');
  thumbNailArrowBox.cbe.resizeTo(14, 6);
  thumbNailArrowBox.cbe.zIndex(1);
  thumbNailHeaderBox = cbeGetElementById('thumbnail.headerBox');
  thumbNailSliderBox = cbeGetElementById('thumbnail.sliderBox');
  rpb = cbeGetElementById('thumbnail.rightPushButton');
  rpb.cbe.resizeTo(10, 18);
  rpb.cbe.moveTo(650, 50);
  rpb.cbe.background('73731B');
  lpb = cbeGetElementById('thumbnail.leftPushButton');
  lpb.cbe.resizeTo(10, 18);
  lpb.cbe.moveTo(10, 50);
  lpb.cbe.background('73731B');
  caseStudyBox = cbeGetElementById('casestudy.box');
  caseStudyBox.cbe.zIndex(10);
  caseStudyBox.cbe.moveTo(0, 83);
  caseStudyBox.cbe.resizeTo(671, 250);
  caseStudyHeaderBox = cbeGetElementById('casestudy.header');
  caseStudyHeaderBox.cbe.resizeTo(340, 25);
  caseStudyHeaderBox.cbe.moveTo(325, 10);
  caseStudyImgBox  = cbeGetElementById('casestudy.sample');
  caseStudyImgBox.cbe.moveTo(30, 15);
  caseStudyImgBox.cbe.resizeTo(284, 188);
  caseStudyImgCaptionBox = cbeGetElementById('casestudy.sample.caption');
  caseStudyImgCaptionBox.cbe.resizeTo(284, 10);
  caseStudyImgCaptionBox.cbe.moveTo(30, 205);
  caseStudyImgCounterBox = cbeGetElementById('casestudy.sample.counter');
  caseStudyImgCounterBox.cbe.moveTo(10, 15);
  caseStudyImgCounterBox.cbe.resizeTo(20, 188);
  caseStudyImgDirectionsBox = cbeGetElementById('casestudy.sample.directions');
  caseStudyImgDirectionsBox.cbe.resizeTo(284, 11);
  caseStudyImgDirectionsBox.cbe.moveTo(30, 220);
  cbeSetImage("casestudy.sample.directions.img", "caseStudyDirections");
  caseStudyTextBox = cbeGetElementById('casestudy.text');
  caseStudyTextBox.cbe.resizeTo(346, 192);
  caseStudyTextBox.cbe.moveTo(325, 40);
  caseStudyTextCol1 = cbeGetElementById('casestudy.text.col1');
  caseStudyTextCol1.cbe.width(160);
  caseStudyTextCol2 = cbeGetElementById('casestudy.text.col2');
  caseStudyTextCol2.cbe.moveTo(175, 0);
  caseStudyTextCol2.cbe.width(160);
  mainMenuArrow = cbeGetElementById('main.menu.arrow');
  var resume = cbeGetElementById('main.resume');
  with(resume.cbe) {
    zIndex(2);
    moveTo(260, 0);
  }
  with(nodeThumbNailBox.cbe) {
    resizeTo(673, 94);
    zIndex(2);
    moveTo(0, 324);
    background('#CCCC66');
  }
  with(cbeGetElementById('main.menu.directions').cbe) {
    resizeTo(212, 13);
    zIndex(4);
    moveTo(((673/2)-(212/2)), 0);
  }
  with(mainMenuArrow.cbe) {
    resizeTo(15, 8);
  }
  var menu = cbeGetElementById('main.menu.inactive');
  with(menu.cbe) {
    zIndex(2);
    moveTo(0, 0);
  }
  with(cbeGetElementById('main.contact.info.fone').cbe){
    zIndex(2);
    moveTo(483, 51);
  }
  with(cbeGetElementById('main.contact.info.email').cbe){
    zIndex(2);
    moveTo(483, 51);
  }

  cbeSetImage('main.car.img', 'mainCar');
  cbeSetImage('thumbnail.rightPushButton.img', 'pushButtonArrowRight');
  cbeSetImage('thumbnail.leftPushButton.img', 'pushButtonArrowLeft');
  cbeSetImage('thumbnail.directions.img', 'thumbNailDirections');
  cbeSetImage('main.resume.img', 'resume');
  cbeSetImage('main.resume.active.web.img', 'resumeWebOff');
  cbeSetImage('main.resume.active.print.img', 'resumePrintOff');
  cbeSetImage('main.resume.active.footer.img', 'resumeFooter');
  cbeSetImage('main.menu.directions.img', 'toolbarDirections');
  cbeSetImage('main.menu.widget.img', 'dropMenu');
  cbeSetImage('main.menu.button.arrow.img', 'menuArrowNormal');
  cbeSetImage('main.menu.bottom.img', 'menuFooter');
  cbeSetImage('main.menu.top.img', 'topBorder');
  cbeSetImage('main.contact.active.img', 'contactFone');
  cbeSetImage('main.contact.info.fone.img', 'contactFoneInfo');
  cbeSetImage('main.contact.info.email.img', 'contactEmailInfo');

  setMainMenu();
  mainPageIsInit = true;
}

function setMainMenu() {
  cbeSetImage('main.menu.inactive.img', currentMenuSection + 'Off');
  if (currentMenuSection == 'category') {
    if (!mainMenuArrow.cbe.moving)
      mainMenuArrow.cbe.moveTo(36, 7);
    cbeSetImage('main.menu.category.img', 'categorySelected2');
    cbeSetImage('main.menu.client.img', 'clientUnselected2');
    cbeSetImage('main.menu.industry.img', 'industryUnselected2');
  } else if (currentMenuSection == 'client') {
    if (!mainMenuArrow.cbe.moving)
      mainMenuArrow.cbe.moveTo(106, 7);
    cbeSetImage('main.menu.category.img', 'categoryUnselected2');
    cbeSetImage('main.menu.client.img', 'clientSelected2');
    cbeSetImage('main.menu.industry.img', 'industryUnselected2');
  } else {
    if (!mainMenuArrow.cbe.moving)
      mainMenuArrow.cbe.moveTo(176, 7);
    cbeSetImage('main.menu.category.img', 'categoryUnselected2');
    cbeSetImage('main.menu.client.img', 'clientUnselected2');
    cbeSetImage('main.menu.industry.img', 'industrySelected2');
  }
}

/**
 * There are two main pages to the application the home page and the main page.
 * The main page is where all the case studies are displayed.
 */
function showMainPage() {
  lastMenuSection = currentMenuSection;
  currentMenu = eval(currentMenuSection + "Menu");
  mainContainer.cbe.background('#DADA94');
  var resume = cbeGetElementById('main.resume');
  with(resume.cbe) {
    show();
    //fadeIn(200, 20);
  }
  with(nodeThumbNailBox.cbe) {
    show();
    //fadeIn(200, 20);
  }
  with(cbeGetElementById('main.menu.directions').cbe) {
    show();
    //fadeIn(200, 20);
  }
  with(mainMenuArrow.cbe) {
    show();
  }
  var menu = cbeGetElementById('main.menu.inactive');
  with(menu.cbe) {
    show();
    //fadeIn(200, 20, "showCurrentCaseStudy()");
  }
  cbeSetImage('home.flame.img', 'mainFlame');
  showCurrentCaseStudy();
  showDropMenu();
  setMainMenu();
  //curremtMenu.header.cbe.show();

}

function showMainText() {
  with(cbeGetElementById('main.text').cbe){
    zIndex(2);
    moveTo(350, 150);
    if (is.nav4) {
      innerHtml("<table>" +
                "<tr><td><font point-size='10' color='black' face='arial,verdana,sans-serif'>GET MOVING:</font></td></tr>" +
                "<tr><td><font point-size='10' color='black' face='arial,verdana,sans-serif'>Select an item from the portfolio menu above</font></td></tr>" +
                "<tr><td><font point-size='10' color='black' face='arial,verdana,sans-serif'>to view client work.</font></td></tr>" +
                "</table>");
    } else {
      innerHtml("<table>" +
                "<tr><td style='font-size:12px;font-family:arial,verdana,sans-serif;color:black;text-align:left;'>GET MOVING:</td></tr>" +
                "<tr><td style='font-size:12px;font-family:arial,verdana,sans-serif;color:black;text-align:left;'>Select an item from the portfolio menu above</td></tr>" +
                "<tr><td style='font-size:12px;font-family:arial,verdana,sans-serif;color:black;text-align:left;'>to view client work.</td></tr>" +
                "</table>");
    }
    show();
  }
}

function showCurrentCaseStudy() {
  currentNode = currentMenu.currentNode;
  if (currentNode) {
    currentNode.thumbNailBox.showThumbNails(null, true);
    currentNode.thumbNailBox.currentThumbNail.casestudy.show();
    cbeGetElementById('main.menu.active').cbe.show();
    currentMenu.show();
    currentTopSection = 'main.menu.active';
  } else {
    with(cbeGetElementById('main.car').cbe){
      zIndex(2);
      moveTo(-300, 200);
      show();
      slideTo(20, 170, 400, "showMainText()");
    }
    cbeGetElementById('home.flame').cbe.show();
  }
}

/**
 * Clear the main page of all floating layers and images.
 */
function clearMainPage() {
  cbeGetElementById('main.contact.info.'+currentContactSection).cbe.hide();
  if (currentTopSection != null) {
    cbeGetElementById(currentTopSection).cbe.hide();
    currentTopSection = null;
  }

  if (currentNode)
    currentNode.thumbNailBox.hideThumbNails();
  cbeGetElementById('main.car').cbe.hide();
  cbeSetImage('home.flame.img', 'flame');
  cbeGetElementById('main.text').cbe.hide();
  cbeGetElementById('main.menu.inactive').cbe.hide();
  cbeGetElementById('main.menu.active').cbe.hide();
  cbeGetElementById('main.resume').cbe.hide();
  cbeGetElementById('main.menu.directions').cbe.hide();
  if (currentMenu != null) {
    nodeThumbNailBox.cbe.hide();
    hideMenu();
  }
}

/**
 * Fade in section
 */
function showSection(id, px, py, endListener){
  if (id == "main.contact.active")
    cbeGetElementById('main.contact.info.'+currentContactSection).cbe.show();
  else
    cbeGetElementById('main.contact.info.'+currentContactSection).cbe.hide();
  var section = cbeGetElementById(id);
  with(section.cbe) {
    zIndex(4);
    moveTo(px, py);
    //fadeIn(null, 20, endListener);
    show();
    eval(endListener);
  }
  hideCurrentSection();
  currentTopSection = id;
}

/**
 * Fade out section
 */
function hideCurrentSection(){
  if (currentTopSection != null) {
    cbeGetElementById(currentTopSection).cbe.hide();
    if (currentMenu.isOpen) {
      currentMenu.close();
    }
  }
}

function clickMainMenuItem(itemNm) {
  if (currentMenuSection != itemNm) {
    //Do image roll overs.
    cbeSetImage('main.menu.' + currentMenuSection + '.img', currentMenuSection + 'Unselected2');
    cbeSetImage('main.menu.inactive.img', currentMenuSection + 'Off');
    cbeSetImage('main.menu.' + itemNm + '.img', itemNm + 'Selected2');

    //Hide old shiz.
    if (currentMenu) currentMenu.hide();
    if (currentMenu.currentNode) {
      currentMenu.currentNode.thumbNailBox.currentThumbNail.casestudy.hide();
      currentMenu.currentNode.thumbNailBox.hideThumbNails();
    }

    currentMenuSection = itemNm;
    currentMenu = eval(itemNm + "Menu");
    currentNode = currentMenu.currentNode;
    if (currentNode) {
      cbeGetElementById('main.text').cbe.hide();
      cbeGetElementById('main.car').cbe.hide();
      cbeGetElementById('home.flame').cbe.hide();
    } else {
      cbeGetElementById('main.text').cbe.show();
      cbeGetElementById('main.car').cbe.show();
      cbeGetElementById('home.flame').cbe.show();
    }

    if (itemNm == 'client') {
      mainMenuArrow.cbe.slideTo(106, 7, 400, "if(currentNode){currentNode.thumbNailBox.showThumbNails(null, true);currentNode.thumbNailBox.currentThumbNail.casestudy.show();}");
    } else if (itemNm == 'industry') {
      mainMenuArrow.cbe.slideTo(176, 7, 400, "if(currentNode){currentNode.thumbNailBox.showThumbNails(null, true); currentNode.thumbNailBox.currentThumbNail.casestudy.show();}");
    } else if (itemNm == 'category') {
      mainMenuArrow.cbe.slideTo(36, 7, 400, "if(currentNode){currentNode.thumbNailBox.showThumbNails(null, true);currentNode.thumbNailBox.currentThumbNail.casestudy.show();}");
    }

    showDropMenu();
    setMainMenu();
  }
}

function mouseOverMainMenuItem(itemNm) {
  cbeSetImage('main.menu.' + lastMenuSection + '.img', lastMenuSection + 'Unselected2');
  cbeSetImage('main.menu.' + itemNm + '.img', itemNm + 'Selected2');
  lastMenuSection = itemNm;
}

function mouseOutMainMenuItem() {
  cbeSetImage('main.menu.' + lastMenuSection + '.img', lastMenuSection + 'Unselected2');
  cbeSetImage('main.menu.' + currentMenuSection + '.img', currentMenuSection + 'Selected2');
  lastMenuSection = currentMenuSection;
}

/**
 * What to do when the menu arrow button is pressed.
 */
function mouseDownMenuArrow() {
  cbeSetImage('main.menu.button.arrow.img', 'menuArrowPressed');
}

/**
 * What to do when the mouse lets up on the menu arrow button.
 */
function mouseUpMenuArrow() {
  cbeSetImage('main.menu.button.arrow.img', 'menuArrowNormal');
  openMenu();
}

function showCaseStudy(index, firstLoad) {
  if (currentNode) {
    if (index != currentNode.thumbNailBox.currentIndex || firstLoad) {
      currentNode.thumbNailBox.currentThumbNail.casestudy.hide();
      currentNode.thumbNailBox.currentIndex = index;
      currentNode.thumbNailBox.currentThumbNail = currentNode.thumbNailBox.thumbNails[index];
      if (!firstLoad) {
        currentNode.thumbNailBox.slideThumbNailArrow("currentNode.thumbNailBox.currentThumbNail.casestudy.show()");
      } else {
        currentNode.thumbNailBox.currentThumbNail.casestudy.show();
      }
    }
  }
}

function mouseOverFone() {
  cbeSetImage('main.contact.active.img', 'contactFone');
  currentContactSection = "fone";
  cbeGetElementById('main.contact.info.email').cbe.hide();
  cbeGetElementById('main.contact.info.fone').cbe.show();
}

function mouseOverEmail() {
  cbeSetImage('main.contact.active.img', 'contactEmail');
  cbeGetElementById('main.contact.info.fone').cbe.hide();
  cbeGetElementById('main.contact.info.email').cbe.show();
  currentContactSection = "email";
}

function mouseOverPrintResume() {
  cbeSetImage('main.resume.active.web.img', 'resumeWebOff');
  cbeSetImage('main.resume.active.print.img', 'resumePrintOn');
}

function mouseOverWebResume() {
  cbeSetImage('main.resume.active.web.img', 'resumeWebOn');
  cbeSetImage('main.resume.active.print.img', 'resumePrintOff');
}

function mouseDownPushButtonRight() {
  if(!is.ie) cbeSetImage('thumbnail.rightPushButton.img', 'pushButtonArrowRightPressed');
  if(!is.nav4) return false;
}

function mouseUpPushButtonRight() {
  if(!is.ie) cbeSetImage('thumbnail.rightPushButton.img', 'pushButtonArrowRight');

}

function mouseDownPushButtonLeft() {
  if(!is.ie) cbeSetImage('thumbnail.leftPushButton.img', 'pushButtonArrowLeftPressed');
  if(!is.nav4) return false;
}

function mouseUpPushButtonLeft() {
  if(!is.ie) cbeSetImage('thumbnail.leftPushButton.img', 'pushButtonArrowLeft');
}

function openResume(page){
  var w = 625;
  var h = 500;
  var x = screen.width/2 - (w/2);
  var y = screen.height/2 - (h/2);
  window.open( page, 'res',
               'menubar=no,' +
               'alwaysRaised=yes,' +
               'directories=no,' +
               'location=no,' +
               'resizable=yes,' +
               'scrollbars=yes,' +
               'status=no,' +
               'toolbar=yes,' +
               'width='+w+',' +
               'height='+h+',' +
               'screenX='+x+',' +
               'screenY='+y+',' +
               'left='+x+',' +
               'top='+y );

}
