// JavaScript Document
var content_folder 		= new Array('','blog','contact','products','portfolio');
var page_content 		= new Array('','detail.php','detail.php','detail.php','detail.php');
var url_name 			= new Array('','blog','contact','products','portfolio');
var menu_name 			= new Array('','blog','contact','products','portfolio');

var root_short			= 'llr';
var has_scroll			= false;

var fx_mouse_overs		= new Array;
var fx_mouse_oversEXTRA		= new Array;
var fx_inner_content_menu;
var fx_inner_content;

var q_str_page			= '';
var q_str_item			= 0;
var active_current		= 1;
var active_menu			= 1;

var active_categories	= 0;
var active_parent		= 0;
var active_item			= 0;
var active_position		= 0;

var display_methods		= new Array('thumbs','rows','one');
var display_method		= 0;

var minimized			= true;
var left_pos			= 0;

var mySpinner;
var navigating			= false;

var url_to_load;
var allow_click			= true;

var swf_load_item		= false;
var swfOveruler			= false;

function LoadPageAll(basis_url, pagina, basis_item){
	$('main_container').setStyle('left' , 0);
	$('main_container').setStyle('top' , 0);
	
	hasFlash();
	
	menulist			= $$('.btn');
	menulist.each(function(element) {
		var current = parseInt(element.getProperty('id').substring(3));
		fx_mouse_overs[current] = MorpheItems(element.getProperty('id'), 500, Fx.Transitions.Cubic.easeOut);
		fx_mouse_oversEXTRA[current] = MorpheItems(element.getProperty('id'), (current + 1) * 1000, Fx.Transitions.Cubic.easeOut);
		
		element.addEvent('mouseenter', function(event){ 
			var current = parseInt(element.getProperty('id').substring(3));
			if(active_current!=current){
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'opacity':0.8});
			}
		});
		element.addEvent('mouseleave', function(){
			var current = parseInt(element.getProperty('id').substring(3));
			if(active_current!=current){
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'opacity':0.5});
			}
		});
				fx_mouse_overs[current].set({'opacity':0});
	});
	
	var imgswapCounter	= 0;
	$$('.imgswap').each(function(img) {
		imgswapCounter++;
		var src 		= img.getProperty('src');
		var extension 	= src.substring(src.lastIndexOf('.'),src.length)
		if(imgswapCounter==active_menu){
			img.setProperty('src',src.replace(extension,'-active' + extension));
		}else{
			img.addEvent('mouseenter', function() { img.setProperty('src',src.replace(extension,'-active' + extension)); });
			img.addEvent('mouseleave', function() { img.setProperty('src',src); });
		}
	}); 
	
	firstResize();	
	trackMovement();
	window.onresize = function goResize(){resizing();}
	$('subLogo').setStyles({'opacity' : 0});
	var subLogo					= MorpheItems('subLogo', 2000, Fx.Transitions.Cubic.easeOut);
	subLogo.start({'opacity':1});
	
	
	var swap1 		= new MooSwap('.listing-thumb');
	
}



var movieOpen = false
function initVideoWerkwijze(nr){
	
	var src = $('vimeourl_' + nr).value
	
	if(movieOpen == false){
		movieOpen = true;
		voorbeeldContent 	= new Fx.Morph('voorbeeld_content', {duration: 1500, transition: Fx.Transitions.Cubic.easeOutr, onComplete: function(){
			$('voorbeeld_video').src = src;
		}});
		voorbeeldContent.set({'opacity': 0});	
		voorbeeldContent.set({'top': middleY - 450});	
		voorbeeldContent.start({'opacity': 1});	
	}else{
		$('voorbeeld_video').src = src;
	}
	
}

