// JavaScript Document
content_folder 		= new Array('','post','post','post','post','post','post','post');
start_content 		= new Array('','home.php','biography.php','foundation.php','partners.php','video.php','photo.php','blog.php');
page_content 		= new Array('','detail.php','detail.php','detail.php','detail.php','detail.php','detail.php','detail.php');
url_name 			= new Array('','home','biography','foundation','partners','video','photo','blog');
categories_array 	= new Array(0,12,11,8,7,3,4,2);

load_innercontent	= new Array(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
swfLoad				= new Array(false,false,false,false,false,false,false,false,false,false,false,false,false);
gallery_type		= new Array(0,0,0,0,0,0,0,0,0,0,0,0,0);




var class_array 	= new Array('','home','bio','basis','basis','basis','video','photo','basis');
var root_domain		= 'http://www.esdavids.com/';

//preloading images menu
var preload_image_object 	= new Array();
var image_url 				= new Array();
var image_url_active 		= new Array();

function preloadImages(){
	image_url[0] 			= root_domain + "img/assets/btns/btn_home.jpg";
	image_url[1] 			= root_domain + "img/assets/btns/btn_bio.jpg";
	image_url[2] 			= root_domain + "img/assets/btns/btn_corporate.jpg";
	image_url[3] 			= root_domain + "img/assets/btns/btn_partners.jpg";
	image_url[4] 			= root_domain + "img/assets/btns/btn_video.jpg";
	image_url[5] 			= root_domain + "img/assets/btns/btn_pictures.jpg";
	image_url[6] 			= root_domain + "img/assets/btns/btn_blog.jpg";
	image_url_active[0] 	= root_domain + "img/assets/btns/active/btn_home.jpg";
	image_url_active[1] 	= root_domain + "img/assets/btns/active/btn_bio.jpg";
	image_url_active[2] 	= root_domain + "img/assets/btns/active/btn_corporate.jpg";
	image_url_active[3] 	= root_domain + "img/assets/btns/active/btn_partners.jpg";
	image_url_active[4] 	= root_domain + "img/assets/btns/active/btn_video.jpg";
	image_url_active[5] 	= root_domain + "img/assets/btns/active/btn_pictures.jpg";
	image_url_active[6] 	= root_domain + "img/assets/btns/active/btn_blog.jpg";
	preload_image_object[0] 	= new Image();
	preload_image_object[0].src = image_url_active[0];
	preload_image_object[1] 	= new Image();
	preload_image_object[1].src = image_url_active[1];
	preload_image_object[2] 	= new Image();
	preload_image_object[2].src = image_url_active[2];
	preload_image_object[3] 	= new Image();
	preload_image_object[3].src = image_url_active[3];
	preload_image_object[4] 	= new Image();
	preload_image_object[4].src = image_url_active[4];
	preload_image_object[5] 	= new Image();
	preload_image_object[5].src = image_url_active[5];
	preload_image_object[6] 	= new Image();
	preload_image_object[6].src = image_url_active[6];

}

preloadImages();

var has_scroll		= false;

var fx_mouse_overs	= new Array;
var fx_inner_content_menu;
var fx_inner_content;
var fx_inner_content_background;
var fx_navigation;
var fx_menu_minimized;
var fx_menu_maximized;
var fx_indicator;

var fx_music_player;
var fx_background_control;

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

//var big_mode		= false;
var minimized		= true;
var activated		= false;
var left_pos		= 265;

var mySpinner;
var navigating		= false;

var url_to_load;
var allow_click		= true;
var inList			= 0;

var q_str_page			= '';
var q_str_parent		= 0;
var q_str_item			= 0;
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);
	
	resizing();
	
	middleX				= innerWidth / 2;
	middleY				= innerHeight / 2;
	
	menulist			= $$('.navigation_div');
	menulist.each(function(element) {
		var current = parseInt(element.getProperty('id').substring(4));
		fx_mouse_overs[current] = MorpheItems(element.getProperty('id'), 800, Fx.Transitions.Cubic.easeOut);
		
		element.addEvent('mouseenter', function(event){ 
			var current = parseInt(element.getProperty('id').substring(4));
			if(active_current!=current){
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'opacity':0.1});
			}
		});
		element.addEvent('mouseleave', function(){
			var current = parseInt(element.getProperty('id').substring(4));
			if(active_current!=current){
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'opacity':1});
			}
		});
		element.addEvent('click', function(){
			var current = parseInt(element.getProperty('id').substring(4));
			if(active_current!=current && allow_click == true){
				fx_mouse_overs[active_current].cancel();
				fx_mouse_overs[active_current].start({'opacity':1});
				
				active_current          = current;
				
				fx_mouse_overs[active_current].cancel();
				fx_mouse_overs[active_current].start({'opacity':0});
				
				active_categories		= categories_array[active_current];
				
				if(active_item != 0){
					resetDetail();
				}
				
				if(start_content[active_current] !=  ''){
					left_pos 				= 265;
					activated				= true; // menu is open namelijk!
					
					initPage();
					
					if(mySpinner){
						mySpinner.destroy();
					}
					
					mySpinner 				= new Spinner('inner_content_menu_listing');
					mySpinner.show(true);
					
					var url				 	= root_domain + content_folder[active_current] + '/' + start_content[active_current] + '?include_header=1';
					loadNshow(url, 'inner_content_menu_listing', 'get', false);
					active_parent			= 0; //dropdownlist values
					
					navigating				= true;
					SWFAddress.setValue('/category/?page='+url_name[active_current]);
					navigating				= false;
					
					
				}else{
					
					$('inner_content_menu_listing').innerHTML 	= '';
					if(mySpinner){
						mySpinner.destroy();
					}
					
					
					if(page_content[active_current] !=  ''){
						
						closeOpen('close')
						
						allow_click 			= false;
						active_item				= 22;
						
						var url				 	= root_domain + content_folder[active_current] + '/' + page_content[active_current] + '?include_header=1';
						open_full				= false;
						//alert(url);
						loadNshow(url, 'inner_content_content', 'get', false);
						navigating				= true;
						SWFAddress.setValue('/category/?page='+url_name[active_current]);
						navigating				= false;
						
					}
				}
				
			}
		});

	});	
	
