$(function(){

	$('a.print').click(function()
	{
		print();		
		return false;
	});

	$("a[href^='http://']:not([href*='"+window.location.hostname+"'])").click(function()
	{
		if(_gaq)
		{
			_gaq.push(['_trackEvent', 'links', 'external', $(this).attr('href')]);
		}
	});
	
	$('.small_header_title').click(function()
	{
		var url = $(this).siblings(':first').children(":first").attr('href');
		if(url!==undefined)
		{
			window.location = url;
		}
	});
	
	$('#debug').toggle(function ()
	{
		$('body').addClass("bgon");
		},function()
		{
			$('body').removeClass("bgon");
	});
	
// !search header

	$('.input_search').focus(function(){
		if($(this).val() == $(this).attr('name')){
			$(this).val('');
		}
		$(this).addClass('active')
	})
	$('.input_search').blur(function(){
		if(!$(this).val()){
			$(this).val($(this).attr('name'))
		}
		$(this).removeClass('active')
	})
	
// !carousel	

	$('.zinfinitecarousel').zinfinitecarousel({
		timer: true
	});

	$('.programme_home, .news_home, .profiles_home').zcarousel();
	//$('.calendar_home').zcarousel2();


	if($('.calendar_home').length){
		$('.calendar_home').zcarousel({
			minuswidth : $('.calendar_home').offset().left,
			ajax: false,
			start: parseFloat($('.calendar_home').attr('rel'))
		});
	}
/*
	if($('.twitter_home').length){
		$('.twitter_home').zcarousel({
			minuswidth : $('.twitter_home').offset().left,
			ajax: false
		});
	}
*/	
	if($('#related_items').length){
		$('#related_items').zcarousel({
			minuswidth : $('#related_items').offset().left,
			ajax: false
		});
	}
	if($('#related_content').length){
		$('#related_content').zcarousel({
			minuswidth : ($('#related_content').offset().left + 32),
			ajax: false
		});
	}
	if($('.news_detail').length){
		$('.news_detail').zcarousel({
			minuswidth: $('.news_detail').offset().left,
			ajax: false
		});
	}
	if($('#related_profiles').length){
		$('#related_profiles').zcarousel({
			minuswidth : ($('#related_profiles').offset().left + 15),
			ajax: false
		});
	}	

// !twitter

	$(".twitter_content").tweet({
            join_text: "auto",
            count: 30,
            avatar_size:48,
			query: "dutchdfa",
            auto_join_text_default: "",
            auto_join_text_ed: "",
            auto_join_text_ing: "",
            auto_join_text_reply: "",
            auto_join_text_url: "",
            loading_text: "loading tweets...",
            onComplete: function(){
            	$('#twitter ul.items').html($('ul.twitter_source').html());
            	//Now activate zcarousel for twitter bar
				$('.twitter_home').zcarousel({
					minuswidth : $('.twitter_home').offset().left,
					ajax: false
				});   
				var height = Math.ceil($('#twitter ul.items li:eq(6)').height());
            }
	});

//OBSOLETED 20111209 
/*
	$('#twitter .down:not(.disabled)').live('click', function(){
		var el = $(this);

		$('.twitter_content li.active').removeClass('active').nextAll('.firsts:first').addClass('active');
		var beginning = $('.twitter_content li.active').position().top;
		if($('.twitter_content li.active').nextAll('.firsts:first').length){
			var end = $('.twitter_content li.active').nextAll('.firsts:first').position().top;		
		} else {
			var end = $('.twitter_content li:last').position().top + $('.twitter_content li:last').outerHeight() + 1;
			el.addClass('disabled');
		}
		var height = Math.ceil(end - beginning);

		var old_height = $('.tweet_list').parent().height();
		$('.twitter_content').animate({
			height: height
		}, 300);
				
		$('.tweet_list').animate({top: '-=' +old_height}, 200, function(){
			var total_height = $('.tweet_list').height();
			var twitter_position = ($('.tweet_list').position().top * -1) + $('.twitter_content').height();
			if(twitter_position > total_height){
				el.addClass('disabled');
			}
		})
		el.parents('#twitter').find('.up').removeClass('disabled');
	})
	$('#twitter .up:not(.disabled)').live('click', function(){
		var el = $(this);
		
		var end = $('.twitter_content li.active').position().top;
		$('.twitter_content li.active').removeClass('active').prevAll('.firsts:first').addClass('active');
		var beginning = $('.twitter_content li.active').position().top;				
		
		if(beginning == 0){
			el.addClass('disabled');
		}

		var height = Math.ceil(end - beginning);

		var old_height = $('.tweet_list').parent().height();
		
		$('.twitter_content').animate({
			height: height
		}, 300)

		$('.tweet_list').animate({top: '+=' + height}, 200, function(){
			var total_height = $('.twitter_content').height();
			var twitter_position = ($('.tweet_list').position().top * -1) + $('.twitter_content').height();
			if(twitter_position == total_height){
				el.addClass('disabled');
			}
		})
		el.parents('#twitter').find('.down').removeClass('disabled');
	})
*/

// !newsdetail	
	
	// correct odd/even on related news articles
	if($('#related_items').length){
		$('#related_items .odd').removeClass('odd')
		$('#related_items li:odd').addClass('odd')		
	}
		
// !calendar

/*
	if($('#calendar').length){
		var steps = 5;
		var calendar_content = $('.calendar_content');
		// set present/now element on top
		var offsetTop = calendar_content.find('.now').position().top;
		if(offsetTop != 0){
			calendar_content.find('ul').css({top: (offsetTop * -1)});
		} else {
			$('#calendar .up').addClass('disabled');
		};
		
		// add class to 'last' element
		var last = calendar_content.find('li.now').index() + steps;
		if(calendar_content.find('li').eq(last).length){
			calendar_content.find('li').eq(last).addClass('last');
		} else {
			calendar_content.find('li:last').addClass('last');			
			$('#calendar .down').addClass('disabled');
		};
		if(!calendar_content.find('li').eq(last + 1).length){
			$('#calendar .down').addClass('disabled');
		};
		// add class to 'first' element
		calendar_content.find('li.now').addClass('first')
		
		// set height of container
		var height = calendar_content.find('li.last').position().top + calendar_content.find('li.last').outerHeight() - offsetTop;
		calendar_content.height(height);
		
		$('#calendar .up:not(.disabled)').live('click', function(){
			var el = $(this);
			$('#calendar .down.disabled').removeClass('disabled');
			var last = calendar_content.find('.first').removeClass('first').prev().addClass('last').index();
			
			if((last - steps) > 0){
				calendar_content.find('li').eq(last - steps).addClass('first')
			} else {
				calendar_content.find('li:first').addClass('first')
				$('#calendar .up').addClass('disabled');
			}
			if(!calendar_content.find('li').eq(last - steps + 1).length){
				$('#calendar .up').addClass('disabled');				
			}
			calendar_content.find('ul').animate({
				top: (calendar_content.find('li.first').position().top * -1)
			})
			
			var beginning = calendar_content.find('.first').position().top;
			var end = calendar_content.find('.last').position().top + calendar_content.find('.last').outerHeight();
			calendar_content.animate({
				height: (end - beginning)
			})
		})
		$('#calendar .down:not(.disabled)').live('click', function(){
			var el = $(this);
			$('#calendar .up.disabled').removeClass('disabled');
			calendar_content.find('.first').removeClass('first')
			var first = calendar_content.find('.last').removeClass('last').next().addClass('first').index();
			
			if(calendar_content.find('li').eq(first + steps).length){
				calendar_content.find('li').eq(first + steps).addClass('last')
			} else {
				calendar_content.find('li:last').addClass('last')
				$('#calendar .down').addClass('disabled');
			}
			if(!calendar_content.find('li').eq(first + steps + 1).length){
				$('#calendar .down').addClass('disabled');				
			}
			calendar_content.find('ul').animate({
				top: (calendar_content.find('li.first').position().top * -1)
			})
			
			var beginning = calendar_content.find('.first').position().top;
			var end = calendar_content.find('.last').position().top + calendar_content.find('.last').outerHeight();
			calendar_content.animate({
				height: (end - beginning)
			})
		})			
	}
*/

// !newsletter

	$('#newslettersubscribe').validate({
		errorPlacement: function(error, element){
			element.parent().append(error)
		},
		submitHandler: function(form){
			$.ajax({
				type: $(form).attr('method'),
				url: $(form).attr('action'),
				data: $(form).serialize(),
				dataType: 'json',
				success: function(result){
					if(result.success){
						$(form).fadeOut(200, function(){
							$(form).after('<p class="newsletter_result">' + result.message + '</p>')
							$('.newsletter_result').click(function(){
								$(this).remove();
								$(form).fadeIn();
							})
						})
					} 
					/*
					if(result.success){
						$(form).fadeOut(200, function(){
							$(form).after('<p class="newsletter_result">' + result.message + '</p>')
						})
					}
					*/
				}
			})			
		}
	})
	$("a[href^='#subscribe']").click(function(){
		$('#newslettersubscribe input:first').focus();
		return false;
	})	

// !start it up!
	
	$("#sort_" + sortOrder).addClass('active');
	var pageTypeBody = $('body').attr('id');
	pageType = pageTypeBody.substr(5, pageTypeBody.length);
	
	if(pageType == 'news' || pageType == 'profile' || pageType == 'nlmap')
	{
		boxWidth = eval('boxWidth' + pageType);
		boxHeight = eval('boxHeight' + pageType);
		searchString = $('#search').attr('value');

		$('#overview li').live('new', function()
		{			
			var el = $(this);
			var id = el.attr('rel');
			
			$.ajax(
			{
				type: 'get',
				url: '/site/ajax/'+pageType+'article.php',
				data: 'offset=-' + id + '&ajax=true',
				dataType: 'json',
				success: function(result)
				{
					if(result.success)
					{
						el.html(result.article)
						el.find('a').trigger('mouseover')
						el.fadeIn('fast');
					}
				}
			})
		});
		
		initTopics();
		
		if(pageType == 'nlmap')
		{
			initTypes();
		}
		
		getArticleArray();
		
		for(var i = 0; i < topicArray.length; i++)
		{
			$('#show_' + i).click(function()
			{
				var idstr = $(this).attr('id');
				var id = idstr.substring(5, idstr.length);
				topicActivate(id);
			});
		}
		
		for(var i = 0; i < totalTypes; i++)
		{
			$('#type_' + i).click(function()
			{
				var idstr = $(this).attr('id');
				var id = idstr.substring(5, idstr.length);
				typeActivate(id);
			});
		}
		
		$('#sort_new').click(function()
		{
			sortActivate('new');
		});
		
		$('#sort_viewed').click(function()
		{
			sortActivate('viewed');
		});
	
		$(".btn_viewmore").click(function()
		{
			articleMore();
			return false;
		});

		// !overview search	
		
		$('#frmSearchSubmit').click(function()
		{
			$('#frmSearch').submit();
		});
		
		$('#frmSearchDelete').click(function()
		{
			clearSearch();
		});
					
		if($('#search').attr('value') != '')
		{
			$('#search_delete').css('display', 'block');
		}
		
		$('#search').keyup(function()
		{
			clearTimeout(searchTimer);
			searchString = $(this).attr('value');
			
			
			
			if(searchString != '')
			{
				searchTimer = setTimeout(goSearch, 600);
				window.curSearchValue = searchString;
			}
		});
	
		$('#search_delete').click(function()
		{
			$('#overview ul').html('');
			searchString = '';
			$('#search').attr('value','');
			getArticleArray();
			$(this).hide();
			return false;
		});
	
		function goSearch()
		{
			clearTimeout(searchTimer);	
			$('#overview ul').html('');
			getArticleArray();
			$('#search_delete').show();
		}
		
		//disable enter
		
		$(document).keypress(function(e)
		{
			var key = 0;
			if (e == null) {
				key = event.keyCode;
			} else { // mozilla
				key = e.which;
			} 
			if(e.which == 13) //enter
			{
				return false;
			}
		});
	}
	
	
	
	
	
	position: { target: $('ul:first li:last') }
	
	$('#main a[tooltip]').each(function()
	{
		$(this).qtip({
			content: $(this).attr('tooltip'), // Use the tooltip attribute of the element for the content
			position: {
				adjust: { x: 5, y: 5 },
      			corner: {
				target: 'topLeft',
				tooltip: 'leftBottom'
				}
			},

			style:{
			name: 'light', // Give it a crea mstyle to make it stand out
			border: { width: 2, radius: 4 },
			tip: { corner: 'bottomLeft' }
			}
		});
	});
	
	if($('.form').length){
		$('.form').each(function(){			
			$(this).validate({
				errorPlacement: function(error, element){
					if(element.is(':radio')){
						element.closest('.radiocontainer').append(error)
					} else {
						element.after(error)
					}
				},
				submitHandler: function(form){
					$(form).find("input[type='submit']").attr('disabled', 'disabled');
					form.submit();
				}
			})			
		})
	}





	resizeFooter();
	sizeSubMenus();
	resizeSide();

});