var minWidth		= 980; //buffert of 20! basic width = 916 rounded gives 920 + 20
var minHeight		= 760; //buffert of 20! basic width = 916 rounded gives 920 + 20
function firstResize(){
	
	//if(q_str_page!='blog'){
		if(document.documentElement.clientWidth){
		
			innerWidth 	= getDocWidth();
			innerHeight	= getDocHeight();
			
			if(innerWidth<minWidth){
				innerWidth 	= minWidth;
			}
			if(innerHeight < minHeight){
				if(!browserIE){
					innerWidth 	= parseInt(innerWidth - 17);
				}
				innerHeight = minHeight;
				has_scroll	= true;
			}
		}else{
			innerWidth 	= minWidth;
			innerHeight = minHeight;
		}
	//}else{
	//	innerWidth 	= parseInt((document.documentElement.clientWidth * 1)) - 17;
	//	innerHeight = 0;
	//}
	positionAfterResize();
	
}

function resizing(){
	if(document.documentElement.clientWidth){
		if(!browserSAF){
			if(browserIE && browserIE8 == false){
				innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
			}else{
				innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
			}
			innerHeight	= parseInt((document.documentElement.clientHeight * 1));
		}else{
			innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
			innerHeight	= parseInt((document.documentElement.clientHeight * 1));
		}
		if(innerWidth<minWidth){
			innerWidth 	= minWidth;
		}
		if(innerHeight < minHeight){
			if(innerHeight > minHeight){ 
				if(!browserIE){
					if(!browserSAF){
						innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 17);
					}else{
						innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 16);
					}
				}
			}
			innerHeight = minHeight;
			has_scroll	= true;
		}
	}else{
		innerWidth 	= minWidth;
		innerHeight = minHeight;
	}
	positionAfterResize();
					
}


var maxWidth 			= 0; //1080; //if 0 then innerwidth!
var av_width			= 0; //will be set
var maxHeight			= 0; //455; //if 0 then innerHeight!
var av_height			= 0; //will be set
var cloadsinited		= false; //will be set