//	fx_inner_content 	 			= MorpheItems('inner_content', 1000, Fx.Transitions.Cubic.easeOut);
//	fx_inner_content_background	 	= MorpheItems('inner_content_background', 1000, Fx.Transitions.Cubic.easeOut);
//	fx_inner_content_menu 			= MorpheItems('inner_content_menu', 1000, Fx.Transitions.Cubic.easeOut);
//	fx_navigation 	 				= MorpheItems('navigation', 500, Fx.Transitions.Cubic.easeOut);
//	fx_menu_minimized 				= MorpheItems('menu_closed', 500, Fx.Transitions.Cubic.easeOut);
//	fx_menu_maximized 				= MorpheItems('menu_open', 500, Fx.Transitions.Cubic.easeOut);
//	fx_indicator					= MorpheItems('indicator', 1000, Fx.Transitions.Cubic.easeOut);
	fx_inner_content 	 			= MorpheItems('inner_content', 800, Fx.Transitions.Cubic.easeOut);
	fx_inner_content_background	 	= MorpheItems('inner_content_background', 800, Fx.Transitions.Cubic.easeOut);
	fx_inner_content_menu 			= MorpheItems('inner_content_menu', 800, Fx.Transitions.Cubic.easeOut);
	fx_navigation 	 				= MorpheItems('navigation', 800, Fx.Transitions.Cubic.easeOut);
	fx_menu_minimized 				= MorpheItems('menu_closed', 800, Fx.Transitions.Cubic.easeOut);
	fx_menu_maximized 				= MorpheItems('menu_open', 800, Fx.Transitions.Cubic.easeOut);
	fx_indicator					= MorpheItems('indicator', 800, Fx.Transitions.Cubic.easeOut);
	
	
	if(active_current!=0){
		q_str_page			= pagina;
		q_str_parent		= parent;
		q_str_item			= basis_item;
		//swfNavigate();	
	}else{
		q_str_page			= pagina;
		q_str_parent		= parent;
		q_str_item			= basis_item;
		if(q_str_page!=''){
			Log.log('meegegeven pagina in LoadInit : '+q_str_page);
			for(var i=0;i<url_name.length;i++){
				if(url_name[i] == q_str_page){
					//fx_mouse_overs[active_current].cancel();
					//fx_mouse_overs[active_current].start({'opacity':1});
					fx_mouse_overs[i].cancel();
					fx_mouse_overs[i].start({'opacity':0});
					active_current			= i
					initPage();
					
					if(q_str_item){
						if(q_str_item!=0 && q_str_item!=''){
							Log.log('meegegeven item in LoadInit : '+q_str_item);
							active_item 		= q_str_item;
							initPageItem();
						}
					}
					
					switch(active_current){
						case 3:
						case 4:
						case 5:
						case 6:
						case 7:
							baseInitListing(false);
						break;
					}
				}
			}
		}else{
			fx_mouse_overs[active_current].cancel();
			fx_mouse_overs[active_current].start({'opacity':0});
			initPage();			
		}
	}
	
	setSlideBase();	
	
	if(swfOveruler){
		//Log.log('swf parameters' + active_current);
		Log.log(q_str_page + ' to ' + url_name[active_current]);
		
		if(q_str_page != url_name[active_current]){
			Log.log('load & show listing');
			
			fx_mouse_overs[active_current].cancel();
			fx_mouse_overs[active_current].start({'opacity':0});
			
			active_categories	= categories_array[active_current];
			
			if(start_content[active_current] !=  ''){
				left_pos 				= 265;
				activated				= true; // menu is open namelijk!
				initPage();
			
				mySpinner 				= new Spinner('inner_content_menu_listing');
				mySpinner.show(true);
				
				var url				 	= root_domain + content_folder[active_current] + '/' + start_content[active_current] + '?include_header=1';
				Log.log(url);
				loadNshow(url, 'inner_content_menu_listing', 'get', false);
				active_parent			= 0; //dropdownlist values
			}
		}else{
			Log.log('show listing');
			//als swf parameters de originel rootmap /blog/title/cat/item overrulen
			fx_mouse_overs[active_current].cancel();
			fx_mouse_overs[active_current].start({'opacity':0});
			switch(active_current){
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
				case 6:
				case 7:
					baseInitListing(false);
				break;
			}
			if(active_item>0){
				left_pos 			= 46;
			}
			initPage();
			
			if(active_item>0 && swf_load_item==true){
				Log.log('item moet ingeladen worden!');
				swf_load_item = false;
				swfOpenItem(active_item, active_categories, active_position)
			}else if(active_item>0){
				Log.log('item staat er al');
				initPageItem();
				initVideo();
				fx_navigation.cancel();
				fx_navigation.start({'left':-219});
				fx_menu_maximized.cancel();
				fx_menu_maximized.start({'opacity':1});
				fx_menu_minimized.cancel();
				fx_menu_minimized.start({'opacity':1 , 'z-index':20 , 'left':219});
			}
		}
		
		
		swfOveruler	= false;
		
	}
	
	
	activated		= true;	
	//want standaard blog!
	
	$('menu_closed').addEvent('mouseenter', function(){							 
		if(allow_click){
			if(activated){
				activated	= false;
				closeOpen('open');
			}
		}
	});
	$('menu_open').addEvent('mouseleave', function(){
		if(allow_click){
			if(!activated){
				activated	= true;
				closeOpen('close');
			}
		}
	});
	
	Log.log('all = initted');
	
	if(flash_can){
		var thisMusic = new SWFObject(root_domain+'music.swf', 'music', 265, 180, "9", "000000");
		thisMusic.addParam("scale", "noscale");
		thisMusic.addParam("quality", "high"); 
		thisMusic.addParam("allowscriptaccess", "all");
		thisMusic.addParam("wmode", "window"); 
		thisMusic.addParam("codebase", "all"); 
		thisMusic.useExpressInstall('expressinstall.swf');
		thisMusic.write('music_player');
		
		fx_music_player 	 		= MorpheItems('music_player', 1000, Fx.Transitions.Cubic.easeOut);
		fx_background_control	 	= MorpheItems('background_control', 1000, Fx.Transitions.Cubic.easeOut);
	
		
		$('music_player').addEvent('mouseenter', function(event){ 
			showFullPlayer	= true;
			showPlayer.delay(500);
		});
		$('music_player').addEvent('mouseleave', function(){
			showFullPlayer	= false;
			fx_music_player.cancel();
			fx_music_player.start({'top': 180});
			fx_background_control.cancel();
			fx_background_control.start({'top': 136});
		});
	}
}

