sfHover = function() {
  var sfEls = document.getElementById("bluehousemenu").getElementsByTagName("LI");
  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    }
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    }
  }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function showContent(id) {
  var element = document.getElementById(id);
  var attribute = element.getAttribute('style');

  //Check if the user is browsing with the most ridiculous browser on earth (IE), if so do the attribute check again - the inane IE way
  if (typeof(attribute) == 'object') {
    var attribute = element.style.getAttribute('display');
    var theMatch = 'none';
  }
  else {
    var theMatch = 'display: none;'
  }

  if (attribute.match(theMatch)) {
    Effect.SlideDown(id);
  }
  else {
    Effect.SlideUp(id);

  }
}

function showMainContent(id,type,reorder) {
  var element = document.getElementById(id);
  var attribute = element.getAttribute('style');

  //Check if the user is browsing with the most ridiculous browser on earth (IE), if so do the attribute check again - the inane IE way
  if (typeof(attribute) == 'object') {
    var attribute = element.style.getAttribute('display');
    var theMatch = 'none';
  }
  else {
    var theMatch = 'display: none;';
    //IE 8 does things another way...
    var theMatchIE8 = 'DISPLAY: none';
  }
  if (type == 'project') {
    var type = 'resident';
  } else {
    var type = 'project';
  }
  if (attribute.match(theMatch) || attribute.match(theMatchIE8)) {
    if (type == 'project') {
      var prefix = 'resident';
      var start = 9;
    } else {
      var prefix = 'project';
      var start = 8;
    }
    var parentElement = document.getElementById(prefix+"s_list");
    var childElement = document.getElementById(prefix+"container-"+id.substr(start));
    var oldNodeList = jQuery("ul#"+prefix+"s_list li");
    oldNodeList[0].style.marginBottom = '0px';
    var oldChild = parentElement.removeChild(childElement); 
    var nodeList = parentElement.childNodes;
    parentElement.insertBefore(oldChild, nodeList[0]);
    nodeList[0].style.marginBottom = '45px';
    var newNodeList = jQuery("ul#"+prefix+"s_list li");
    newNodeList[1].style.borderTop = '1px solid #CCCCCC';    
    var elementVisible = jQuery("ul#"+prefix+"s_list li ."+prefix+"_body:visible");
    if (elementVisible.parent().attr("id")) {
      if (prefix == "resident") {
        var substrValue = 18;
      } else {
        var substrValue = 17;
      }
      var bodyId = elementVisible.parent().attr("id").substr(substrValue);
      Effect.SlideUp(prefix+"-"+bodyId);
    }
   
    var oldChild = parentElement.removeChild(childElement); 
    var nodeList = parentElement.childNodes;
    parentElement.insertBefore(oldChild, nodeList[0]);
    if (reorder != '') {
      jQuery("ul#"+type+"s_list li").css("margin-bottom","0");
      var nodeList = jQuery("ul#"+type+"s_list li");
      nodeList[0].style.borderTop = '1px solid #CCCCCC';    
      var reorder = reorder.split(",");
      var parentElement = document.getElementById(type+"s_list");
      var i=0;
      for (i=0;i<=reorder.length-1;i++) {
        var childElement = document.getElementById(type+"container-"+reorder[i]);
        var oldChild = parentElement.removeChild(childElement);
        oldChild.setAttribute('moved',"movedup");
        var nodeList = parentElement.childNodes;
        parentElement.insertBefore(oldChild, nodeList[0]);
        if (i == 0) {
          oldChild.style.marginBottom = '45px';
        }        
      }
    }
    Effect.SlideDown(id);
//    scroll(0,0);
//	scrollTo(0,0);
	 goto_top()
  }
  else {
    if (reorder != '') {
      var oldNodeList = jQuery("ul#"+type+"s_list li");
      oldNodeList[0].style.marginBottom = '0px';
      oldNodeList[0].style.borderTop = '1px solid #CCCCCC';    
      var reorder = reorder.split(",");
      var i=0;
      for (i=0;i<=reorder.length-1;i++) {
        var childElement = document.getElementById(type+"container-"+reorder[i]);
        childElement.removeAttribute('moved');
        console.log('test');
      }
    }
    Effect.SlideUp(id);
  }
}

function openLinks() {
  jQuery(document).ready(function() {
     jQuery("a[href^=http]").each(function(){
        if(this.href.indexOf(location.hostname) == -1) {
           jQuery(this).attr({
              target: "_blank",
              title: "Opens in a new window"
           });
        }
     })
  });
}

jQuery(document).ready(function() {
  openLinks();
});

/*
function showMainContent(id,type,reorder) {
  var element = document.getElementById(id);
  var attribute = element.getAttribute('style');

  //Check if the user is browsing with the most ridiculous browser on earth (IE), if so do the attribute check again - the inane IE way
  if (typeof(attribute) == 'object') {
    var attribute = element.style.getAttribute('display');
    var theMatch = 'none';
  }
  else {
    var theMatch = 'display: none;';
    //IE 8 does things another way...
    var theMatchIE8 = 'DISPLAY: none';
  }
  if (type == 'project') {
    var type = 'resident';
  } else {
    var type = 'project';
  }
  if (attribute.match(theMatch) || attribute.match(theMatchIE8)) {
    if (type == 'project') {
      var prefix = 'resident';
      var start = 9;
    } else {
      var prefix = 'project';
      var start = 8;
    }
    var parentElement = document.getElementById(prefix+"s_list");
    var childElement = document.getElementById(prefix+"container-"+id.substr(start));
    var oldNodeList = jQuery("ul#"+prefix+"s_list li");
    oldNodeList[0].style.marginBottom = '0px';
    var oldChild = parentElement.removeChild(childElement); 
    var nodeList = parentElement.childNodes;
    parentElement.insertBefore(oldChild, nodeList[0]);
    nodeList[0].style.marginBottom = '45px';
    var newNodeList = jQuery("ul#"+prefix+"s_list li");
    newNodeList[1].style.borderTop = '1px solid #CCCCCC';
    if (reorder != '') {
      var oldNodeList = jQuery("ul#"+type+"s_list li");
      oldNodeList[0].style.marginBottom = '0px';
      oldNodeList[0].style.borderTop = '1px solid #CCCCCC';

      var reorder = reorder.split(",");
      var parentElement = document.getElementById(type+"s_list");
      var i=0;
      for (i=0;i<=reorder.length-1;i++) {
        var childElement = document.getElementById(type+"container-"+reorder[i]);
        var oldChild = parentElement.removeChild(childElement);
        oldChild.setAttribute('moved',"movedup");
        var nodeList = parentElement.childNodes;
        parentElement.insertBefore(oldChild, nodeList[0]);
        if (i == 0) {
          oldChild.style.marginBottom = '45px';
        }
      }
    }
    Effect.SlideDown(id);
//    scroll(0,0);
//	scrollTo(0,0);
	 goto_top()
  }
  else {
    if (reorder != '') {
      var reorder = reorder.split(",");
      var i=0;
      for (i=0;i<=reorder.length-1;i++) {
        var childElement = document.getElementById(type+"container-"+reorder[i]);
        childElement.removeAttribute('moved');
      }
    }
    Effect.SlideUp(id);
  }
}
*/