// touchles javascript™ -- no event handlers in html

window.onload = kickOff;
window.onresize = pageCalc;

var curLeft = 0;
var logoObj;
var aAll;

function kickOff() {
	aAll = document.getElementsByTagName("a");
	// disable and change color of active page's link
    for (var i=0; i<aAll.length; i++) {
        if (window.location.href.split("#")[0] == aAll[i].href) {
            aAll[i].onclick = function() {if (this.blur) {this.blur();} return false;}
            aAll[i].style.cursor = "text";
			aAll[i].style.borderBottom = "none";
			aAll[i].style.color = "#9999aa";
            if (aAll[i].className == "site") {
				aAll[i].style.color = "#ffffff";
           	}
        }
		// fix ie's lack of support for css :focus so tabbers see skip links on focus
		if (navigator.appName == "Microsoft Internet Explorer" && aAll[i].className == "skip") {
			var restoreColor = aAll[i].style.color;
			var restoreBorder = aAll[i].style.borderBottom;
			aAll[i].onfocus = function() {this.style.color = "#999999"; this.style.borderBottom = "1px solid #999999";}
			aAll[i].onblur = function() {this.style.color = restoreColor; this.style.borderBottom = restoreBorder;}
		}
     }
	// fixes in-page link bug for Internet Explorer
	if (navigator.appName == "Microsoft Internet Explorer") {
		getElementsByClass("target");
	}
    // calculate certain elements for placement:
	pageCalc();
}

function findPos() {
	// position logo-aligned bg image relative to window width accounting for browsers' differing def of offsetParent:
	logoObj = document.getElementById("footerbox").firstChild.firstChild;
	if (logoObj.offsetParent) {
		curLeft = logoObj.offsetLeft;
		while (logoObj.offsetParent!=null) {
			logoObj = logoObj.offsetParent;
			curLeft += logoObj.offsetLeft;
		}
	}
	document.getElementsByTagName("body")[0].style.backgroundPosition = curLeft - 649 + "px";
}

function equalCol() {
	// make the column depths match so they have full-height attributes (bg colors, etc):
	var colArray = new Array(["nav",0],["main",0],["sidebar",0]);
	for (var i=0; i<colArray.length; i++) {
		// everyone expresses their natural column heights:
		document.getElementById(colArray[i][0]).style.height = "100%";
		// detect natural column heights in px and store in the array:
		colArray[i][1] = document.getElementById(colArray[i][0]).offsetHeight;
	}
	// determine tallest column in the array:
	var tallCol = Math.max(colArray[0][1],colArray[1][1],colArray[2][1]);
	// make all columns the height of the tallest column:
	for (var i=0; i<colArray.length; i++) {
		document.getElementById(colArray[i][0]).style.height = tallCol + "px";
	}
}

function pageCalc() {
	// position logo-aligned bg image relative to window width:
	findPos();
	// make the column depths match so they have full-height attributes:
	equalCol();
}

function getElementsByClass(searchClass,node,tag) {
	// fixes in-page link bug for Internet Explorer; first find all destinations (elements with classname "target"):
    var classElements = new Array();
	if ( node == null ) {
			node = document;
	}
	if ( tag == null ) {
			tag = '*';
	}
	var elAll = node.getElementsByTagName(tag);
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (var i = 0, j = 0; i < elAll.length; i++) {
		if (pattern.test(elAll[i].className)) {
			classElements[j] = elAll[i];
			j++;
		}
	}
	// then insert what is an invalid attribute for most elements, with an invalid value to boot:
	for (var i=0; i<classElements.length; i++) {
		classElements[i].setAttribute("tabIndex",-1)
	}
}

function mapSwitch1(txt, map){
  txt_obj = document.getElementById(txt);
  map_obj = document.getElementById(map);
  var map_val = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=334+mason+street,+san+francisco,+ca+94102&amp;sll=37.0625,-95.677068&amp;sspn=52.107327,64.511719&amp;ie=UTF8&amp;hq=&amp;hnear=334+Mason+St,+San+Francisco,+California+94102&amp;z=14&amp;iwloc=A&amp;ll=37.795881,-122.405205&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=334+mason+street,+san+francisco,+ca+94102&amp;sll=37.0625,-95.677068&amp;sspn=52.107327,64.511719&amp;ie=UTF8&amp;hq=&amp;hnear=334+Mason+St,+San+Francisco,+California+94102&amp;z=14&amp;iwloc=A&amp;ll=37.795881,-122.405205" style="color:#0000FF;text-align:left">View Larger Map</a></small>';

  if (map_obj.style.display == "none") {
         map_obj.style.display = "block";
         document.getElementById('map').innerHTML = map_val;
         txt_obj.innerHTML = "Hide Map";
  } else {
          map_obj.style.display = "none";
          txt_obj.innerHTML = "Show Map";
  }
}

function mapSwitch2(txt_griffon, map_griffon){
  txt_griffon_obj = document.getElementById(txt_griffon);
  map_griffon_obj = document.getElementById(map_griffon);
  var map_griffon_val = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=155+steuart+street+San+Francisco,+ca+94105&amp;sll=37.0625,-95.677068&amp;sspn=52.107327,64.511719&amp;ie=UTF8&amp;hq=&amp;hnear=155+Steuart+St,+San+Francisco,+California+94105&amp;z=17&amp;ll=37.792878,-122.392206&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=155+steuart+street+San+Francisco,+ca+94105&amp;sll=37.0625,-95.677068&amp;sspn=52.107327,64.511719&amp;ie=UTF8&amp;hq=&amp;hnear=155+Steuart+St,+San+Francisco,+California+94105&amp;z=17&amp;ll=37.792878,-122.392206" style="color:#0000FF;text-align:left">View Larger Map</a></small>';

  if (map_griffon_obj.style.display == "none") {
         map_griffon_obj.style.display = "block";
         document.getElementById('map_griffon').innerHTML = map_griffon_val;
         txt_griffon_obj.innerHTML = "Hide Map";
  } else {
          map_griffon_obj.style.display = "none";
          txt_griffon_obj.innerHTML = "Show Map";
  }
}

function mapSwitch3(txt_inn, map_inn){
  txt_inn_obj = document.getElementById(txt_inn);
  map_inn_obj = document.getElementById(map_inn);
  var map_inn_val = '<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=440+Post+Street,+San+Francisco,+CA+94102&amp;sll=37.785714,-122.413214&amp;sspn=0.051281,0.063&amp;ie=UTF8&amp;hq=&amp;hnear=440+Post+St,+San+Francisco,+California+94102&amp;z=17&amp;ll=37.788218,-122.409112&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=440+Post+Street,+San+Francisco,+CA+94102&amp;sll=37.785714,-122.413214&amp;sspn=0.051281,0.063&amp;ie=UTF8&amp;hq=&amp;hnear=440+Post+St,+San+Francisco,+California+94102&amp;z=17&amp;ll=37.788218,-122.409112" style="color:#0000FF;text-align:left">View Larger Map</a></small>';

  if (map_inn_obj.style.display == "none") {
         map_inn_obj.style.display = "block";
         document.getElementById('map_inn').innerHTML = map_inn_val;
         txt_inn_obj.innerHTML = "Hide Map";
  } else {
          map_inn_obj.style.display = "none";
          txt_inn_obj.innerHTML = "Show Map";
  }
}