var showFullPlayer	= false;
function showPlayer(){
	if(showFullPlayer){
		fx_music_player.cancel();
		fx_music_player.start({'top': 44});
		fx_background_control.cancel();
		fx_background_control.start({'top': 0});
	}
}

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<1000){
			innerWidth 	= 1000;
		}
		
		if(innerHeight < 640){
			innerHeight = 640;
			has_scroll	= true;
			if(!browserIE){
				if(!browserSAF){
					innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 17);
				}else{
					innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 16);
				}
			}
		}
	}else{
		//alert(2)
		innerWidth 	= 1000;
		innerHeight = 600;
	}
	middleX				= innerWidth / 2;
	middleY				= innerHeight / 2;
	
	$('slides_container').setStyle('width' , innerWidth);
	$('slides_container').setStyle('height' , innerHeight);
	$('main_container').setStyle('width' , innerWidth);
	$('main_container').setStyle('height' , innerHeight);
	$('content').setStyle('height' , innerHeight);
	$('content').setStyle('width' , innerWidth);
	
	$('navigation').setStyle('height' , innerHeight);
	$('menu_open').setStyle('height' , innerHeight);
	$('menu_closed').setStyle('height' , innerHeight);
	
	
	$('inner_content_menu').setStyles({'height':innerHeight});
	$('inner_content_menu_listing').setStyles({'height':innerHeight});
	$('inner_content').setStyles({'height':innerHeight});
	$('inner_content_background').setStyles({'height':innerHeight});
	$('inner_content_content').setStyles({'height':innerHeight});
	
	$('site_menu').setStyle('top', middleY - 97);
	$('site_menu_extra').setStyle('top', innerHeight - 225);
	$('site_menu_small').setStyle('top', middleY - 23);
	$('site_menu_extra_small').setStyle('top', innerHeight - 85);
	
	$('search').setStyle('left', innerWidth - 195);
	//$('search').setStyle('display', 'block');
	$('twitterfeeds').setStyle('left', innerWidth - 265);
	$('twitterfeeds').setStyle('display', 'block');
	
	$('slides_container').setStyle('display' , 'block');
	$('main_container').setStyle('display' , 'block');
	
	proportions_site 		= innerHeight/innerWidth;
	resizeBG();
	
	if($('listing_nav')){
		$('listing_nav').setStyles({'top': innerHeight});
		ChangeAnim('top', $('listing_nav'), innerHeight - 44, 1000, Fx.Transitions.Cubic.easeOut);
		//setScollButtons();
	}
										
	if($('listing_container')){
		//innerheight - top position - listing nav height
		$('listing_container').setStyles({'height': innerHeight - 120});
	}
	
	/*
	if($('search_optioncategories')){
		loadDropDownActions('search_optioncategories','categories');		
	}
	*/

	if($('post_drag_area')){
		$('post_drag_area').setStyles({'height': innerHeight - 22});
		$('post_content_area').setStyles({'height': innerHeight - 44});
		setScroll('post_content', 'post_content_area', 'vertical');
	}					
}

var open_full = false;

function initPage(){
	Log.log('config listing area voor : ' + active_current);
		
	switch(active_current){
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
			fx_inner_content_menu.cancel();
			fx_inner_content_menu.start({'left':left_pos, 'width':292});
		break;
	}
	if(active_item == 0 && active_current != 2){
		fx_inner_content.cancel();
		fx_inner_content.start({'left':0, 'width':0});					
	}
}

