function hideSidebar() {
	$("#sidebarCell").hide();
	$("#content").attr("class","noSidebar");
	$("#mainBodyCell").width(706);
	stretchBodyCell();
}

function showSidebar() {
	$("#sidebarCell").show();
	$("#content").attr("class","");
	$("#mainBodyCell").width(528);
	stretchBodyCell();
}

function stretchBodyCell(){
	//var dochoogte = $(document).height();
	//var target = dochoogte-330;
	//$("#bodyMain").height(target);
}

/*****************************
/* 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 processZoomImages(path){

	$("a[class^=zoomImage]").each(
		function(){
			var obj=$(this);
			var thumbsizeArr,thumbwidth,thumbheight,urlParts,server,relpath,query			
			if(obj.attr("rel").indexOf("x")>1){
				thumbsize = obj.attr("rel");
				thumbsizeArr = thumbsize.split("x");
			}else{
				thumbsize = obj.attr("class").split("_")[1];
				thumbsizeArr = thumbsize.split("x");
			}
			var thumbwidth = thumbsizeArr[0];
			var thumbheight = thumbsizeArr[1];
			var urlParts = /^(https?:\/\/.+?)?(\/.+?)(\?.*?)?$/.exec(obj.attr("href")); 
			var server = urlParts[1]; // maybe be '' depending on the browser 
			var relpath = urlParts[2]; 
			var query = urlParts[3]; 
			$.ajax({
				  url: path,
				  data : {
				  	  file : relpath,
					  width : thumbwidth,
					  height : thumbheight
				  },
				  success: function(data) {
					obj.html("<img src='"  + data.thumb + "' alt='' />");
				  },
				  dataType:"json"
			});
			obj.fancybox({
				'transitionIn'	:	'elastic',
				'transitionOut'	:	'elastic',
				'speedIn'		:	200, 
				'speedOut'		:	200, 
				'overlayShow'	:	false
			});
		}
	)
}

function loadCalendar(params){
	$.ajax( { 
	  type: 'get', 
	  url: "/templates/sodalis/includes/includeCalendarEvents.asp", 
	  data: params,
	  success:function(r){
	  	$("#bodyMain").html(r);
		stretchBodyCell();
	  }
	} ); 	
}
function loadCalendarItem(calendarId){
	$.ajax( { 
	  type: 'get', 
	  url: "/templates/sodalis/includes/includeCalendarEvent.asp", 
	  data: {
	  	calendarId:calendarId,
		websiteLanguage:websiteLanguage
	  },
	  success:function(r){
	  	$("#bodyMain").html(r);
		stretchBodyCell();
	  }
	} ); 	
}
function loadWhoiswho(){
	$.ajax( { 
	  type: 'get', 
	  url: "/templates/sodalis/includes/includeWhoiswho.asp", 
	  data: {
		websiteLanguage:websiteLanguage
	  },
	  success:function(r){
	  	$("#bodyMain").html(r);
		stretchBodyCell();
	  }
	} ); 	
}
function loadFolderTrees(){
	$('.folderTree').each(function(index){
		$(this).fileTree({  
	        root: $(this).attr("rel"),  
	        script: '/admin/js/jqueryFileTree/connectors/jqueryFileTree.asp',  
	        expandSpeed: 300,  
	        collapseSpeed: 300,  
	        multiFolder: false 
	    }, function(file) {  
	        window.open(file,'Download');  
	    });
	});
}
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();
			break;
		case "blog":
			if(SWFAddress.getParameter("calendarId")){
				loadCalendarItem(SWFAddress.getParameter("calendarId"));
				hideSidebar();
			}else{
				loadCalendar(parameterList);
				showSidebar();
			}
			break;
		case "whoiswho":
			loadWhoiswho();
			break;
	}
	stretchBodyCell();
}

$(function(){
		SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
		// folderTrees
		loadFolderTrees();
		stretchBodyCell();

});
$(window).resize(function(){
		stretchBodyCell();
	}
);
