$(window).resize(function() {
	$('header div.last').css('width', screen.width - ($('header nav').width() - $('header nav ul li.blank').width()) + 19);
	$('footer div.last').css('width', screen.width - ($('footer ul.social').width() + $('footer ul.contact').width()) );
});

$(function(){
	$('header div.last').css('width', screen.width - ($('header nav').width() - $('header nav ul li.blank').width()) + 19);
	$('footer div.last').css('width', screen.width - ($('footer ul.social').width() + $('footer ul.contact').width()) );
	
	// Clickable
	//$('.clickable, .clickable li, .clickable div, #news ul li, #twitter ul li, #content .footer nav div, footer ul li').click(function(){
	//	if($(this).attr('target')!='_blank') window.location=$(this).find('a').attr('href');return false;
	//});
	
	// jQuery Tools Tabs
	//$('#watwedoen ul').tabs('article#content > .wrap', {effect: 'ajax', history: true, initialIndex:-1});
	
	$('#menu-main li').click(function(){
		el = $('a:first',this);
		if(el.attr('href') !== undefined){
			if(el.attr('target')=='_blank'){
				return true;
			}else{
				doAjaxForPage($(this));
				return false;
			}
		}else{
			return true;
		}
	});
	
	$('section#news ul li, .list li, .ajaxed').live('click',function(){
		doAjaxForPage($(this));
		return false;
	});
	
	$('#watwedoen ul li').live('click',function(){
		doAjaxForService($(this));
		return false;
	});
	
	function doAjaxForPage(el){
		theUrl = el.find('a').attr('href');
		initWidth = $('#ajax-content').width();
		$.ajax({
			cache: false,
			dataType: 'html',
			url: theUrl,
			beforeSend: function(){
				$('#ajax-content').animate({width:0},300,function(){$('#ajax-content').hide()});
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				alert('error while connecting to server');
			},
			success: function(data){
				$('#ajax-content').show().animate({width:initWidth},400).html(data);
			}
		})
		$('li', el.parent()).removeClass('current');
		el.addClass('current');
	}
	
	function doAjaxForService(el){
		theUrl = el.find('a').attr('href');
		initWidth = $('#ajax-service-wrapper').width();
		$('#ajax-service-wrapper').animate({width:0},300,function(){$('#ajax-service-wrapper').hide()});
		$('#ajax-service-wrapper').load(theUrl + ' #ajax-service-content', function(){
			$('#ajax-service-wrapper').show().animate({width:initWidth},400);
			$('#ajax-service-client').fadeOut('fast');
			$('#ajax-service-client').load(theUrl + ' #referenties', function(){
				$('#ajax-service-client').fadeIn('fast');
			});
			
		});
		$('li', el.parent()).removeClass('current');
		el.addClass('current');
	}
	
	$('header nav ul li a').click(function(){
			$('header nav ul li').removeClass('current');
			$(this).parent().addClass('current');
	}); 
	
	$( '#watwedoen ul li a').click(function(){
			$('#watwedoen ul li').removeClass('current');
			$(this).parent().parent().addClass('current');
	});
	
	//$('#watwedoen ul li:first').hide();

	
	// Tweeets
	$('#tweets').tweetable({username: 'antznl', time: true, limit: 3, replies: true, position: 'append'});
	
	
	//toggle the boxes
	$('.box_header').click(function(){
		$(this).next('ul, div').slideToggle(400, function() {
			$(this).addClass('closed');
		});			
	});	
});



