$(document).ready(function(){
	
	var speed = 600;
	var activeElm = false;
	var animationRunning = false;
	
 	var fixActiveBlock = function() {
	
		var activeElm = $('ul.blocks li[rel=active]');
		
		activeElm.find('div.text-more').hide();
		activeElm.find('.read-more').show();
		
		activeElm.attr('rel','normal');
		
		//activeElm.fadeIn(speed);
		//.delay((speed / 2))
		activeElm.find('div.image,div.text').fadeIn(speed);
		//activeElm.find('div.text').fadeIn(speed);
		
		return activeElm;
	}
	
	/*$('ul.blocks li').hover(function () {
	
		$(this).find('a.more').trigger('click');
		
	},function () {
		
	});*/
	
	$('ul.blocks li a.more').click(function () {
		
		if(!animationRunning) 
		{
			
			animationRunning = true;
		
			fixActiveBlock();
		
			var openingElm = $(this).parent().parent();

			openingElm.find('.image').hide();
		
			openingElm.find('.text').hide();
		
			openingElm.find('.text-more').fadeIn(speed);
		
		
			openingElm.find('.read-more').hide();
		
			$('ul.blocks').css({
			
				'position' 	: 'absolute',
				'width'		: '990px',
				'border'	: '0px solid #FF0000'
			 
			});
		
			// Attr rel van de li halen
			openingElm.parent().removeAttr('rel').animate({
		
				'width'		: '645px'
			
			},speed,function () {
			
				$(this).attr('rel','active');
			
				$('ul.blocks').css({

					'position' 	: 'static',
					'width'		: 'auto',
					'border'	: '0px'

				});
			
			});
			
			$('ul.blocks li[rel=normal]').animate({

				'width'		: '142px'

			},speed,function () {

				animationRunning = false;
				

			}).find('.text').html('');
		
		}
		else 
		{
			//alert('running');
		}
		
		return false;
	});
	
	
});