/* !init variables */

var curSearchValue= '';
var sortOrder = 'new';
var articleArray = new Array();
var topicActive;
var typeActive = 0;
var totalActive = 0;
var activeArray = new Array();
var showMoreLink = true;
var topicArray = new Array('dutch', 'design', 'fashion', 'archi', 'all');
var totalTopics = topicArray.length;
var totalTypes = 11;
var boxWidthnews = 208;
var boxHeightnews = 216;
var boxWidthnlmap = 208;
var boxHeightnlmap = 216;
var boxWidthprofile = 272;
var boxHeightprofile = 234;
var boxMargin = 16;
var boxEvenTopMargin = 11;
var sorted = false;
var showMoreLink = false;
var totalArticlesDisplay;
var totalArticles;
var totalArticlesStart;
var totalInRow = 0;
var totalRowsStart = 3;
var totalRows;
var animateDuration = 200;
var totalViewmoreRows = 4;
var searchTimer;
var searchString = '';
var notfoundStringnews = 'Sorry, no matching articles found.';
var notfoundStringnlmap = 'Sorry, no matching articles found.';
var notfoundStringprofile = 'Sorry, no matching profiles found.';
var pageType = '';

/* !get articles and update */

function getArticleArray() // array is ['dutch:0','design:0','fashion:0','archi:0','active:1','id:0','stats:0','orig_order:0','type_id:0']
{
	articleArray = new Array();
	
	$.ajax({
		cache: 'false',
		type: 'get',
		url: '/site/ajax/getarticles.php',
		data: 'search=' + searchString + "&type=" + pageType,
		dataType: 'json',
		success: function(result)
		{
			if(result)
			{
				if(result.length > 0){
			 
					for(var i = 0; i < result.length; i++)
					{
						articleArray[i] = new Array();
						
						for(var j = 0; j < result[i].length; j++)
						{
							articleArray[i][j] = result[i][j];
						}	
					}
					totalArticles = articleArray.length;
					
					if (searchString != '' && sortOrder != 'new')
					{
						sortArray(sortOrder);
					}
					updateArticles();
				}
			}else
			{
				//no results
				$('#overview ul').html('<strong>' + eval('notfoundString' + pageType)+'</strong>');
				$("#viewmore").hide();
				$('#overview').height(100);
				resizeFooter();
			}
		}
	})
}