function positionAfterResize(){
	middleX				= innerWidth / 2;
	middleY				= innerHeight / 2;

	$('main_container').setStyles({'width' : innerWidth, 'height' : innerHeight});
	
	$('menuContainer').setStyles({'left' : middleX - 490, 'top' : innerHeight - 220});
	$('logoContainer').setStyles({'left' : middleX - 136, 'top' : middleY - 270});
	
	if(maxWidth > 0){
		if(innerWidth > maxWidth + 20 ){ //scrollbarbuffer..always
			av_width		= maxWidth;
		}else{
			av_width		= innerWidth-20;
		}
	}else{
		av_width	= innerWidth;
	}
	
	if(maxHeight > 0){ //fixed height
		av_height		= maxHeight;
	}else{
		av_height		= innerHeight - 90 - 170; //used for slideshows! - 90 - 170 means minus header and minus footer(+ info)
	}
	
	proportions_site 	= av_height / av_width;  
	
	
	$('bigHeart').setStyles({'opacity' : 0.7});
	if(!cloadsinited){
		$('mainLogo').setStyles({'opacity' : 0});
	}
	
	$('werkwijze').setStyles({'left' : (middleX - 440)});

	if(activePart != 2){
		$('voorbeeld').setStyles({'top' : (innerHeight)});
		$('voorbeeld_content').setStyles({'left' : (middleX - 440)});
	}else{
		$('voorbeeld').setStyles({'top' : (innerHeight - 140)});
	}
	$('voorbeeld').setStyles({'width':innerWidth});
	$('scroll_content').setStyles({'width':innerWidth - 120});
	$('scroll_right').setStyles({'left':innerWidth - 60});
	
	if($('scroll_right_ookleuk')){
	$('scroll_right_ookleuk').setStyles({'left':innerWidth - 230});
	$('scroll_content_ookleuk').setStyles({'width':innerWidth - 300});
	}
	
	if(activePart != 3){
		$('contact').setStyles({'top' : (innerHeight)});
	}
	$('contact').setStyles({'left' : (middleX + 80)});
	
	if(activePart != 3){
		$('ook_leuk').setStyles({'left' : -1 * (innerWidth),'top' : (middleY - 300)});
	}
	$('ook_leuk').setStyles({'top' : (middleY - 300),'width':innerWidth - 200});
	
		
	if($('wolken_a')){
	$('wolken_a').setStyles({'top' : (innerHeight - 200),'width' : innerWidth});
	$('wolken_b').setStyles({'top' : (innerHeight - 200),'width' : innerWidth});
	}
	
	if(!cloadsinited){
		cloadsinited = true;
		if($('wolk_1')){
			$('wolk_1').setStyles({'left' : -443});
			$('wolk_2').setStyles({'left' : innerWidth - 715});
			$('wolk_3').setStyles({'left' : 0});
			$('wolk_4').setStyles({'left' : innerWidth - 786});
				
		}
			
			moveWolk1();
			moveWolk2();
			wolk3_a = new Fx.Morph('wolk_3', {duration: 100000, transition: Fx.Transitions.Linear, onComplete: function(){
				moveWolk3();
			}});
			//wolk3_a.start({'left': -1528 });
			wolk4_a = new Fx.Morph('wolk_4', {duration: 120000, transition: Fx.Transitions.Linear, onComplete: function(){
				moveWolk4();
			}});
			//wolk4_a.start({'left': innerWidth });
		
			doItAgain();
		
			var mainLogo				= MorpheItems('mainLogo', 1000, Fx.Transitions.Cubic.easeOut);
			mainLogo.start({'opacity':1});
	
			moveWerkwijze 			= new Fx.Morph('werkwijze', {duration: 2000, transition: Fx.Transitions.Cubic.easeOut});
			moveVoorbeeld			= new Fx.Morph('voorbeeld', {duration: 2000, transition: Fx.Transitions.Cubic.easeOut});
			moveVoorbeeldContent	= new Fx.Morph('scroll_content_scroller', {duration: 1000, transition: Fx.Transitions.Cubic.easeOut});
			moveContact				= new Fx.Morph('contact', {duration: 5000, transition: Fx.Transitions.Cubic.easeOut});
			voorbeeldContent 		= new Fx.Morph('voorbeeld_content', {duration: 2000, transition: Fx.Transitions.Cubic.easeOut});
			
			moveOokleuk				= new Fx.Morph('ook_leuk', {duration: 2000, transition: Fx.Transitions.Cubic.easeOut});
			moveOokleukContent		= new Fx.Morph('scroll_content_scroller_ookleuk', {duration: 2000, transition: Fx.Transitions.Cubic.easeInOut});
			
			continueSite.delay(2000)
			
			
			$('scroll_right_ookleuk').addEvent('click', function(){
				scrollerDirection	= 1;
				scrollNowOokLeuk();
			});
			$('scroll_left_ookleuk').addEvent('click', function(){
				scrollerDirection	= -1;
				scrollNowOokLeuk();
			});
		
			$('scroll_right').addEvent('mouseenter', function(){
				clearInterval(scrollert);
				scrollerDirection	= 1;
				scrollert			= scrollNow.periodical(10);
			});
			$('scroll_right').addEvent('mouseleave', function(){;
				scrollerDirection	= 0;
				clearInterval(scrollert);
			});
			$('scroll_left').addEvent('mouseenter', function(){
				clearInterval(scrollert);
				scrollerDirection	= -1;
				scrollert			= scrollNow.periodical(10);
			});
			$('scroll_left').addEvent('mouseleave', function(){;
				scrollerDirection	= 0;
				clearInterval(scrollert);
			});	
	}
	
	
	
	$('main_container').setStyle('display' , 'block');
	
	
	
}

var moveContact;
var moveWerkwijze;
var moveVoorbeeld;
var moveVoorbeeldContent;
var voorbeeldContent;

var moveOokleuk;
var moveOokleukContent;

