window.onload=init;

function init() {
	var actie = document.getElementById('actie');
	if (actie) {
		actie.style.position='absolute';
		
		var ph = actie.parentNode.parentNode.parentNode.offsetHeight;
		var pt = actie.parentNode.parentNode.parentNode.offsetTop;
		var h = actie.offsetTop;
		//alert(ph+' '+h+' '+actie.parentNode.parentNode.tagName);
		//actie.style.marginTop=((ph-h)-actie.offsetHeight)+'px';
		actie.style.top=(pt+(ph-actie.offsetHeight))+'px';

		actie.style.visibility='visible';
	}
	
	//var t = document.getElementById('top');
	
}

var rotateimages=new Array;
var rotateidx=0;

function _rotate() {
	var r = document.getElementById('rotate');
	while (r.childNodes.length>0)
		r.removeChild(r.childNodes[0]);
	for (var i=0;i<4;i++) {
		r.appendChild(rotateimages[rotateidx--]);
		if (rotateidx<0) rotateidx=rotateimages.length-1;
		if (rotateidx>=rotateimages.length) rotateidx=0;
	}
	setTimeout('_rotate()',5000);
}

function clickrotate() {
	var m = this.src.match(/([a-z0-9]+).jpg/);
	var d = document.getElementById('rotatepopup');
	if (d) d.parentNode.removeChild(d);
	
	var midden = document.getElementById('content');

	d = document.createElement('IMG');
	d.id = 'rotatepopup';
	d.src = 'images/'+m[1]+'.jpg';
	d.style.cursor='pointer';
	d.onclick=function() { fadedir(this,10,-1); }
	//d.onclick=function() { this.parentNode.removeChild(this); }
	midden.appendChild(d);
	setTimeout('clickrotatecheck()',50);
}

function clickrotatecheck() {
	var d = document.getElementById('rotatepopup');
	if (d) {
		if (d.width==0) setTimeout('clickrotatecheck()',50);
		else  {
			//alert(d.parentNode.offsetWidth+' '+d.width+' '+(d.parentNode.offsetWidth-d.width));
			var w = self.innerWidth ? self.innerWidth : document.body.clientWidth;
			d.style.left=((w-d.width)/2)+'px';
			fadedir(d,0,1);
			d.style.visibility='visible';
		}
	}
}

function rotate(imgs) {
	var imgs = imgs.split(',');
	for (var i=0;i<imgs.length;i++) {
		var img = document.createElement('IMG');
		img.src='images/thumb_'+imgs[i];
		img.onclick=clickrotate;
		img.style.cursor = 'pointer';
		rotateimages.push(img);
	}
	_rotate();
}

function fadedir(div,op,dir) {
	op+=dir;
	if (op<=10 && op>=0) {
		div.style.opacity=op/10;
		div.style.filter='alpha(opacity='+op*10+')';
		if (op>0 && op<10)
			setTimeout(function() { fadedir(div,op,dir); },25);
	}
	if (op==0) {
		div.parentNode.removeChild(div);
	}
}

function startRes(pKlantNr,pTaalCode) {
	window.open('http://www.virtueelboeken.nl/index.asp?u=' + pKlantNr + '&taal=' + pTaalCode, 'VirtueelBoeken', 'toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=750,height=520,top=50,left=20');
}
