/* behavioursLB.js
Theme: AOSurgery2008-P6
update 2009-11-10 (rsc) 
update 2009-12-07 (msc) key navi now in IE too 

Functions used in the lightboxes
*/

/* Reloading the parent of the lightbox */
function reloadParentWindow (linkToLoad) { 
	parent.location.href = linkToLoad; 
}

// focus window to catch keyevents
window.onload = function() {
  window.focus();
}

/* 
 * navigate with arrow keys / quit window
 *
 * checks if button elements is available and if so
 * take it's href and reload the location
 */
window.document.onkeydown = function(e) {
  // stupid IE.
  if (!e) {
    var e = window.event;
  }
  var keycode = e.keyCode || e.which;

  switch(keycode) {
    // ESC close iframe
    case 27:
      closeThisLB(window.document.getElementById('btnClose').href.match(/'(.*)'/)[1]);
      break
      
    // keyboard navigation
    case 37:
      if (window.document.getElementById('btnPrev') !== null) {
        window.location.href = window.document.getElementById('btnPrev').href
      }
      break
    case 39:
      if (window.document.getElementById('btnNext') !== null) {
        window.location.href = window.document.getElementById('btnNext').href
      }
      break
    default:
      break
  }
}


/* Closing the lightbox and jumping to anchor on opening page (msc) */
function closeThisLB (anchorToJumpTo) { 

	if (anchorToJumpTo != undefined) {

		var parentURL = parent.location.href; /* get URL of LB-Opener */
		parentURL = parentURL.replace(/#[^#]*$/, ''); /* reg ex: cut off everything from # onwards */
		parentURL += anchorToJumpTo; /* append defined anchor to URL */
		
		parent.location.href= parentURL; /* jump to that anchor (no http reload if in cache, which is the case) */
		/* AND */
		parent.myLytebox.end(); /* close that LightBox */
		
		
	} else {		
		/* if  no anchor defined, just close LB without jumping anywhere */
		parent.myLytebox.end();
	}
	
}