function updateArticles()
{
			
	// more link deactivated
	
	$("#viewmore").hide();	
	showMoreLink = false;
			
	// empty activeArray and make new one
	
	activeArray = new Array();
	totalActive = 0;
		
	for(var i = 0; i < totalArticles; i++)
	{				
		
		// topics
		
		if(topicActive == 4) // show all
		{
			for(var j = 0; j < totalTopics; j++) // loop through topics
			{
				if(articleArray[i][j] == 1) // this topic is active, break after this one
				{
					
					var curType = articleArray[i][8];
					
					//debug.log(curType+' | '+typeActive);
			
					if(curType == typeActive || typeActive == 0)
					{
						activeArray[totalActive] = new Array();
						activeArray[totalActive][0] = totalActive;
						activeArray[totalActive][1] = articleArray[i][5]; // id from article	
						activeArray[totalActive][2] = j;  // topic
						totalActive++;					
						break;
					}
				}
			}
		
		}else if(articleArray[i][topicActive] == 1) //dutch design fashion archi = 1
		{
			var curType = articleArray[i][8];
			
			//debug.log(curType+' | '+typeActive);
			
			if(curType == typeActive || typeActive == 0)
			{
				activeArray[totalActive] = new Array();
				activeArray[totalActive][0] = totalActive;		
				activeArray[totalActive][1] = articleArray[i][5]; // id from article
				activeArray[totalActive][2] = topicActive; // topic
				totalActive++;
			}
		}	
	}

	totalInRow = getTotalInRow();
	
	//totalArticlesStart = Math.ceil(totalRowsStart * totalInRow);
	totalArticlesStart = Math.ceil(totalRowsStart * totalInRow) - 1; // -1 because of introduction text

	if(totalActive < totalArticlesStart)
	{
		totalArticlesDisplay = totalActive;
	}else
	{
		totalArticlesDisplay = totalArticlesStart;
	}
	
	// remove articles
	
	for(var i = 0; i < totalArticles; i++)
	{	
		$("#article_" + i).remove();
		articleArray[i][4] = 0;
	}
	
	if(totalActive == 0) //when the user clicks a topic and there are no matches
	{
		$('#overview ul').html('<strong>'+eval('notfoundString'+pageType)+'</strong>');
	}
	
	// place and load articles on stage
	
	for(var i = 0; i < totalArticlesDisplay; i++)
	{
		articleArray[activeArray[i][0]][4] = 1; // set visibility of this article to 1
		
		if($("#article_" + activeArray[i][0]).length > 0) // does the article exsist?
		{
			//remove classes
			$("#article_" + activeArray[i][0]).removeClass("dutch");
			$("#article_" + activeArray[i][0]).removeClass("design");
			$("#article_" + activeArray[i][0]).removeClass("fashion");
			$("#article_" + activeArray[i][0]).removeClass("archi");
			
			//add class
			$("#article_" + activeArray[i][0]).addClass("dutch");
			
		}else
		{
			var arrayid = i;
			var id = activeArray[i][1];
			
			$('#overview ul').append('<li class="art_small news" rel="' + id + '" id="article_' + arrayid + '"></li>');
			$("#article_" + arrayid).addClass(topicArray[activeArray[i][2]]);
			$('#article_'+ arrayid).hide(); // show again when loaded
		}
	}

	$('#overview li').each(function(){
		$(this).trigger('new')
	})

	if(totalArticlesDisplay < totalArticlesStart) // hide more link if total start articles are less then standard
	{
		$("#viewmore").hide();	
		showMoreLink = false;
	}else
	{
		$("#viewmore").show();	
		showMoreLink = true;
	}
	
	updatePositions();
}