var detail_width	= 400;
function initPageItem(){
	Log.log('config item area voor : ' + active_item + ' : open_full = ' + open_full+ ' : active_current = ' + active_current);
	if(active_item > 0 && open_full == false){
		open_full = true;
		switch(active_current){
			case 1:
			case 2:
			case 3:
			case 4:
			case 7:
				detail_width			= 400;
				fx_inner_content.cancel();
				fx_inner_content.start({'left':left_pos + 265, 'width':400});
				fx_inner_content_background.cancel();
				fx_inner_content_background.start({'opacity':0.7});
			break;
			case 5:
				detail_width			= 690;
				fx_inner_content.cancel();
				fx_inner_content.start({'left':left_pos + 265, 'width':690});
				fx_inner_content_background.cancel();
				fx_inner_content_background.start({'opacity':0.9});
			break;
			case 6:
				detail_width			= 320;
				fx_inner_content.cancel();
				fx_inner_content.start({'left':left_pos + 265, 'width':320});
				fx_inner_content_background.cancel();
				fx_inner_content_background.start({'opacity':0.7});
			break;
		}
	}
}

function closeOpen(action){
	if(allow_click){
		Log.log('open / close menu : '+ action);
		switch(action){
			case 'close':
				
				fx_inner_content_menu.cancel();
				fx_inner_content_menu.start({'left':left_pos});
				fx_inner_content.cancel();
				fx_inner_content.start({'left':left_pos + 265, 'width':detail_width});
				
				fx_navigation.cancel();
				fx_navigation.start({'left':-219});
				fx_menu_maximized.cancel();
				fx_menu_maximized.start({'opacity':1});
				fx_menu_minimized.cancel();
				fx_menu_minimized.start({'opacity':1 , 'z-index':20 , 'left':219});
			break;
			case 'open':
				
				fx_inner_content_menu.cancel();
				fx_inner_content_menu.start({'left':0});
				fx_inner_content.cancel();
				fx_inner_content.start({'left':265, 'width':detail_width});
				
				fx_navigation.cancel();
				fx_navigation.start({'left':0});
				fx_menu_maximized.cancel();
				fx_menu_maximized.start({'opacity':1});
				fx_menu_minimized.cancel();
				fx_menu_minimized.start({'opacity':1 , 'z-index':10 , 'left':-1000});
			break;
		}
	}
}

var fxcontentShower;
var listing_thumb
var listing_thumb_list;
var listing_thumb_array		= new Array;				
var fx_listing_thumb		= new Array;				
				
function processAfterClick(target, output){
	switch(target){
		case 'inner_content_menu_listing':
			$(target).innerHTML = output;
			$(target).addEvent('domready', function() {
				baseInitListing(true);
			});
		break;
		case 'listing_container':
			$(target).innerHTML = output;
			$(target).addEvent('domready', function() {
				if($('listing_container')){
					//innerheight - top position - listing nav height
					$('listing_container').setStyles({'height': innerHeight - 120});
					setScollButtons();
				}
				fxcontentShower					= MorpheItems(target, 400, Fx.Transitions.Cubic.easeOut);
				listing_thumb_array				= new Array;				
				listing_thumb_list				= $$('#listing_container img');
				initList(true);
				
			});
		break;
		case 'inner_content_content':
			$(target).innerHTML = output;
			$(target).addEvent('domready', function() {
				/*if($('post_drag_area')){
					$('post_drag_area').setStyles({'height': innerHeight - 22});
					$('post_content_area').setStyles({'height': innerHeight - 44});
					setScroll('post_content', 'post_content_area', 'vertical');
				}*/					
				fxcontentShower					= MorpheItems(target, 400, Fx.Transitions.Cubic.easeOut);
				listing_thumb_array				= new Array;				
				listing_thumb_list				= $$('#inner_content_content img');
				if(comments){
					comments = false;
					switch(active_current){
						case 1:
						case 2:
						case 3:
						case 4:
						case 6:
						case 7:
							fx_inner_content_background.cancel();
							fx_inner_content_background.start({'opacity':0.7});
						break;
					}
				}
				initItem();
			});
		break;
		case 'post_content':
			//comments of (back 2) post
			$(target).innerHTML = output;
			$(target).addEvent('domready', function() {

				if($('post_drag_area')){
					$('post_drag_area').setStyles({'height': innerHeight - 22});
					$('post_content_area').setStyles({'height': innerHeight - 44});
					setScroll('post_content', 'post_content_area', 'vertical');
				}					
				
				fxcontentShower					= MorpheItems(target, 400, Fx.Transitions.Cubic.easeOut);
				
				if($('form_login') || $('form_comment') ){
					//comments
					
					comments = true;
				
					
					if($('form_login')){
						setSomeForm('form_login','login_form','login_form','', false, 'submit_btn')
					}else{
						setSomeForm('form_comment','comment_form','comment_form','', false, 'submit_btn')
					}
					
					$('post_content').setStyle('width',365);
					detail_width			= 400;
					fx_inner_content.cancel();
					fx_inner_content.start({'left':left_pos + 265, 'width':detail_width});
					fx_inner_content_background.cancel();
					fx_inner_content_background.start({'opacity':0.9});
					
					fxcontentShower.set({'opacity': 1});									
					
					if(mySpinner){
					   mySpinner.destroy();
					}
					allow_click		= true;
				}else{
					//post
					listing_thumb_array				= new Array;				
					listing_thumb_list				= $$('#inner_content_content img');
					initItem();
				}
			});
		break;
		case 'login_area_content':
			$(target).innerHTML = output;
			$(target).addEvent('domready', function() {
				
				if($('form_account')){
					ChangeAnim('height', $('login_area'), 210, 400, Fx.Transitions.Cubic.easeOut);
					ChangeAnim('height', $('login_area_background'), 210, 400, Fx.Transitions.Cubic.easeOut);
					setSomeForm('form_account','account_form','account_form','info_creation', false, 'submit_btn')
				}
				
				fxcontentShower					= MorpheItems(target, 400, Fx.Transitions.Cubic.easeOut);
				fxcontentShower.set({'opacity': 1});									
				if(mySpinner){
				   mySpinner.destroy();
				}
				allow_click		= true;
			});
		break;
		case 'items_suggest':
			$(target).innerHTML 	= output;
			$(target).addEvent('domready', function() {
				active_name_search	= false;
				mySpinner_search.toggle(target);
				mySpinner_search.destroy()
				$(target).setStyles({'opacity': 1});
			});
		break;
	}
}

