document.observe('dom:loaded', function() {
  // if (secure?)
  if ( document.location.href.indexOf('secure_login') < 0) {
    var i = $$('iframe.login_box')[0];
    if (i) {
      i.observe('load', function (ev) {
        i.stopObserving('load');
        i.observe('load', function (ev) { 
          $$('span.just_logged_out').each( function (e) { e.hide(); } );
          setTimeout(function (ev) {
            uri = rootURI(window.location);
            if ($('redirect_uri'))
              window.location = uri.substr(0, uri.length - 1) + $('redirect_uri').innerHTML; 
            else
              window.location = uri;
          }, 750); 
        });
      });
    }
  }
  else {
    // if (!parent?)
    if (parent.window.location.href.indexOf('secure_login') < 0) {
      bindLock();
      if (parent.window.location.pathname != '/')
        $('flash_notice').hide();
    }
    else
      $$('.secure_login table').each( function(e) { e.hide(); } );
      // $$('body')[0].childElements().each( function(e) { e.hide(); } );
  }
});

function bindLock () {
  // var s = frames['secure_login'].document.getElementById('siteseal');
  if ($$('a.lock')[0]) {
    $$('a.lock')[0].observe('mouseover', function (ev) {
      $('siteseal').setStyle({
        display : 'block',
        position : 'absolute',
        top : Event.pointerY(ev),
        left : Event.pointerX(ev) - $('siteseal').getWidth()
      });
      setTimeout(function (ev) { $('siteseal').setStyle({ display : 'none' }); }, 2000);
    });
  }
}
