function showBusyOverlay() {
	updateBusyOverlayPosition();
	if($('#busyoverlay')!=null)
		$('#busyoverlay').show();
}

function hideBusyOverlay(){
	if($('#busyoverlay')!=null)
		$('#busyoverlay').hide();
}

function hideSidebar() {
	$("#sidebarCell").hide();
}

function showSidebar() {
	$("#sidebarCell").show();
}

function hideMenu2(){
	$("#menu2").hide();
	stretchBodyCell();
}
function showMenu2(){
	$("#menu2").show();
	stretchBodyCell();
}


function stretchBodyCell(){
	var dochoogte = $(document).height();
	var bodyMainMargin = 40;
	var headerhoogte = $("#headerCell").height();
	var creditshoogte = $("#creditsCell").height();

	//$("#bodyMain").height(dochoogte - headerhoogte - creditshoogte);	
	$("#menuCell").height(dochoogte - headerhoogte);
}

function updateOverlaySize() {
	var arrayPageSize = getPageSize();
	$('#overlay').width(arrayPageSize[0]);
	$('#overlay').height(arrayPageSize[1]);
}

function updateBusyOverlayPosition() {
	var arrayPageSize = getPageSize();
	if($('#busyoverlay')!=null){
		$('#busyoverlay').css('left',Math.round((arrayPageSize[0]-156)/2) + 'px');
		$('#busyoverlay').css('top',Math.round((arrayPageSize[1]-8)/2) + 'px');
	}
}

/*****************************
/* algemene functies
/****************************/
	

function createPopupWindow(html,name,width,height) {
	var n=open
	( 
	html, name, 
	'width='+width+',height='+height
	+',left='+(screen.width -width )/2
	+',top=' +(screen.height-height)/2
	+',status=0,menubar=0,toolbar=0,scrollbars=0,resizable=1'
	);
	n.focus();
}

function getPageSize() {
	return [$(document).width(),$(document).height()];
}

function loadCalendar(params){
	$.ajax( { 
	  type: 'get', 
	  url: "/templates/vision/includes/includeCalendarEvents.asp", 
	  data: params, 
	  beforeSend: function(r){
	  	showBusyOverlay();
	  },
	  complete: function(r) { 
	    hideBusyOverlay();
	  }, 
	  success:function(r){
	  	$("#bodyMain").html(r);
		stretchBodyCell();
		updateOverlaySize();
	  }
	} ); 	
	
}
function hideTitle(){
	$('#pageTitle').hide();
}

function setBodyMainClass(c){
	$('#bodyMain').addClass(c);
}

/*****************************
/* SWFADDRESS
/****************************/

function handleChange(event) {
    var parameters = new Array();
	var parameterNames = new Array();
	var parameterList = '';
	var alias='';
	var i=0;
    for (var p in event.parameters) {
		parameterNames[i] = p;
        parameters[i] = event.parameters[p];
		parameterList+=parameterNames[i] + '=' + parameters[i] + '&';
		i++;
    }
	alias=event.path.substring(1,event.path.length-1);
	
	switch(alias){
		case "home":
			hideTitle();
			hideSidebar();
			break;
		case "blog":
			loadCalendar(parameterList);
			hideSidebar();
			break;
		case "projects":
			var flashV = {	
				project:SWFAddress.getParameter("project")
			};
			var att = { 
				data:'/templates/vision/swf/projects.swf', 
				width:687, 
				height:470, 
				bgcolor:'#FFFFFF', 
				menu:'false',
				wmode:'transparent'
			};
			var par = {flashvars:jQuery.param(flashV),wmode:'transparent'};
			var id = 'pageHtml';
			var myObject = swfobject.createSWF(att, par,id);		
			
			hideSidebar();
			showMenu2();
			setBodyMainClass('projects');
			break;
		case "process":
			hideSidebar();
			setBodyMainClass('projects');
			break;
		case "contact":
			hideTitle();
			hideSidebar();
			setBodyMainClass('contact');
			break;
		case "tools":
			var flashV = {	
				tool:SWFAddress.getParameter("tool"),
				nos:SWFAddress.getParameter("nos")
			};
			var att = { 
				data:'/templates/vision/swf/tools.swf', 
				width:480, 
				height:320, 
				bgcolor:'#FFFFFF', 
				menu:'false',
				wmode:'transparent'
			};
			var par = {flashvars:jQuery.param(flashV),wmode:'transparent'};
			var id = 'toolsFlash';
			var myObject = swfobject.createSWF(att, par,id);		
			break;
		case "customers":
			hideSidebar();
			break;
	}
	stretchBodyCell();
	updateOverlaySize();
}

$(function(){
		stretchBodyCell();
		updateOverlaySize();
		SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
		// folderTrees
		$('.folderTree').each(function(index){
			$(this).fileTree({  
		        root: $(this).attr("rel"),  
		        script: '/admin/js/jqueryFileTree/connectors/jqueryFileTree.asp',  
		        expandSpeed: 300,  
		        collapseSpeed: 300,  
		        multiFolder: true 
		    }, function(file) {  
		        window.open(file,'Download');  
		    });
		});

});
$(window).resize(function(){
		stretchBodyCell();
		updateOverlaySize();
	}
);