var activePart = 0;
function resetALL(nr){
	if(nr != 4){
		moveOokleukContent.cancel();			
		moveOokleukContent.start({'left': innerWidth});	
		moveOokleuk.cancel();			
		moveOokleuk.start({'left': -1 * innerWidth});
		scrollPosition = 0;
		
	}
	if(nr != 3){
		moveContact.cancel();			
		moveContact.start({'top': innerHeight});			
	}
	if(nr != 2){
		moveVoorbeeld.cancel();			
		moveVoorbeeld.start({'top': innerHeight});	
		movieOpen = false;
		voorbeeldContent.cancel();			
		
		var CloseVoorbeeldContent 	= new Fx.Morph('voorbeeld_content', {duration: 2000, transition: Fx.Transitions.Cubic.easeIn, onComplete:function(){ 
			$('voorbeeld_video').src = '';		
		}});
		CloseVoorbeeldContent.start({'top': -630});	
	}
	if(nr != 1){
		moveWerkwijze.cancel();			
		var CloseMoveWerkwijze 	= new Fx.Morph('werkwijze', {duration: 2000, transition: Fx.Transitions.Cubic.easeIn, onComplete:function(){ 
			$('werkwijze_video').src = '';		
		}});
		CloseMoveWerkwijze.start({'top': -630});	
	}
}
function openWerkwijze(){
	resetALL(1);
	activePart = 1;
	moveWerkwijze.cancel();			
	moveWerkwijze.set({'opacity': 0});	
	moveWerkwijze.set({'top': middleY - 450});	
	moveWerkwijze.start({'opacity': 1});	
	
	var src = $('werkwijze_vimeo').value
	$('werkwijze_video').src = src;
}

var scrollPosition			= 0;
var scrollert				= 0;
var scrollerDirection		= 0;

function openVoorbeeld(){
	activePart = 2;	
	resetALL(2);
	moveVoorbeeld.cancel();			
	moveVoorbeeld.start({'top': innerHeight - 140});			
	
	scrollPosition = 0;
	moveVoorbeeldContent.cancel();			
	moveVoorbeeldContent.start({'left': 0});	
	
	
}

function openOokLeuk(){
	resetALL(4);
	activePart = 4;
	scrollPosition = 0;
	moveOokleukContent.cancel();			
	moveOokleukContent.start({'left': 0});	
	moveOokleuk.cancel();			
	moveOokleuk.start({'left': 100});	
}

function scrollNow(){
	switch(scrollerDirection){
		case 1:
			scrollPosition -= 4
		break;
		case -1:
			scrollPosition += 4
		break;
	}
	if(scrollPosition > 0){
		scrollPosition = 0;
	}
	$('scroll_content_scroller').setStyles({'left':scrollPosition});
}

function scrollNowOokLeuk(){
	moveOokleukContent.cancel();
	switch(scrollerDirection){
		case 1:
			scrollPosition -= (innerWidth - 100)/2;
		break;
		case -1:
			scrollPosition += (innerWidth - 100)/2;
		break;
	}
	if(scrollPosition > 0){
		scrollPosition = 0;
	}
	//$('scroll_content_scroller_ookleuk').setStyles({'left':scrollPosition});
	moveOokleukContent.start({'left':scrollPosition});
}

function openContact(){
	resetALL(3);
	activePart = 3;
	moveContact.cancel();			
	moveContact.start({'top': middleY - 320});			
}

var wolk1_a;
var wolk1_b;
var wolk2_a;
var wolk2_b;
var wolk3_a;
var wolk3_b;
var wolk4_a;
var wolk4_b;

function moveWolk1(){
	 wolk1_a 	= new Fx.Morph('wolk_1', {duration: 100000, transition: Fx.Transitions.Linear, onComplete: function(){
		 wolk1_b = new Fx.Morph('wolk_1', {duration: 125000, transition: Fx.Transitions.Linear, onComplete: function(){
			moveWolk1();
		}});
		wolk1_b.start({'left': -886});			
	}});
	wolk1_a.start({'left':innerWidth});
}

function moveWolk2(){
	 wolk2_a 	= new Fx.Morph('wolk_2', {duration: 100000, transition: Fx.Transitions.Linear, onComplete: function(){
		 wolk2_b = new Fx.Morph('wolk_2', {duration: 105000, transition: Fx.Transitions.Linear, onComplete: function(){
			moveWolk2();
		}});
		wolk2_b.start({'left':innerWidth});			
	}});
	wolk2_a.start({'left': - 1392});
}