function articleMore()
{
	//update totals
	var tempTotal = totalArticlesDisplay;
	totalInRow = getTotalInRow();
	//totalArticlesDisplay = Math.ceil(totalArticlesDisplay / totalInRow) * totalInRow;
	
	//totalArticlesDisplay = Math.ceil((totalArticlesDisplay / totalInRow) * totalInRow)-1;
	totalArticlesDisplay += totalInRow * totalViewmoreRows;
	if(totalArticlesDisplay > totalActive)
	{
		totalArticlesDisplay = totalActive;
	}
	
	//load new items	
	
	for(var i = 0; i < totalArticlesDisplay; i++)
	{
		articleArray[activeArray[i][0]][4] = 1; // set visibility of this article to 1
		
		if($("#article_" + activeArray[i][0]).length == 0) // doesn't the article exsist?
		{
			var arrayid = i;
			var id = activeArray[i][1];
			
			$('#overview ul').append('<li class="art_small news" rel="'+id+'" id="article_'+ arrayid +'"></li>');
			$("#article_" + arrayid).addClass(topicArray[activeArray[i][2]]);
			$('#article_'+ arrayid).hide(); // show again when loaded
			$('#article_'+i).trigger('new');
		}
	}
	
	if(totalArticlesDisplay < totalArticlesStart) // hide more link if total start articles are less then standard
	{
		$("#viewmore").hide();	
		showMoreLink = false;
	}else
	{
		$("#viewmore").show();	
		showMoreLink = true;
	}
	
	if(totalArticlesDisplay == totalActive)
	{
		//all articles are shown
		$("#viewmore").hide();	
		showMoreLink = false;
	}
	
	updatePositions();
}



