/* scripts for katz.khopesh.com
 * toggle banner, jump around in page */

/** dtog : Sting -> VOID
  * toggle the display of explicitly declared child elements */
function dtog (parent) {
  var obj=document.getElementById(parent);
  if(obj.innerHTML.indexOf('display: none',0)>0) {
    obj.innerHTML=obj.innerHTML.replace(/display: none/,'display: block');
    obj.innerHTML=obj.innerHTML.replace(/[a-z]* menu/,'hide menu');
  } else {
    obj.innerHTML=obj.innerHTML.replace(/display:[ a-z]*/,'display: none');
    obj.innerHTML=obj.innerHTML.replace(/[a-z]* menu/,'show menu');
  }
}

/** vtog : Sting -> VOID
  * toggle the display of explicitly declared child elements */
function vtog (parent) {
  var obj=document.getElementById(parent+"word");
  var inner=document.getElementById(parent+"target");
  var justtog=false;
  if(obj==inner) { justtog=true; inner=document.getElementById(parent); }
  if(inner.style.visibility=="hidden") {
    inner.style.visibility="visible";
    if(justtog) 
      { inner.style.height="inherit"; }
      else { obj.innerHTML=obj.innerHTML.replace(/[a-z]* menu/,'hide menu'); }
  } else {
    inner.style.visibility="hidden";
    if(justtog) 
      { inner.style.height="0"; }
      else { obj.innerHTML=obj.innerHTML.replace(/[a-z]* menu/,'show menu'); }
  }
}


var oldbrowser=false; // need to put a test in here
var SIVsupport=true; // scrollIntoView support will be tested before use

/** jumpTo : String -> VOID
  * scrolls browser view to the object passed by name */
function jumpTo(where) { 
  if(document.getElementById) {
    var element=document.getElementById(where);
    if(element.scrollIntoView) { // find out whether SIV really exists
      element.scrollIntoView(true);
    } else {
      // this is untested; mozilla now supports scrollIntoView()
      SIVsupport=false;
      element.HTMLElement_scrollIntoView();
      // if you care enough to have investigated a problem 
      // with your old/odd browser and have a solution/tip
      // then please email me at webmaster+scripts@khopesh.com
      // and PLEASE include the address for this page!
    }
  } else { document.location.href="#"+where; }
  return false // prevent href="#..." part of <a> from happening
}

/* the following creates scrollIntoView() for browsers that do not have it
   original taken 2002/05/24 from:
   http://www.faqts.com/knowledge_base/view.phtml/aid/8554/fid/128
   comments are mine 

   ATTENTION CUT+PASTE PEOPLE! please note that this is
   NOT completely independent of the above functions;
   please use jumpTo() rather than scrollIntoView() */

/** HTMLElement_getPageCoords : VOID (method call) -> Object
  * finds and returns the coordinates of the object called from  */
function HTMLElement_getPageCoords () {
  var coords = {x: 0, y: 0}; var el = this;
  do {
    coords.x += el.offsetLeft;
    coords.y += el.offsetTop;
  } while ((el = el.offsetParent));
  return coords;
}

/** HTMLElement_scrollIntoView : VOID (method call) -> VOID
  * scrolls browser view to the object called from  */
function HTMLElement_scrollIntoView () {
  var coords = this.getPageCoords();
  window.scrollTo (coords.x, coords.y);
}
if(!SIVsupport) { // only set this if needed
  HTMLElement.prototype.scrollIntoView = HTMLElement_scrollIntoView;
}

