function obscureAddMid() { document.write('&#64;');	}
function obscureAddEnd() { document.write('&#46;'); }
function initTabs() {
	if ($('hometabs')) {
		
		
		var container = $('hometabs');
	    new SimpleTabs(container, {
	        selector: 'h2' 
	    });
	}
}
function timeline() {
	if (!$('tlscroll')) { return true; }
	var totIncrement		= 0;
	var increment			= 130;
	var maxRightIncrement	= $('tlup').get('nheight'); // increment*(-6);
	var fx = new Fx.Tween($('tlscroll'), {duration: 500, transition: 'back:in:out'});
	
	if ($('tlup')) {
		$('tlup').addEvent('click', function() {
		if(totIncrement < 0) {
		    totIncrement += increment;
		    fx.start('margin-top', totIncrement);
		    }
		});
		
		$('tldown').addEvent('click', function() {
		if(totIncrement > maxRightIncrement) {
		    totIncrement -= increment;
		    fx.start('margin-top', totIncrement);
		    }
		});	
	}
}

function slideRelated() {
	var totIncrement		= 0;
	var increment			= 130;
	var maxRightIncrement	= -(($$('#relatedlist li').length * 70) - 200); // -1100; // $('tlup').get('nheight'); // increment*(-6);
	// $('tlup').get('nheight');
	
	 
	//if (($$('#relatedcontainer img').length) < 5) { $('portfoliocontrols').style.visibility='hidden';  }
	//if (($$('#relatedcontainer img').length) == 0) { $('portfoliocontrols').style.display='none'; }
	  
	var fx = new Fx.Tween($('relatedlist'), {duration: 500, transition: 'back:in:out'});
	
	if ($('scrollRight')) {
		$('scrollRight').addEvent('click', function() {
		if(totIncrement < 0) {
		    totIncrement += increment;
		    fx.start('margin-left', totIncrement);
		    // if (totIncrement == 0) { $('tlup').style.visibility="hidden"; }
		    //$('tldown').style.visibility="visible";
		    }
		// else { $('tlup').style.visibility="hidden"; }
		});
		
		$('scrollLeft').addEvent('click', function() {
		if(totIncrement > maxRightIncrement) {
		    totIncrement -= increment;
		    fx.start('margin-left', totIncrement);
		    // if (totIncrement == maxRightIncrement) { $('tldown').style.visibility="hidden"; }
		    // $('tlup').style.visibility="visible";
		    }
		// else { $('tldown').style.visibility="hidden"; }
		});	
		// $('tlup').style.visibility="hidden";
	}
}
function fixLinks() {
	$$('#maincontent p.bodytext a').each(function(element) {
		if (element.href.substr(11, 7).toLowerCase() == "youtube") {
			var vfile=element.href.split("?v=");
			element.href='/sys/video/?vfile='+vfile[1];
			SqueezeBox.assign(element, {handler: 'iframe', size: {x: 640, y: 386}});			
		} 
	});
	SqueezeBox.assign($$('.filelist a.map'), {handler: 'iframe',size: {x: 920, y: 400}});
}
function fixPhotos() {
	// fix contentfoto's, maak er meteen een dropshadow bij.
	var dsFoto = $$('#maincontent p img');
	dsFoto.each(function(item, index) { 
		classDef = (index %2 ==0)? 'even' : 'odd';
		var anchor = new Element('div', {
			'class': 'dsframe dsframe'+classDef,
			'style': 'height:'+((Math.round(item.height/(item.width/180)))+2)+'px;width:190px;font-weight:bold;',
			'html': '<div class="foto"><a class="pzoom" href="'+item.src+'"><img src=\''+item.src+'\' border=\'0\' /></a></div>'
			}).replaces(item);
	});
	
	$$('#maincontent p img').each(function(element) {
        new ReMooz(element, {
            centered: true, 
            'shadow': 'onOpenEnd',
            'resizeFactor': 0.8, 
            origin: element.getElement('img') 
        });
 
    });
    
    
	//SqueezeBox.assign($$('#maincontent p.bodytext img'),{handler: 'iframe', size: {x: 920, y: 400}});
	// uit, wijst nu naar single pagina SqueezeBox.assign($$('#related a.image'));
}

function fillAlfalist() {
	var toggles = $$('.toggler');
	var content = $$('.elements');
	var AccordionObject = new Accordion(toggles, content, {
		show: 0, 
		display: 0,
		height : true,
		width : false,
		opacity: true,
		fixedHeight: false, 
		fixedWidth: false,
		alwaysHide: true,
		onComplete: function(toggler, element) {
			//toggler.highlight('#d99da9');
		},
		onActive: function(toggler, element) {
			// toggler.highlight('#76C83D'); //green
			//element.highlight('#d99da9');
			//$('active').highlight('#76C83D');
		},
		onBackground: function(toggler, element) {
			//toggler.highlight('#DC4F4D'); //red
			//element.highlight('#DC4F4D');	
			//$('background').highlight('#DC4F4D');	
		}
	});
	
    // SqueezeBox.assign($$('.elements .tools a.preview'));
    // SqueezeBox.assign($$('.elements .tools a.map'), {handler: 'iframe', size: {x: 920, y: 400}});
}