/* !show category (all, design, fashion, architecture) */

function initTopics()
{	
	if($.cookie('topic_active_cookie' + pageType) != null)
	{
		topicActive =  $.cookie('topic_active_cookie' + pageType);
	}else
	{
		$.cookie('topic_active_cookie' + pageType, 4, { path: '/' });
		topicActive = 4;
	}
	$("#show_" + topicActive).addClass('active');
}

function topicActivate(topicId)
{	
	$('#overview ul').html('');
	$("#show_" + topicActive).removeClass('active');
	topicActive = topicId;
	$.cookie('topic_active_cookie' + pageType, topicId, { path: '/' });
	$("#show_" + topicActive).addClass('active');
	updateArticles();
}

/* !sorting (new, most viewed) */

function sortArray(order)
{
	switch(order)
	{
		case 'new':
			articleArray.sort(sortNew);		
		break;
		
		case 'viewed':
			articleArray.sort(sortView);
		break;
	}
	sorted = true;
	updateArticles();
}

function sortView(a, b)
{
	return b[6] - a[6];
}

function sortNew(a, b)
{
	return a[7] - b[7];
}

function sortActivate(sorting)
{
	$("#sort_" + sortOrder).removeClass('active');
	sortOrder = sorting;
	$("#sort_" + sortOrder).addClass('active');
	sortArray(sortOrder);
}

