	window.addEvent('domready', function () {
									  
	//alert(window);								  

	size = window.getSize();
	
	$$('.zoom a').each(function (z) {
		var input = z.getParent('div').getElement('input');	
		var zoomtxt = String(input.value);
		z.addEvent('click', function(e){
			if(e) new Event(e).stop();
			if(this.getParent('div').getParent('span').getParent('div').getProperty('id')=="RSid"){
				$('Lzoom').set('html', zoomtxt);
				$('Lzoom').setStyle('visibility','visible');
			}else{
				$('Rzoom').set('html', zoomtxt);
				$('Rzoom').setStyle('visibility','visible');
			}
		});
		z.addEvent('mouseleave', function(e){
			if(this.getParent('div').getParent('span').getParent('div').getProperty('id')=="RSid"){
				$('Lzoom').setStyle('visibility','hidden');
			}else{
				$('Rzoom').setStyle('visibility','hidden');
			}
		});
	});

	if($('next')){
		var next = $('next').getProperty('href');
		if($('RTxt')){
			$('RTxt').addEvent('click', function(event){
				self.location.href = next;		
			})		
		}else if($('IndexRTxt')){
				$('IndexRTxt').addEvent('click', function(event){
					self.location.href = next;		
				})			
		}else if($('BGR')){
				$('BGR').addEvent('click', function(event){
					self.location.href = next;		
				})			
		}else{
			$('BRG_img').addEvent('click', function(event){
				self.location.href = next;		
			})
		}
	}
	if($('previous')){
		var previous = $('previous').getProperty('href');
		if($('LTxt')){
			$('LTxt').addEvent('click', function(event){
				self.location.href = previous;		
			})
		}else if($('IndexLTxt')){
				$('IndexLTxt').addEvent('click', function(event){
					self.location.href = previous;		
				})			
		}else{
			$('BGL').addEvent('click', function(event){
				self.location.href = previous;		
			})
		}
	}

	if($('RQuote')){
		q = $('RQuote').getElement('input').value;
		c=0;imgx=0;imgy=0;
		sdx = (Math.random()*2)+1;
		sdy = ((Math.random()*3)-1)/2;
		$('BGR').setStyle('position', 'absolute');
		var addCount = function(){ 
			if(c++<q.length){t=q.substring(0,c);$('RQuote').set('text', t);}
			imgx -= sdx;imgy -= sdy;
			if (Math.round(Math.random()*10) == 0){sdy = ((Math.random()*3)-1)/2;}
			if (imgy>0){imgy = 0;}
			if (imgy<(490-600)){imgy = 490-600;}
			if (imgx<(360-900)){imgx += sdx;sdx = -((Math.random()*2)+1);}
			if (imgx>0){imgx+=sdx;sdx=(Math.random()*2)+1;}
			$('BRG_img').setStyle('left', imgx);
			$('BRG_img').setStyle('top', imgy);
		};
		addCount.periodical(100);
	}
	
    scherm = window.getSize();
    if ($('selected')) {
        var myValues = $('selected').getPosition();
        var half = window.innerHeight / 2
        $('doc').scrollTo(0, (myValues.y - half + 7));
    }
	var z=100;
	$$('#PostIts div').each(function (e) {
		var myDrag = new Drag(e).attach();
		e.addEvent('click', function(){this.setStyle('z-index',z++);});
									  
		/*							  
		var myDrag = new Drag(drag).detach(); //The Element can't be dragged.
			drag.addEvent('click', function(){
				this.setStyle('z-index',z++);							
				myDrag.attach();
			});
		*/					  
									  
        /*new Drag(drag, {
            snap: -60,
            onSnap: function (el) {
				el.setStyle('z-index',z++);
                el.addClass('dragging');
            },
            onComplete: function (el) {
                el.removeClass('dragging');
            }
        });*/
		
    });

    $$('#doc > #container > div > a').each(function (but, i) {
        but.addEvent('mouseover', function (e) {
            temp = "nog niks";
            txts = this.getParent('div').getChildren('input');
            pgs = txts[0].value;
            tit = txts[1].value;
            $('tip').set('html', '<div><p>' + pgs + '</p><h3>' + tit + '</h3></div>');
        })
        but.addEvent('mouseleave', function (e) {
            $('tip').set('html', '');
        })
    })

    $$('#doc > #container > div > a > img').each(function (img, n) {
        img.addEvents({
            'mouseover': function () {
                src = this.getProperty('src');
                if (src.contains('chap_left')) this.setProperty('src', 'img/p_hov_chap_left.gif');
                if (src.contains('chap_right')) this.setProperty('src', 'img/p_hov_chap_right.gif');
                if (src.contains('wit_left')) this.setProperty('src', 'img/p_hov_left.gif');
                if (src.contains('wit_right')) this.setProperty('src', 'img/p_hov_right.gif');
                if (src.contains('sel_left')) this.setProperty('src', 'img/p_hov_left.gif');
                if (src.contains('sel_right')) this.setProperty('src', 'img/p_hov_right.gif');
            },
            'mouseleave': function () {
                this.setProperty('src', src);
            }
        });

    })
	
		$$('.lb').each(function(but,n){
			
			but.addEvent('click',function(e){
				if(e) new Event(e).stop(); //dan wordt dit niet als href gebruikt
					href = but.getProperty('href');
					$('lightbox').setStyles({'display': 'block',
										  'position':'fixed',
										  'top':'0',
										  'left':'0',
										  'text-align':'center',
										  'width':size.x,
										  'height':size.y,
										  //'background':'url("img/back.png")',
										  'z-index':'4'});
					if(href.contains('mp4')){
						$('lightbox').set('html', '<table align="center" height="100%"><tr><td height="100%" valign="middle"><EMBED style="background:transparent;" id="video" SRC=\"QT/'+href+'\"></EMBED></td></tr></table><div id=\"lb\">&nbsp;</div>');
						embed = $('lightbox').getElement('embed');
						embed.setStyles({
										'height':'376px',
										'width' : '480px',
										'position':'relative',
										'z-index':'5'
										});
					}else{	
						parDiv = but.getParent('div');
						file = parDiv.getChildren('input');
						path = file[0].value;
						filename= file[1].value;
						$('lightbox').setStyle('display','block');
						$('lightbox').set('html', '<table align="center" height="100%"><tr><td height="100%" valign="middle"><a href="javascript:si(\''+path+'\',\''+filename+'\')"><img id="lb_img" src="'+href+'"></a></td></tr></table><div id=\"lb\">&nbsp;</div>');	
						image = $('lightbox').getElement('img');
						image.setStyles({
										'max-height':size.y,
										'position':'relative',
										'z-index':'5'
										});
					}
					if($('video'))$('video').addEvent('click',function(){})	
					if($('image'))$('image').addEvent('click',function(){$('lightbox').setStyle('display', 'none');})	
					$('lb').addEvent('click',function(){
						$('lightbox').setStyle('display', 'none');
					})	
		})
		
		})
					

});

function getTheStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

load_slide=function(src){
		$('pl').setStyle('z-index', '3');
		//$('pl').set('html', '<img src="/site/lib/preloader.gif" />');
		var once=false;

		var im= new Asset.image(src,{'width':'100%','height':'',
			onload: function(){
				if(once){
					return;
				}else{
					once = true;
					this.swapSrc(im);
				}
			}.bind(this)
		})
}	

getsize=function(pt, fn){
		var once=false;
		$('lightbox').setStyle('display','none');
		$('pp').setStyle('display','block');
		$('pp').setStyle('top','0');
		$('iw').set('html', '<img src="'+pt+fn+'" id="iw_img">');
		var myImage = new Asset.image(pt+fn, {id: 'image', 
			onload:	function(){
				if(once){
					return;
				}else{
					once = true;
					myImageWidth = $('iw_img').getStyle('width').toInt();
					myImageHeight = $('iw_img').getStyle('height').toInt();
					//alert(myImageWidth+"--"+myImageHeight);
					if(myImageWidth>size.x || myImageHeight>size.y){
						$('iw').setStyle('top','0px');						
						$('pp').addEvents({
							'mouseup':function(e){sp(e);},'mousemove':function(e){sp(e);},
							'click':function(e){$('pp').removeEvents();$('pp').setStyle('display','none');$('iw').setStyle('top','-10000px');}
						});
					}else{
						$('pp').removeEvents();$('pp').setStyle('display','none');
					}
				}
			}
		});
}

function si(pt, fn){
	getsize(path,filename);
}

function sp(e){
    w=$('pp').getStyle('width').toInt();h=$('pp').getStyle('height').toInt();if(w==100){gs();}
    var iw=myImageWidth;var ih=myImageHeight;
	
    if(iw){
        $('iw').setStyle('left',((iw>w)?((e.client.x/w)*(w-iw)):((w-iw)/2)));
        $('iw').setStyle('top',((ih>h)?((e.client.y/h)*(h-ih)):((h-ih)/2)));
    }
}
function gs() {
    // IE patch
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    w = window.innerWidth;
    h = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    w = document.documentElement.clientWidth;
    h = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    w = document.body.clientWidth;
    h = document.body.clientHeight;
  }
 return Array(w, h);
}

