
var clipTop = 0;
var clipWidth = 240;
var clipBottom = 593; // match this height with agendalayer!
var topper = 0;
var lyrheight = 0;
var time,amount,theTime,theHeight,DHTML;

function initScroller()
{
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	var x = new getObj('agendalayer');
	if (document.layers)
	{
		lyrheight = x.style.clip.bottom;
		lyrheight += 20;
		x.style.clip.top = clipTop;
		x.style.clip.left = 0;
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
	}
	else if (document.getElementById || document.all)
	{
		lyrheight = x.obj.offsetHeight;
		x.style.clip = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' 0)'
	}
}

function scrollayer(layername,amt,tim)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	amount = amt;
	theTime = tim;
	realscroll();
}

function toStart(layername)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);                                                                        
	if (!thelayer) return;
		
	amount = 0;
	clipTop = 0;
	topper = 0;
	clipBottom = 593;	
	
	theTime = 0;
	realscroll();
}

function toEnd(layername)
{
	if (!DHTML) return;
	thelayer = new getObj(layername);
	if (!thelayer) return;
	
	amount = 0;
	
	if (lyrheight > 593)
	{
		clipTop = (lyrheight-593);
		topper = (593-lyrheight);
	}
	
	clipBottom = lyrheight;	
	theTime = 0;

	realscroll();
}

function realscroll()
{
	if (!DHTML) return;
	clipTop += amount;
	clipBottom += amount;
	topper -= amount;
	
	if (clipTop < 0 || clipBottom > lyrheight)
	{
		clipTop -= amount;
		clipBottom -= amount;
		topper += amount;
		return;
	}
	
	if (document.getElementById || document.all)
	{
		clipstring = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' 0)'
		thelayer.style.clip = clipstring;
		thelayer.style.top = topper;
		
	}
	else if (document.layers)
	{
		thelayer.style.clip.top = clipTop;
		thelayer.style.clip.bottom = clipBottom;
		thelayer.style.top = topper;
	}
	
	time = setTimeout('realscroll()',theTime);
}

function stopscroll()
{
	if (time) clearTimeout(time);
}


/* 
	"micro" api ... zie http://www.quirksmode.org/js/layerscroll.html
*/

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}



/* 

	VOOR LICHTKRANT

*/
function lichtbalk(id, w, h, sp, pa) {
  this.id=id; this.el = document.getElementById? document.getElementById(id): null; 
  if (!this.el) return; this.css = this.el.style; 
  this.css.left = this.x = 0; this.css.top = this.y = 0;
  this.w=w; this.h=h; this.num=2;
  this.ctr=0; // pause onload
  this.pause=1000; this.speed=30;
  this.lastTime = new Date().getTime(); this.check = 0;
  this.active = true;
  this.index = 0;  balken.ar[0] = this;
  this.speed = sp; this.pause = pa;
}

lichtbalk.prototype.controlScroll = function() {
  if (this.ctr <= 1) {
        if (this.x > -this.w * this.ctr) { 
    			var nx = this.x + -1 * this.elapsed/1000 * this.speed;
          nx = Math.max(nx, -this.w * this.ctr);
          this.shiftTo(nx, 0);	
    		} else this.doPause();
	}
}

lichtbalk.prototype.doPause = function() {
  this.check += this.elapsed;
  if (this.check >= this.pause) { this.ctr++; this.check = 0; }
}

lichtbalk.prototype.shiftTo = function(x, y) {
  this.css.left = (this.x = x) + "px";
  this.css.top = (this.y = y) + "px";
}

balken = {};  
balken.ar = [];
balken.callRate = 5;
balken.timer = window.setInterval("balken.control()", balken.callRate);
balken.control = function() {
  var curObj, now;
  curObj = balken.ar[0];
    if ( curObj != null && curObj.active ) {
      now = new Date().getTime();
      curObj.elapsed = now - curObj.lastTime;
      curObj.lastTime = now; curObj.controlScroll();
    }
}

balken.GeckoTableFix = function() {
  var i, wndo, holderId, holder, x, y;
	if ( navigator.userAgent.indexOf("Gecko") > -1 && navigator.userAgent.indexOf("Firefox") == -1 ) {
    balken.hold = []; 
    for (i=0; arguments[i]; i++) {
      wndo = document.getElementById( arguments[i] );
      holderId = wndo.parentNode.id;
      holder = document.getElementById(holderId);
      document.body.appendChild( holder.removeChild(wndo) );
      wndo.style.zIndex = 1000;
      x = holder.offsetLeft; y = holder.offsetTop;
      wndo.style.left = x + "px"; wndo.style.top = y + "px";
      balken.hold[i] = [ arguments[i], holderId ];
    }
   window.addEventListener("resize", balken.rePosition, true);
  }
}

balken.rePosition = function() {
  var i, wndo, holder, x, y;
  if (balken.hold) {
    for (i=0; balken.hold[i]; i++) {
      wndo = document.getElementById( balken.hold[i][0] );
      holder = document.getElementById( balken.hold[i][1] );
      x = holder.offsetLeft; y = holder.offsetTop;
      wndo.style.left = x + "px"; wndo.style.top = y + "px";
    }
  }
}

function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}

balken.unHook = function() {
  var curObj;
  curObj = balken.ar[0];
    if ( curObj != null && curObj.el ) { 
      curObj.el.onmouseover = null;
      curObj.el.onmouseout = null;
      curObj.el = null;
    }
}

if ( window.addEventListener ) window.addEventListener( "unload", balken.unHook, true);
else if ( window.attachEvent ) window.attachEvent( "onunload", balken.unHook );


function adres(s) { location.href= 'mailto:'+s+'@filmmuseum.nl'; }