/* !types (used in nlmap) */

function initTypes()
{	
	if($.cookie('type_active_cookie'+pageType) != null)
	{
		typeActive =  $.cookie('type_active_cookie' + pageType);
	}else
	{
		$.cookie('type_active_cookie' + pageType, 0, { path: '/' });
		typeActive = 0;
	}
	$("#type_" + typeActive).addClass('active');
}

function typeActivate(typeId)
{	

	$('#overview ul').html('');
	$("#type_" + typeActive).removeClass('active');
	typeActive = typeId;
	$.cookie('type_active_cookie' + pageType, typeId, { path: '/' });
	$("#type_" + typeActive).addClass('active');
	updateArticles();
}

/* !positioning */

function getTotalInRow()
{
	var e = clientCoords();
	var winWidth = e.w; 
	var winHeight  = e.h;
	//debug.log(winWidth+' / '+boxWidth + boxMargin);
	return Math.floor((winWidth - boxMargin) / (boxWidth + boxMargin));	
}

function updatePositions()
{
	var e = clientCoords();
	var winWidth = e.w; 
	var winHeight = e.h;	
	
	var curRow = 1;
	var curBox = 0;
	var startY = 0;
	var startX = 0;
	
	totalInRow = getTotalInRow();
	totalRows = Math.ceil((totalArticlesDisplay+1) / totalInRow);
	
	/*
if(totalInRow == 1)
	{
		totalRows++;
		var extrarow = true;
		//extra row because of introduction text
	}else
	{
		var extrarow = false;
	}
*/

	var firstrow = true;

	for(var i = 0; i < totalRows; i++)
	{	
		if(totalInRow == 1 && i==0)
		{
			firstrow = false;
			totalRows++;
			i++;
			debug.log('FIRST EXTRA ROW ITEM');
		}
		
		
		
		for(var j = 0; j < totalInRow; j++)
		{
			
			if(firstrow)//first row, show introduction text
			{
				firstrow = false;
				j = 1;
				debug.log('FIRST ROW ITEM');
			}
			
			
			if(curBox < totalArticlesDisplay)
			{	
				
				
				
				var newX = startX + (j * (boxWidth + boxMargin));
				var newY = startY + (i * (boxHeight + boxMargin));

				if(j%2)
				{
					newY += boxEvenTopMargin;
				}				
				//$("#article_" + activeArray[curBox][0]).animate({left: newX, top: newY}, 0);
				$("#article_" + activeArray[curBox][0]).animate({left: newX, top: newY}, { duration: animateDuration, queue: false });
	    		curBox++;
    		}
    	}
	}
	// change height div
	var newheight = totalRows * (boxHeight + boxMargin);
	$('#overview').height(newheight);
	resizeFooter();
}

