var Fullscreen = new FullscreenC();
var fsVars = new FullscreenVars();

function FullscreenC() { }

function FullscreenVars() {
  this.show = true;
  this.fullscreenText = 'Vollbild';
  this.normalscreenText = 'Normalbild';
  this.urlToFullScreen = "/fullscreen.php";
}

FullscreenC.prototype.show = function (name) {
  if (!fsVars.showing) {

    setNonstaticAncestors(name);
    nonstaticAncestors.each(function(el){el.removeClassName('relative')})
    $(name).className='fullscreen';
    this.oldWidth = $(name).getStyle('width');
    this.oldHeight = $(name).getStyle('height');
    this.oldMarginTop = $(name).getStyle('margin-top');
    $(name).setStyle({position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', marginTop: 0 })
    map.checkResize();
    document.body.scrollTo(name);
    document.body.setStyle({height: $(name).getHeight(), overflow: 'hidden'})
    $('fullscreenButton').innerHTML = fsVars.normalscreenText;
    map.enableScrollWheelZoom();
    fsVars.showing = true;
  }
  else {
    this.hide(name);
  }
}

FullscreenC.prototype.hide = function (name) {
  document.body.setStyle({height: 'auto', overflow: 'visible'})
  nonstaticAncestors.each(function(el){el.addClassName('static')});
  $(name).className=('normal');
  $(name).setStyle({position: 'relative', top: 'auto', left: 'auto', width: this.oldWidth, height: this.oldHeight, marginTop: this.oldMarginTop});
  $('fullscreenButton').innerHTML = fsVars.fullscreenText;
  map.disableScrollWheelZoom();
  fsVars.showing = false;

}

var nonstaticAncestors = new Array();

function setNonstaticAncestors (name) {
  var ancestors = $(name).ancestors();
  ancestors.each(function(el){
    if (el.getStyle('position')!="static") {
      nonstaticAncestors.push(el);
    }
  })
}
