// <![CDATA[

function assignPopups() {
  if (!document.getElementById) return false;

  var a = document.getElementById('maplink');
  var href = a.href ? a.href : a.getAttribute('href');
  if (!a || !href) return false;

  a.onclick = function() {
    var win = window.open(href, 'mapwindow', 'width=400,height=350');
    return false;
  } 

}


function flash_embed() {

  var f_container = document.createElement('div');
  f_container.id = 'flash_container';
  document.getElementById('wrapper').appendChild(f_container);

  var fl = new FlashObject("/images/photos.swf", "photos", "700", "110", 7, "#fff");
  fl.write('flash_container');
 
}

function assignLinks(id) {

  if (!id) var id = 'navigation';
  var lnks = document.getElementById(id).getElementsByTagName('a');

  var selected;

  for (var i = 0; i < lnks.length; i++) {
    if (lnks[i].parentNode.parentNode.className == 'nav-second' || lnks[i].parentNode.parentNode.className == 'nav-third' || lnks[i].parentNode.id == 'open') {
      continue;
    }

    var sublists = lnks[i].parentNode.getElementsByTagName('ul');

    if (sublists.length > 0) {

      var list = sublists[0];
      if (list.parentNode.className != 'active') {
        list.style.display = 'none';

        lnks[i].onclick = function (list) {
          return function() {
            if (selected) selected.style.display  = selected.style.display == 'none' ? 'block' : 'none';
            if (selected != list) {
              list.style.display = list.style.display == 'none' ? 'block' : 'none';
              selected = list;
            }
            else {
              selected = null;
            }
            return false;
          }
        }(list);
      }
    }
  }

}

document.onclick = function() {
  rep();
}

function rep() {

/*  var de = window.attachEvent ? document.body : document.documentElement;
  var f  = document.getElementById('footer');
  var h  = de.scrollHeight;
  f.style.top = h + 'px';
  alert(f.offsetTop + ', ' + de.scrollHeight); */
  var nav = document.getElementById('navigation');
  var h = getStyle(nav, 'height');

}

function getStyle(el, style) {

  if (!document.getElementById) return;
  var value = el.style[style];
  if (!value) {
    if (document.defaultView) {
      value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
    }
    else if (el.currentStyle) {
      value = el.currentStyle[style];
    }
  }
  return value;
}

// window.addEventListener ? window.addEventListener('load', assign, false) : window.attachEvent('onload', assign);

window.onload = function() {
  assignPopups();
  flash_embed();
  assignLinks();
}

// ]]>