function baseInitListing(loadImages){
	Log.log('baseInitListing : meaning : zet alle scrolls en dropdowns');
	fxcontentShower					= MorpheItems('inner_content_menu_listing', 400, Fx.Transitions.Cubic.easeOut);
				
	if($('listing_nav')){
		$('listing_nav').setStyles({'top': innerHeight});
		ChangeAnim('top', $('listing_nav'), innerHeight - 44, 1000, Fx.Transitions.Cubic.easeOut);
		setScollButtons();
	}
										
	if($('listing_container')){
		//innerheight - top position - listing nav height
		$('listing_container').setStyles({'height': innerHeight - 120});
	}
	
	if($('search_optioncategories')){
		loadDropDownActions('search_optioncategories','categories');		
	}
	
	listing_thumb_array				= new Array;				
	listing_thumb_list				= $$('#inner_content_menu_listing img');
	initList(loadImages);

}

function initList(loadImages){
	Log.log('init list : meaning : alle mouseovers voor de listing worden toegewezen + na inladen alles tonen!');
	
	if(loadImages){
	
		listing_thumb_list.each(function(element){
			listing_thumb_array.push(element.src);
		});	
		if(listing_thumb_array.length > 0){
			var myImages = new Asset.images(listing_thumb_array, {
				onComplete: function(){
					listing_thumb			= $$('.listing_thumb');
					listing_thumb.each(function(element) {
						var current 				= parseInt(element.getProperty('id').substring(14));
						fx_listing_thumb[current] 	= MorpheItems(element.getProperty('id'),400, Fx.Transitions.Cubic.easeOut);
						element.addEvent('mouseenter', function(event){ 
							var current = parseInt(element.getProperty('id').substring(14));
							fx_listing_thumb[current].cancel();
							fx_listing_thumb[current].start({'opacity':0.7});
						});
						element.addEvent('mouseleave', function(){
							var current = parseInt(element.getProperty('id').substring(14));
							fx_listing_thumb[current].cancel();
							fx_listing_thumb[current].start({'opacity':1});
						});
		
					});
				   
					fxcontentShower.set({'opacity': 1});									
					if(mySpinner){
					   mySpinner.destroy();
					}
					allow_click		= true;
					
					
					if(active_item!=0){
						if(swf_load_item){
							Log.log('swf_load_item');
							swf_load_item = false;
							swfOpenItem(active_item, active_categories, active_position);
						}else{
							Log.log('data is er al...laat zien....');
							if($('post_drag_area')){
								$('post_drag_area').setStyles({'height': innerHeight - 22});
								$('post_content_area').setStyles({'height': innerHeight - 44});
								setScroll('post_content', 'post_content_area', 'vertical');
							}					
							fxcontentShower					= MorpheItems($('inner_content_content'), 400, Fx.Transitions.Cubic.easeOut);
							listing_thumb_array				= new Array;				
							listing_thumb_list				= $$('#inner_content_content img');
							initItem();
							
							if(active_position!=0){
								var new_top				= 145 + Math.round((active_position - 1) * 151) - listScrollPosition;
								if(new_top<145){
									var diff			= 145 - new_top
									oldListScrollPosition	=listScrollPosition;
									listScrollPosition		-=diff;
									doScroll();
									new_top					= 145;
								}else if((innerHeight - new_top)<126){
									var diff				= 126 - (innerHeight - new_top)
									oldListScrollPosition	= listScrollPosition;
									listScrollPosition		+=diff;
									doScroll();
									new_top					= innerHeight - 126;
								}
								
								fx_indicator.cancel();
								fx_indicator.start({'top':new_top});
							}else{
								Log.log('no position');
							}
						}
					}
					/**/
				}
			});
		}else{
			fxcontentShower.set({'opacity': 1});									
			if(mySpinner){
			   mySpinner.destroy();
			}
			allow_click		= true;
		}
	}else{
		listing_thumb			= $$('.listing_thumb');
		listing_thumb.each(function(element) {
			var current 				= parseInt(element.getProperty('id').substring(14));
			fx_listing_thumb[current] 	= MorpheItems(element.getProperty('id'),400, Fx.Transitions.Cubic.easeOut);
			element.addEvent('mouseenter', function(event){ 
				var current = parseInt(element.getProperty('id').substring(14));
				fx_listing_thumb[current].cancel();
				fx_listing_thumb[current].start({'opacity':0.7});
			});
			element.addEvent('mouseleave', function(){
				var current = parseInt(element.getProperty('id').substring(14));
				fx_listing_thumb[current].cancel();
				fx_listing_thumb[current].start({'opacity':1});
			});

		});
	   
		fxcontentShower.set({'opacity': 1});									
		if(mySpinner){
		   mySpinner.destroy();
		}
		allow_click		= true;
	}
}

