var d = document;        
var nObj = d.getElementById;
var cTN = d.createTextNode;
var cE = d.createElement;
var agt = navigator.userAgent.toLowerCase();
var navSections = new Array("abt","res","agr","comm","prod");

onload = function firstLoad() {
  if((agt.indexOf("msie")!=-1) && (agt.indexOf("opera")<1) && (agt.indexOf("win")!=-1)) styleAbbr()
  if(d.getElementById){ 
    if(d.createTextNode){ expandMsg(); pageWidth(); drawIcon("navSections"); }
  }  
}

/*Get-Set Styles*/
function setStyle(i, p, v) {
  var sObj = d.getElementById(i);
  sObj.style[p] = v;
}

function getStyle(i, p) {
 var sObj = d.getElementById(i);
 var sheets = d.styleSheets;
 if(p == 'n'){ p = 'none'; }
 else if(p == 'b'){ p = 'block'; }


 if(sheets.length > 0) {
  for(var x = 0; x < sheets.length; x++){
   var rules = sheets[x].cssRules;
   if(rules.length > 0) {
    for(var y = 0; y < rules.length; y++) {
     var z = rules[y].style;
     if(((z[p] != "") && (z[p] != null)) && (rules[y].selectorText == "#" + i)) { return z[p]; }
    }
   }
  }  
 } return null;
}

function hideShowEl(i,v) {
  var sObj = d.getElementById(i).style; 
  if(v == "n") sObj.display = "none";
  else if(v == "b") sObj.display = "block";
  else if(v == "i") sObj.display = "inline";
  else if(v == "") hideShowToggle(i,"block")
}

function hideShowList(i,v){
  if(v == "") {
    var sObj = d.getElementById(i); 
    if(sObj.style.display == "none") v = "b";  
    else if(sObj.style.display == "block") v = "n";
  }  
  for(x = 0; x < navSections.length; x++){ hideShowEl(navSections[x],"n"); }
  hideShowEl(i,v)
  if(agt.indexOf("mac") == -1) drawIcon("navSections")
}

/*Left Nav*/
function drawIcon(a){
 if((cTN) && (agt.indexOf("mac") == -1)) {
  var menu = d.getElementById(a);
  var icons = menu.getElementsByTagName("span")
  var icon, blurb, section = ""
  for(x = 0; x < icons.length; x++){
    var hObj = d.getElementById(navSections[x])
  	var iObj = icons[x];
  	var lObj = icons[x].parentNode;
    var section = " what's in \"" + lObj.childNodes[1].nodeValue + "\"";
    if(hObj.style.display == "block"){ icon = "\-"; blurb = "Click to hide" + section; }
    else{ icon = "\+"; blurb = "Click to show" + section;}
  	var tObj = d.createTextNode(icon);
    if(!iObj.hasChildNodes()) iObj.appendChild(tObj)
    else iObj.replaceChild(tObj,iObj.childNodes[0])
    lObj.setAttribute("href","javascript:hideShowList(\"" + navSections[x] + "\",\"\");")
    //lObj.setAttribute("href","javascript:hideShowList(\"" + navSections[x] + "\",\"\");adjustFixMenu()")
    lObj.title = blurb
    hideShowEl(icons[x].id,"i")
  }

  }
}

/*Page sizing*/
function expandMsg(){
  expand = d.createElement("DIV")
  expand.id = "expandMe"
  expand.style.display = "none"
  expand.appendChild(d.createTextNode("Widen your browser for extra content"))
  d.getElementById("flag").appendChild(expand)
}

function pageWidth(){
  //if(agt.indexOf("gecko")!=-1) fontScale();
  if(agt.indexOf("opera")<0){
    pageSizer();
    if(d.getElementById("navigation") && d.defaultView) adjustFixMenu();
  }
}

function pageSizer(){
  if(cE){ 
  if(d.body.clientWidth) { 
    (d.body.clientWidth>600) ? hideShowEl("expandMe","n") : hideShowEl("expandMe","b")
  }
  else if(w.innerWidth) {
    (w.innerWidth<570) ? hideShowEl("expandMe","b") : hideShowEl("expandMe","n")
  } }
}

function styleAbbr() {
  var oldBodyText, newBodyText, reg
  oldBodyText = document.body.innerHTML;
  reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
  newBodyText = oldBodyText.replace(reg, '<abbr $1><span class=\"info\" $1>$2</span></abbr>');
  document.body.innerHTML = newBodyText;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
 // <a href='#' onclick="MM_openBrWindow('http://www.crowsconstruction.ca/imageres/index.htm', 'MAP','location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=675')"><img border="0" src="image/resident.jpg" width="200" height="92" alt="Residential Projects">
  }