function fillSingle() {
	SqueezeBox.assign($$('.tx-p3wido-pi1 a.preview'));
	// SqueezeBox.assign($$('.tx-p3wido-pi1 a.map'), {handler: 'iframe', size: {x: 920, y: 400}});
	SqueezeBox.assign($$('.tx-p3wido-pi1 a.map'), {handler: 'iframe', size: {x: 920, y: 400}});
}
function blabla() {
	
	
	$$('.elements .tools a').each(function(element) {
        // Constructor, takes the element and options as arguments
        new ReMooz(element, {
            centered: true, // Zoom the center of the screen
            'shadow': 'onOpenEnd', // fx is faster because shadow appears after resize animation
            'resizeFactor': 0.8, // resize to maximum 80% of screen size
            origin: element.getElement('img') // Take the image inside as origin for the zooming element
        });
 
    });
	
	
	
}
function fixRelated() {

	var pos,wrapper = $('relatedwrapper'), images = $$('#relatedwrapper img'); links = $$('#relatedwrapper a');
	var collapsed=false;
	
	links.addEvents({
		click: function(a) {
			a.stop();
			if (collapsed) { window.top.location=this.href;}
		}
	});
	
	deviation = wrapper.getPosition();
			
	images.each(function(img){
    pos = img.getPosition();
	
    img
        .store('default:coords', pos)
        .set('styles', {
            top: pos.y,
            left: pos.x
        })
        .set('morph', {
            transition: 'back:out'
        });
    
    
    	(function(){
        	this.setStyle('position', 'absolute');
    	}).delay(1, img);
     
     	images.addEvents({
    		click: function(e){
        
        if (collapsed){
            o=0;
            images.each(function(img, i){
            	
                (function(){
                	this.setStyle('width', '64px');
                	this.setStyle('-webkit-transform', 'rotate(0)');
                    this.setStyle('-moz-transform', 'rotate(0)');		
         			this.morph({
                        top: this.retrieve('default:coords').y-deviation.y-55,
                        left: (this.retrieve('default:coords').x-deviation.x)+10
                    });
                }).delay(40 * i, img);
            });
            
            collapsed = false;
        } else {
            var picked = $(e.target).retrieve('default:coords');
            
            images.each(function(img, i){
                (function(){
                	this.setStyle('width', '64px');
                    this.setStyle('-webkit-transform', 'rotate(' + $random(-10, 10) + 'deg)');
                    this.setStyle('-moz-transform', 'rotate(' + $random(-10,10) + 'deg)');
                    this.morph({
                    
                        top: 0 + $random(-20, 20),
                        left: 0 + $random(-20, 20)
                    });
                    
                }).delay(40 * i, img);
            });
            
            collapsed = true;
        }
    }
    
		});
		
	});
	
	//var picked = $(e.target).retrieve('default:coords');
    images.each(function(img, i){
    	(function(){
    		this.setStyle('width', '120px');
        	this.setStyle('-webkit-transform', 'rotate(' + $random(-10, 10) + 'deg)');
        	this.setStyle('-moz-transform', 'rotate(' + $random(-10,10) + 'deg)');
            this.morph({
            	top: 0 + $random(-20, 20),
                left: 0 + $random(-20, 20)
            });
        }).delay(40 * i, img);
    });
    collapsed = true;       
}

function tiltRelated() {
	images = $$('#relatedwrapper img');
	images.each(function(img, i){
    	(function(){
    		this.setStyle('-webkit-transform', 'rotate(' + $random(-5, 5) + 'deg)');
        	this.setStyle('-moz-transform', 'rotate(' + $random(-5,5) + 'deg)');
        }).delay(40 * i, img);
    });
}
window.addEvent('domready', function() {
	initTabs();
	fixPhotos();
	fixLinks();
	slideRelated();
	fillAlfalist();
	fillSingle();
	tiltRelated();
	timeline();
	// fixRelated();
	
	
	Cufon.replace($$('H1.maintitle'), {
		textShadow: '1px 1px rgba(0, 0, 0, 0.4)',
		fontFamily: 'Charlemagne Std'
	});
	Cufon.replace($$('.topmarker'), {
		textShadow: '1px 1px rgba(0, 0, 0, 0.1)',
		fontFamily: 'Charlemagne Std'
	});
	Cufon.replace($$('.left h2'), {
		textShadow: '1px 1px rgba(0, 0, 0, 0.1)',
		fontFamily: 'Charlemagne Std'
	});
	//Cufon.replace($$('li.caption'), {
	//	textShadow: '1px 1px rgba(0, 0, 0, 0.1)',
	//	fontFamily: 'Charlemagne Std'
	//});
	Cufon.replace($$('div.menu a'), {
		fontFamily: 'Helvetica Neue'
	});
	Cufon.replace($$('#bodywrapper .top .docu a'), {
		fontFamily: 'Helvetica Neue'
	});

});