function openVideo(){
	if(flash_can){
		var thisVideo = new SWFObject(root_domain+'video.swf', 'video', 645, 377, "9", "000000");
		thisVideo.addParam('flashvars','&item_id='+video_id);
		thisVideo.addParam("scale", "noscale");
		thisVideo.addParam("quality", "high"); 
		thisVideo.addParam("allowscriptaccess", "all");
		thisVideo.addParam("allowFullScreen", "true"); 
		thisVideo.addParam("wmode", "window"); 
		thisVideo.addParam("codebase", "all"); 
		thisVideo.useExpressInstall('expressinstall.swf');
		thisVideo.write('video_container');
		allow_click		= true;
		video_id		= 0;
	}	
}

function dropDownHandler(value, click_target,element_txt){
	var selected_option	= value;
	switch(click_target){
		case 'categories':
			mySpinner 							= new Spinner('inner_content_menu_listing');
			mySpinner.show(true);	
			
			active_parent						= value;		
			var url				 				= root_domain + content_folder[active_current] + '/listing.php?include_header=2&categories='+categories_array[active_current]+'&parent='+value;
			loadNshow(url, 'listing_container', 'get', false);
			
			//resetDetail();
			fx_indicator.cancel();
			active_position						= 0;
			fx_indicator.start({'top':-50});
			
			resetScroll();
			
		break;
	}
}

function resetDetail(){
	active_item								= 0;
	$('inner_content_content').innerHTML 	= '';
	fx_indicator.cancel();
	active_position							= 0;
	fx_indicator.start({'top':-50});
	fx_inner_content.cancel();
	fx_inner_content.start({'left':0, 'width':0});	
	open_full 								= false; // resetten want item is gesloten!
					
}

var new_top;
function openItem(items_id, categories, position){
	//Log.log('open item : meaning : zet de indicator op de juiste plek / scroll listing indien nodig / laad het item in!');
	if(allow_click){
		allow_click 							= false;
		active_item								= items_id;
		
		$('inner_content_content').innerHTML 	= '';
		mySpinner 								= new Spinner('inner_content');
		mySpinner.show(true);
		
		active_position			= position;
		new_top					= 145 + Math.round((position - 1) * 151) - listScrollPosition;
		if(new_top<145){
			var diff			= 145 - new_top
			oldListScrollPosition	=listScrollPosition;
			listScrollPosition		-=diff;
			doScroll();
			new_top					= 145;
		}else if((innerHeight - new_top)<126){
			var diff				= 126 - (innerHeight - new_top)
			oldListScrollPosition	= listScrollPosition;
			listScrollPosition		+=diff;
			doScroll();
			new_top					= innerHeight - 126;
		}
		
		fx_indicator.cancel();
		fx_indicator.start({'top':new_top});
		
		navigating				= true;
		SWFAddress.setValue('/category/?page='+url_name[active_current]+'&item='+items_id+'&c='+categories+'&p='+position+'&parent='+active_parent);
		navigating				= false;
		url_to_load				= root_domain + content_folder[active_current] + '/detail.php?include_header=1&item='+items_id+'&categories='+categories;
		
		
		openItemLoad.delay(0);
	}
}

function openItemLoad(url){
	loadNshow(url_to_load, 'inner_content_content', 'get', false);
}

var video_id 	= 0;
function initItem(){
	//Log.log('open_full = ' + open_full);
	//Log.log('init item : meaning : laad alle images en laat alles zien (plus schuif menu naar links! en positioneer de rest!)');
	
	if(!open_full){
		left_pos 			= 46;
		initPage();
		initPageItem();
		fx_navigation.cancel();
		fx_navigation.start({'left':-219});
		fx_menu_maximized.cancel();
		fx_menu_maximized.start({'opacity':1});
		fx_menu_minimized.cancel();
		fx_menu_minimized.start({'opacity':1 , 'z-index':20 , 'left':219});
	}
	
	listing_thumb_list.each(function(element){
		listing_thumb_array.push(element.src);
	});	
	
	if(listing_thumb_array.length > 0 ){
		
		var myImages = new Asset.images(listing_thumb_array, {
			onComplete: function(){
				fxcontentShower.set({'opacity': 1});									
				if(mySpinner){
				   mySpinner.destroy();
				}
		
				if($('post_drag_area')){
					$('post_drag_area').setStyles({'height': innerHeight - 22});
					$('post_content_area').setStyles({'height': innerHeight - 44});
					setScroll('post_content', 'post_content_area', 'vertical');
				}

				initVideo();
			}
		});	
	
	}else{
		
		fxcontentShower.set({'opacity': 1});									
		if(mySpinner){
		   mySpinner.destroy();
		}
		
		if($('post_drag_area')){
			$('post_drag_area').setStyles({'height': innerHeight - 22});
			$('post_content_area').setStyles({'height': innerHeight - 44});
			setScroll('post_content', 'post_content_area', 'vertical');
		}
		initVideo();
	}
					
				
}