function clientCoords()
{	
    if(jQuery.browser.msie)
    {
        return {w:document.documentElement.offsetWidth,h:document.documentElement.offsetHeight}
    }else
    {
       return {w:window.innerWidth,h:window.innerHeight}
    }
}

//!resize website

function sizeSubMenus()
{
	var total = 0;
	$('.nav_subnav').each(function()
	{
		total++;
		var w = $(this).width();
		var neww = Number(w % 16);
		var newww = w - neww;	
		$(this).css('width', newww + 48)
	});
}


function resizeFooter()
{
	var ch = $('#wrapper').outerHeight(true);
	var wh = $(window).height();
	var fh = $('#footer').height();
	var dif = wh - ch - fh;
	if(dif > 0)
	{
		$('#footer').css('margin-top', dif + 'px');
	}else
	{
		$('#footer').css('margin-top', '0px');
	}
}

function resizeSide()
{
	var titleWidth = $('#header_titlelarge').width();
	var windowWidth = $(window).width();
	var remainderSpace;
	var xPos;
	var dif = Number((windowWidth - titleWidth) % 32) + 32;
	var introwidth = windowWidth - 96 - (windowWidth % 32);
	var max = windowWidth - dif;

	if(windowWidth > 992)
	{
		$('.header_right').css('margin-right', dif);
		$('#footer_socials').css('margin-right', dif);
		$('.zinfinitecarousel_header').css('width', introwidth);
		$('.zinfinitecarousel .art_nav_right').css('left', introwidth);
	}else
	{
		$('.header_right').css('margin-right', 16);
		$('#footer_socials').css('margin-right', 16);
	}	
}

$(window).resize(function()
{	
	$.fn.zcarousel.recalculate($('.zcarousel'))	
	$.fn.zinfinitecarousel.check();
	resizeFooter();
	resizeSide();

	if(pageType=='news' || pageType=='profile' || pageType=='nlmap')
	{
	
	//update totals
	
	totalInRow = getTotalInRow();
	
	totalArticlesDisplay = Math.ceil((totalArticlesDisplay / totalInRow) * totalInRow); 
	

	if(totalArticlesDisplay > totalActive)
	{
		totalArticlesDisplay = totalActive; 
	}
	
	debug.log(totalArticlesDisplay+' display');
/*
	if() {
	
	}
*/
	
	//load new items	
	
	for(var i = 0 ; i < totalArticlesDisplay; i++)
	{
		articleArray[activeArray[i][0]][4] = 1; // set visibility of this article to 1
		
		if($("#article_" + activeArray[i][0]).length == 0) // doesn't the article exsist?
		{
			debug.log(i+' loaded');
			var arrayid = i;
			var id = activeArray[i][1];
			//$('#overview ul').append('<li class="art_small news" rel="'+id+'" id="article_'+ arrayid +'"></li>');
			$('#overview ul').append('<li rel="'+id+'" id="article_'+ arrayid +'"></li>');
			$("#article_" + arrayid).addClass(topicArray[activeArray[i][2]]);
			$('#article_'+ arrayid).hide(); // show again when loaded
			$('#article_'+i).trigger('new');
		}
	}
	updatePositions();
	}
});


/*
$.cookie('the_cookie'); // get cookie
$.cookie('the_cookie', 'the_value'); // set cookie
$.cookie('the_cookie', 'the_value', { expires: 7 }); // set cookie with an expiration date seven days in the future
$.cookie('the_cookie', '', { expires: -1 }); // delete cookie
*/

