//web.js by David Lantner for dave's domain v4
Event.observe(window,'load', function(){
  var divs = document.getElementsByTagName('div');
  for (var i=0; i<divs.length; i++) {
    // W3C uses "class", IE uses "className" so we check for each:
    if (divs[i].getAttribute('class') == 'more' || divs[i].getAttribute('className') == 'more') {
	  // hide the divs with class 'more':
	  var divId = divs[i].getAttribute('id');
	  new Effect.toggle(divId, 'slide');
	}
    if (divs[i].getAttribute('class') == 'site' || divs[i].getAttribute('className') == 'site') {
	  // add link to show divs with class = 'more':
	  var a = document.createElement('a');
	  a.setAttribute('href','#');
	  a.setAttribute('class','toggle');
	  a.setAttribute('className','toggle'); // for IE
	  a.setAttribute('id','a' + divs[i].getAttribute('id') + '-more');
	  a.setAttribute('title','Expand to view more details or collapse it out of view');
	  a.appendChild(document.createTextNode('Show description'));
	  a.onclick = toggleMore; // IE requires a function, so we must use this approach, rather than setAttribute('onclick', ... )
	divs[i].appendChild(a);
    }
  }
  
  function toggleMore(e) { // with thanks to http://www.quirksmode.org/js/events_access.html
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode; // for Safari
    new Effect.toggle(targ.getAttribute('id').slice(1), 'slide');
    if(targ.firstChild.nodeValue == 'Show description') targ.firstChild.nodeValue = 'Hide description';
    else targ.firstChild.nodeValue = 'Show description';
    return false;
  }
});