function initVideo(){
	if(active_categories==3){
		video_id 		= $('active_item').value;
		allow_click		= false;
		openVideo.delay(800);
	}else if($('is_video') && $('is_video').value == 'yes' && $('video_id') && $('video_id').value != ''){
		video_id 		= $('video_id').value;
		allow_click		= false;
		openVideo.delay(800);
		detail_width			= 690;
		fx_inner_content.cancel();
		fx_inner_content.start({'left':left_pos + 265, 'width':690});
		fx_inner_content_background.cancel();
		fx_inner_content_background.start({'opacity':0.9});
	}else{
		allow_click		= true;
		switch(active_current){
			case 1:
			case 2:
			case 3:
			case 4:
			case 7:
				detail_width			= 400;
			break;
			case 6:
				detail_width			= 320;
			break;
		}
		fx_inner_content.cancel();
		fx_inner_content.start({'left':left_pos + 265, 'width':detail_width});
		fx_inner_content_background.cancel();
		fx_inner_content_background.start({'opacity':0.7});
			
	}
}


//scrolling etc -- OK!
function setScroll(target, scroll_in, mode){
	if(mode == 'vertical'){
		var this_height 		= 0;
		var container_height 	= 0;
		var this_scrollheight	= 5000;
		
		this_height 			= parseInt($(target).getStyle('height')) + 200;
		
		if((active_categories==3) || ($('is_video') && $('is_video').value == 'yes' && $('video_id') && $('video_id').value != '')){
		this_height 			= 900;
		
		}
		//alert(this_height);
		container_height 		= parseInt($(scroll_in).getStyle('height'));
	
		var activeScrollElement 	= $(scroll_in);
		var activeScroll 			= new Fx.Scroll(activeScrollElement);
		var itemScrollPosition		= 0;
		var activeScrollheight		= this_height - container_height;
		activeScroll.set(itemScrollPosition, 0);
		
		var SliderObject = new Slider('post_drag_area', 'dragger', {
			//options
			range: [0,this_scrollheight],
			wheel: true,
			steps: this_scrollheight/5,
			snap: true,
			mode: 'vertical',
			//callback events
			onChange: function(pos){
				itemScrollPosition	= pos/this_scrollheight * activeScrollheight;
				activeScroll.set(0,itemScrollPosition);
			}
		});
	}		
}


var myScrollEffect;
var listScrollPosition 		= 0;
var oldListScrollPosition 	= 0;
function setScollButtons(){
	$('scroll_up').removeEvent('click', scrollUp);
	$('scroll_down').removeEvent('click', scrollDown);
	$('scroll_up_3').removeEvent('click', scrollUpTimesThree);
	$('scroll_down_3').removeEvent('click', scrollDownTimesThree);
	
	inList				= $('inList').value;
	listScrollPosition 	= 0;
	
	myScrollEffect = new Fx.Scroll('listing_container', {
		offset: {
			'x': 0,
			'y': listScrollPosition
		}
	}).toTop();

	$('scroll_up').addEvent('click', scrollUp);
	$('scroll_down').addEvent('click', scrollDown);
	$('scroll_up_3').addEvent('click', scrollUpTimesThree);
	$('scroll_down_3').addEvent('click', scrollDownTimesThree);
}

function scrollUp(){
	oldListScrollPosition	= listScrollPosition;
	listScrollPosition-=151;
	doScroll();
}

function scrollDown(){
	oldListScrollPosition	= listScrollPosition;
	listScrollPosition+=151;
	doScroll();
}

function scrollUpTimesThree(){
	oldListScrollPosition	= listScrollPosition;
	listScrollPosition-=3*151;
	doScroll();
	
}

function scrollDownTimesThree(){
	oldListScrollPosition	= listScrollPosition;
	listScrollPosition+=3*151;
	doScroll();
}

function doScroll(){
	if(myScrollEffect){
		myScrollEffect.cancel();
	}
	if(listScrollPosition<0){
		listScrollPosition = 0;
	}
	if(listScrollPosition > ((inList * 151) - (innerHeight - 120))){
		if((inList * 151) > (innerHeight - 120)){
			listScrollPosition = (inList * 151) - (innerHeight - 120);
		}else{
			listScrollPosition = 0;
		}
	}
	myScrollEffect = new Fx.Scroll('listing_container', {
		offset: {
			'x': 0,
			'y': listScrollPosition
		}
	}).toTop();
	
	
	if(active_item!=0){
		var change 						= listScrollPosition - oldListScrollPosition;
		var current_indicator 			= parseInt($('indicator').getStyle('top'));
	//	alert(oldListScrollPosition);
	//	alert(listScrollPosition);
		fx_indicator.cancel();
		fx_indicator.start({'top':current_indicator - change});
	}
}

function resetScroll(){
	oldListScrollPosition 	= 0;
	listScrollPosition 		= 0;
	
	myScrollEffect = new Fx.Scroll('listing_container', {
		offset: {
			'x': 0,
			'y': listScrollPosition
		}
	}).toTop();
}

//slides -- OK!
var active_slide			= 0;
var count_slides			= 0;
var slide_urls				= new Array();
var slide_urls_big			= new Array();
var slide_ttls				= new Array();
var fx_slide_info;

var allow_refresh			= true;
var allow_auto_refresh		= true;
var refresher;