function moveWolk3(){
	 wolk3_a 	= new Fx.Morph('wolk_3', {duration: 205000, transition: Fx.Transitions.Linear, onComplete: function(){
		 wolk3_b = new Fx.Morph('wolk_3', {duration: 285000, transition: Fx.Transitions.Linear, onComplete: function(){
			moveWolk3();
		}});
		wolk3_b.start({'left': -1528});			
	}});
	wolk3_a.start({'left':innerWidth});
}

function moveWolk4(){
	 wolk4_a 	= new Fx.Morph('wolk_4', {duration: 200000, transition: Fx.Transitions.Linear, onComplete: function(){
		 wolk4_b = new Fx.Morph('wolk_4', {duration: 210000, transition: Fx.Transitions.Linear, onComplete: function(){
			moveWolk4();
		}});
		wolk4_b.start({'left':innerWidth});			
	}});
	wolk4_a.start({'left': - 886});
}

var directionBigHeart			= 1;
function doItAgain(){
	var target_value			= 0;
	switch(directionBigHeart){
		case 1:
			target_value		= 0.6;
			directionBigHeart	= 2;
		break;
		case 2:
			target_value		= 0.4;
			directionBigHeart	= 1;
		break;
	}
	var bigHeart = 	new Fx.Morph('bigHeart', {duration: 1500, transition: Fx.Transitions.Cubic.easeOut, onComplete: function(){
	//	doItAgain();
	}});
	
	bigHeart.start({'opacity':target_value});
}

var continueSite = function(){
	var subLogo					= MorpheItems('subLogo', 2000, Fx.Transitions.Cubic.easeOut);
	subLogo.start({'opacity':0});
	
	menulist.each(function(element) {
		var current = parseInt(element.getProperty('id').substring(3));
		fx_mouse_oversEXTRA[current].start({'opacity':0.5});
	
	});
}

function trackMovement(){
	var top_pos_btns	= middleY + 270 + 20;
	var left_pos_btns	= middleX - 490;
	
	var max_distance	= 1000;
		
	
	
	var array_X = new Array(left_pos_btns + 121,left_pos_btns + 377,left_pos_btns + 603,left_pos_btns + 802)
	var array_Y = new Array(top_pos_btns,top_pos_btns,top_pos_btns,top_pos_btns)
	var myElement 	= $(document.body);
	myElement.addEvent('mousemove', function(event){
		mouseY 			= event.page.y;											  
		mouseX 			= event.page.x;											  
		
		var distance_1	= Math.sqrt(Math.pow((mouseX-array_X[0]),2) + Math.pow((mouseY-array_Y[0]),2));
		var width_1		= 0;
		if(distance_1 > 500){
			width_1		= 182;
		}else{
			width_1		= 182 + ( 30 * ((500 - distance_1)/500)) ;
		}
		$('btn1_image').width = width_1;									  
		
		var distance_2	= Math.sqrt(Math.pow((mouseX-array_X[1]),2) + Math.pow((mouseY-array_Y[1]),2));
		var width_2		= 0;
		if(distance_2 > 500){
			width_2		= 199;
		}else{
			width_2		= 199 + ( 35 * ((500 - distance_2)/500)) ;
		}
		$('btn2_image').width = width_2;								  
		
		var distance_3	= Math.sqrt(Math.pow((mouseX-array_X[2]),2) + Math.pow((mouseY-array_Y[2]),2));
		var width_3		= 0;
		if(distance_3 > 500){
			width_3		= 135;
		}else{
			width_3		= 135 + ( 25 * ((500 - distance_3)/500)) ;
		}
		$('btn3_image').width = width_3;							  
		
		var distance_4	= Math.sqrt(Math.pow((mouseX-array_X[3]),2) + Math.pow((mouseY-array_Y[3]),2));
		var width_4		= 0;
		if(distance_4 > 500){
			width_4		= 153;
		}else{
			width_4		= 153 + ( 30 * ((500 - distance_4)/500)) ;
		}
		$('btn4_image').width = width_4;
		
		
	});	
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}
