/*

DROPDOWN SIZER FOR FREESTYLE MENUS v1.0

This script resizes the dropdown to the full rowser width, as IE6 struggles doing it by CSS

*/

function getElementsByClass(searchClass, node, tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = document.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\\\s)" + searchClass + "(\\\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className)) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return [curleft, curtop];
  }
}

function resizeElements() {

  var dropArray = getElementsByClass("navDrop", "navMainList", "ul");
  for (i = 0; i < dropArray.length; i++) {
    dropArray[i].style.width = document.body.clientWidth;
  }
  if ($('contentMain')) {
    var height = 400;
    if ($('contentMain')) if ($('contentMain').clientHeight>height) { height = $('contentMain').clientHeight; }
    if ($('navPanel')) if ($('navPanel').clientHeight>height) { height = $('navPanel').clientHeight; }
    $('container').style.height = height + "px";
  }
  else {
    var bottombox;
    var top = 0;
    if ($('storyAddress')) if (findPos($('storyAddress'))[1] > top) { bottombox = $('storyAddress'); top = findPos($('storyAddress'))[1]; }
    if ($('storyAddress1')) if (findPos($('storyAddress1'))[1] > top) { bottombox = $('storyAddress1'); top = findPos($('storyAddress1'))[1]; }
    if ($('storyAddress2')) if (findPos($('storyAddress2'))[1] > top) { bottombox = $('storyAddress2'); top = findPos($('storyAddress2'))[1]; }
    if ($('storyContact')) if (findPos($('storyContact'))[1] > top) { bottombox = $('storyContact'); top = findPos($('storyContact'))[1]; }
    if ($('storyContact1')) if (findPos($('storyContact1'))[1] > top) { bottombox = $('storyContact1'); top = findPos($('storyContact1'))[1]; }
    if ($('storyContact2')) if (findPos($('storyContact2'))[1] > top) { bottombox = $('storyContact2'); top = findPos($('storyContact2'))[1]; }
    if (bottombox) {
      $('container').style.height = findPos(bottombox)[1] + bottombox.clientHeight - 140 + "px";
    }
    else {
      if ($('IE6')) {
        $('container').style.height = "490px";
      }
    }
  }
}