function overlay(e) {	
	$('#content').prepend('<div id="ajax-loader"/>');
	$('#content').prepend('<div id="ajax-overlay"/>');
	$('#ajax-overlay').css({
		width:$('#content').width(),
		height:$('#content').height(),
		background:'#ffffff',
		opacity:0.7,
		position:'absolute',
		zIndex:998
	});
	$('#ajax-loader').css({
		width:$('#content').width(),
		height:$('#content').height(),
		background:'url(http://allroundsupport.nl/themes/allround/img/ajax-loader.gif) 50% 50% no-repeat',
		opacity:0.5,
		position:'absolute',
		zIndex:999
	});
}

$(document).ready(function(){
	//head titel goed zetten
	if($('#header_title p').text() != ''){
		$('#intro h1 a:first').text($('#header_title p').text());	
	}

	//referentie ajax
	$('.tabs li a').bind('click',function(e){
		$('.tabs li').removeClass('active');
		$(this).parent().addClass('active');
		var url = $(this).attr('href');
		url = url.replace('referenties/ajax', 'referenties');
		url = url.replace('referenties', 'referenties/ajax');
		
		//overlay
		overlay(e);
		
		$.get(url, {}, function(html){
			
			setTimeout(function(){
				//set te content
				$('#content #referenties-wrapper').html(html);
				
				//animations
				$('#ajax-overlay, #ajax-loader').css({height:$('#com_wrapper').height()}).fadeOut(function(){$(this).remove();});
				
				/*
				//hoogtes gelijk trekken
				$('.com_wrapper img').load(function(){equalHeight($('.com_wrapper'));});*/
				
			}, 200);
			
		});
		
		return false;
	});

	$('#paginate a').live('click',function(e){
		var url = $(this).attr('href');
		url = url.replace('referenties/ajax', 'referenties');
		url = url.replace('referenties', 'referenties/ajax');
		
		//overlay
		overlay(e);
		
		$.get(url, {}, function(html){
			
			setTimeout(function(){
				//set te content
				$('#content #referenties-wrapper').html(html);
				
				//animations
				$('#ajax-overlay, #ajax-loader').css({height:$('#com_wrapper').height()}).fadeOut(function(){$(this).remove();});
				
				/*
				//hoogtes gelijk trekken
				$('.com_wrapper img').load(function(){equalHeight($('.com_wrapper'));});*/
				
			}, 200);
			
		});
		
		return false;
	});




	//validate forms
	$('.contact-formulier').validationEngine({ promptPosition: "centerRight" });
	$('.reageer-formulier').validationEngine({ promptPosition: "centerRight" });
	

	//lege ul van de subnav iden
	if( $('.subnav ul').length < 1 ) {$('.subnav').css('display','none');}

	//tweets
    $('#news').jTweetsAnywhere({
		username: 'AllroundGroep',
		//searchParams : ['q=from:reinos_%20OR%20%23tvvego%20OR%20from:suneco_nl'],
		count: 3,
		showTweetFeed: {
        		expandHovercards: true,
        		showSource: true
    		},
	tweetFeedDecorator: function() {
		return '<ul class="news"></ul>';
	},
	tweetTimestampDecorator: function(tweet, options) {
		// the default tweet timestamp decorator does a little bit of Twitter like formatting.

		// if tweet is a native retweet, use the retweet's timestamp
		var tw = tweet.retweeted_status || tweet;

		// reformat timestamp from Twitter, so IE is happy
		var createdAt = formatDate(tw.created_at);

		// format the timestamp by the tweetTimestampFormatter
		var tweetTimestamp = options.tweetTimestampFormatter(createdAt);
		var tweetTimestampTooltip = options.tweetTimestampTooltipFormatter(createdAt);

		var screenName = tw.user ? tw.user.screen_name : false || tw.from_user;
		var html =
			'<span class="jta-tweet-timestamp">ongeveer ' +
			tweetTimestamp +
			'</span>';

		return html;
	},
	tweetTimestampDecorator: function(tweet, options){
   			var now = new Date();
			
			var tw = tweet.retweeted_status || tweet;

			// reformat timestamp from Twitter, so IE is happy
			var timeStamp = formatDate(tw.created_at);
			
			var diff = parseInt((now.getTime() - Date.parse(timeStamp)) / 1000);
	
			var tweetTimestamp = '';
			if (diff < 60)
			{
				tweetTimestamp += diff + ' seconden' + (diff == 1 ? '' : '') + ' geleden';
			}
			else if (diff < 3600)
			{
				var t = parseInt((diff + 30) / 60);
				tweetTimestamp += t + ' minuten' + (t == 1 ? '' : '') + ' geleden';
			}
			else if (diff < 86400)
			{
				var t = parseInt((diff + 1800) / 3600);
				tweetTimestamp += t + ' uur' + (t == 1 ? '' : '') + ' geleden';
			}
			else
			{
				var t = parseInt((diff + 43200) / 86400);
				tweetTimestamp += t + ' dag' + (t == 1 ? '' : 'en') + ' geleden';
			}
	
			return '<span class="jta-tweet-timestamp">' + tweetTimestamp + '</span>';
		},
		tweetSourceDecorator : function(tweet, options)
		{
			//leeg maken en niks tonen
			html = '';
			return html;
		}
    });



});
