function popup(url, width, height)
{
  width = width == null ? 500 :  width
  height = height == null ? 500 :  height
  x = Math.ceil((screen.width - width) / 2)
  y = Math.ceil((screen.height - height) / 2)
  window.open(url, 'popup', 'width=' + width + ',height=' + height + ',top=' + y + ',left=' + x + ',status=0,scrollbars=1')
}

function externalLinks()
{
  if (!document.getElementsByTagName) {
    return
  }
  var anchor
  var anchors = document.getElementsByTagName('a')
  for (var i = 0; i < anchors.length; i++) {
    anchor = anchors[i]
    targetUrl = anchor.getAttribute('href')
    if ((targetUrl && anchor.getAttribute('rel') == 'external') || (targetUrl && targetUrl.indexOf('http://') != -1 && targetUrl.indexOf('implants') == -1 && targetUrl.indexOf('appletree') == -1)) {
      anchor.target = '_blank'
    }
  }
}

function fixPng()
{
    if (typeof document.body.style.maxHeight != 'undefined') {
        return false
    }
    imgs = document.getElementsByClassName('png')
    for (var i = 0; i < imgs.length; i++) {
        parentTag = imgs[i].parentNode
        parentTag.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgs[i].src + "', sizingMethod='scale');"
        imgs[i].style.visibility = 'hidden'
    }
}

menuOver = function() {
  // run menuOver only for IE < 7
  if (typeof document.body.style.maxHeight != 'undefined' || !$('navigation')) {
    return false
  }
  var listItems = $('navigation').getElementsByTagName('LI')
  for (var i = 0; i < listItems.length; i++) {
    listItems[i].onmouseover = function() { this.className += ' hover' }
    listItems[i].onmouseout = function() { this.className = this.className.replace(new RegExp(' hover\\b'), '') }
  }
}
// run for IE only
if (window.attachEvent) window.attachEvent('onload', menuOver)

function init()
{
  externalLinks()
  fixPng()
  // initialise calendars
  if (typeof calendarInit != 'undefined') {
    backdated = typeof backdatesAllowed != 'undefined' && backdatesAllowed ? true : false
    calendarInit(backdated)
  }
  // avoid "click to activate" on <object> tags in IE
  if (document.all) {
    objs = document.getElementsByTagName('object')
    for (var i = 0; i < objs.length; i++) {
      objs[i].outerHTML = objs[i].outerHTML
    }
  }
  // Google map loader
  if (typeof load == 'function') {
    load()
  }
}

function startGallery()
{
    var myGallery = new gallery(Moo.$('gallery'), {
        timed: true,
        showCarousel: true,
        textShowCarousel: 'thumbnails',
        thumbWidth: 67,
        thumbHeight: 50,
        titleSelector: 'h1',
        showArrows: false,
        showInfopane: false,
        embedLinks: false,
        fadeDuration: 1500,
        delay: slideshow.delay,
        delayStart: slideshow.delayStart
    })
}
if (typeof window.onDomReady == 'function') {
    window.onDomReady(startGallery)
}

onload = init