function setSlideBase(){
		active_slide		= -1;
		var url_slides		= $('valuesURL_1').value;
		slide_urls			= url_slides.split('#');
		var url_slides_big	= $('valuesBigURL_1').value;
		slide_urls_big		= url_slides_big.split('#');
		var title_slides	= $('valuesTitles_1').value;
		slide_ttls			= title_slides.split('#');
		count_slides		= $('aantal_thumbs_1').value;
		setSlideAuto();
	
}
function setSlideManual(){
	$clear(refresher)
	var nr 			= active_slide
	if(nr < (count_slides-1)){
		nr++
	}else{
		nr			= 0;
	}
	setSlide(nr);
}
function setSlideAuto(){
	if(allow_auto_refresh){
		var nr 			= active_slide
		if(nr < (count_slides-1)){
			nr++
		}else{
			nr			= 0;
		}
		setSlide(nr);
	}else{
		$clear(refresher)
	}
}

function setSlide(nr){
	if(nr!=active_slide && allow_refresh == true){
		active_slide	= nr;
		allow_refresh	= false;
		loadNewSlide(root_domain + slide_urls[nr]);
	}
}

var current_img_fx_out;
var current_img_fx_in;
var this_breedte_image;
var this_hoogte_image;
var proportions_site;
var proportions_original;
				
function loadNewSlide(new_url){
		
		new Asset.images(new_url, {
			onProgress: function(i) {
				this_breedte_image 	= this.width;
				this_hoogte_image 	= this.height;
				this.setStyles({
					'opacity': 0
				});
			},
			onComplete: function() {
				
				proportions_original 	= this_hoogte_image/this_breedte_image;
	
				
				
				current_img_fx_out = new Fx.Morph($('slide_image'), {duration: 300, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
					
					current_img_fx_in = new Fx.Morph($('slide_image'), {duration: 300, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
						allow_refresh	= true;
						$clear(refresher);
						refresher		= setSlideAuto.periodical(25000);
					}});
					
					current_img_fx_in.set({'opacity': 0});
					$('slide_image').src = new_url;
					var new_width;
					var new_height;
					
					if(proportions_original >= proportions_site){
						new_height		= innerWidth * proportions_original
						if(new_height < innerHeight){
							new_height 		=  innerHeight;
							new_width 		=  new_height * proportions_original;
						}
						$('slide_image').setStyles({'width' : new_width, 'height' : new_height});
						$('slides_container').setStyles({'top' : 0, 'left' : 0});
						//$('slide_image').setStyle('width' ,innerWidth);
					}else{
						var new_width		= innerHeight / proportions_original
						$('slide_image').setStyles({'width' : new_width, 'height' : innerHeight});
						$('slides_container').setStyles({'left' : (innerWidth-new_width)/2 , 'top' : 0});
					}
					
					
					current_img_fx_in.cancel();
					current_img_fx_in.start({'opacity': 1});
					
					
				}});
					
				current_img_fx_out.cancel();
				current_img_fx_out.start({'opacity': 0});
				
			}
		});
		
}

function resizeBG(){
	var new_width;
				var new_height;
				if(proportions_original >= proportions_site){
		new_height		= innerWidth * proportions_original
		if(new_height < innerHeight){
			new_height 		=  innerHeight;
			new_width 		=  new_height * proportions_original;
		}
		$('slide_image').setStyles({'width' : new_width, 'height' : new_height});
		$('slides_container').setStyles({'top' : 0, 'left' : 0});
	}else{
		new_width		= innerHeight / proportions_original
		if(new_width < innerWidth){
			new_width 		=  innerWidth;
		}
		$('slide_image').setStyles({'width' : new_width, 'height' : innerHeight});
		$('slides_container').setStyles({'left' : (innerWidth-new_width)/2 , 'top' : 0});
	}
}

var main_parent_name	= '';
var parent_name			= '';
var main_parent_id		= 0;
var parent_id			= 0;

String.prototype.stripSpaces = function( ){ 
	var test = this; 
	test = test.replace( /&nbsp;/, "" ); 
	test = test.replace( /\s/g, "-" ); 
	test = test.replace( '/', "-" ); 
	test = test.replace( /[\(\)\.\\ ]/g, '');

	return test; 
};


var comments = false;

function viewComments(thisItem){
	Log.log('view comments');
	if(allow_click){
		allow_click 			= false;
		mySpinner 				= new Spinner('inner_content');
		mySpinner.show(true);
		url_to_load				= root_domain + content_folder[active_current] + '/comment/index.php?include_header=1&parent='+thisItem;
		loadNshow(url_to_load, 'post_content', 'get', false);
	}
}
function createAccount(){
	Log.log('createAccount');
	if(allow_click){
		allow_click 			= false;
		mySpinner 				= new Spinner('inner_content');
		mySpinner.show(true);
		url_to_load				= root_domain + content_folder[active_current] + '/comment/account_create.php?include_header=1';
		loadNshow(url_to_load, 'login_area_content', 'get', false);
	}
}

var active_name_search					= false;
function checkSearchName(input){
	if(input.length > 2){
		if(!active_name_search){
			active_name_search				= true;
			mySpinner_search 				= new Spinner('items_suggest');
			mySpinner_search.show(true);
			loadNshow(root_domain + 'zoek/name_search.php?include_header=1&search='+input,'items_suggest', 'get', false);
		}
	}else{
		$('items_suggest').innerHTML					= '';	
	}
}

function initNameSearch(input){
	if(input == 'search'){
		$('searchvalue').value					= '';
		$('items_suggest').innerHTML			= '';
	}
}

