	var MIN_COLS = 2;
	var COL_WIDTH = 270;
	var GAP = 20; 
	
	var offx, offy = 0;
	maxy = new Array();
	
	$(function() { 
		offy = 0;
		offx = 0;
		arrange(); 
		arrange_list()
	});

	function arrange() {
		var _max_h = 0;
		var _footer_y=0;
		
		// how many columns fits here?
		var columns = Math.max(MIN_COLS, parseInt(600 / (COL_WIDTH+GAP)));
		$('.each_mainnews').css('width',COL_WIDTH  + 'px');
		$('.twocols').css('width', COL_WIDTH*2 + GAP  );
		$('.threecols').css('width', COL_WIDTH*3 + GAP*2);

		for (x=0; x < columns; x++) {
			maxy[x] = 0;
		}
		
		// lets iterate over all posts
		$('.each_mainnews').each(function(i) {

			var pos, cursor, w , altura= 0;
	
			w = (Math.floor($(this).outerWidth() / COL_WIDTH));
			cursor = 0;

			if (w>1) {
				for (x=0; x < columns-(w-1); x++) {
					cursor = maxy[x] < maxy[cursor] ? x : cursor;
				}
				pos = cursor;
				
				for (var x=0; x<w; x++) {
					altura = Math.max(altura, maxy[pos+x]);
				}
				for (var x=0; x<w; x++) 
					maxy[pos+x] = parseInt($(this).outerHeight()) + GAP + altura;
					
				$(this).css('left', pos*(COL_WIDTH+GAP) + offx).css('top',altura + offy);
				
				_max_h=(altura > _max_h)?maxy[pos+w-1]:_max_h;
			}
			else {
			
				for (x=0; x < columns; x++) {
					cursor = maxy[x] < maxy[cursor] ? x : cursor;
				}

				$(this).css('left', cursor*(COL_WIDTH+GAP) + offx).css('top',maxy[cursor] + offy);
				maxy[cursor] += $(this).outerHeight() + GAP;
				
				_max_h=(maxy[cursor]>_max_h)?maxy[cursor]:_max_h;
			}
		});
		
	_footer_y=(_footer_y<_max_h)?_max_h:_footer_y;
	
	$('#main_news_container').css({'height':_footer_y});
		
	}
	
//-------- List -------------------------//

var COL_WIDTH_list = 300;
var GAP_list = 20; 

var offx_list = 0;
var offy_list = 0;


function arrange_list() {
		var _max_h = 0;
		var _footer_y=0;
		
		// how many columns fits here?
		var columns = Math.max(MIN_COLS, parseInt(960 / (COL_WIDTH_list+GAP_list)));
		$('.each_list').css('width',COL_WIDTH_list  + 'px');
		$('.twocols').css('width', COL_WIDTH_list*2 + GAP_list  );
		$('.threecols').css('width', COL_WIDTH_list*3 + GAP_list*2);

		for (x=0; x < columns; x++) {
			maxy[x] = 0;
		}
		
		// lets iterate over all posts
		$('.each_list').each(function(i) {

			var pos, cursor, w , altura= 0;
	
			w = (Math.floor($(this).outerWidth() / COL_WIDTH_list));
			cursor = 0;

			if (w>1) {
				for (x=0; x < columns-(w-1); x++) {
					cursor = maxy[x] < maxy[cursor] ? x : cursor;
				}
				pos = cursor;
				
				for (var x=0; x<w; x++) {
					altura = Math.max(altura, maxy[pos+x]);
				}
				for (var x=0; x<w; x++) 
					maxy[pos+x] = parseInt($(this).outerHeight()) + GAP_list + altura;
					
				$(this).css('left', pos*(COL_WIDTH_list+GAP_list) + offx_list).css('top',altura + offy_list);
				
				_max_h=(altura > _max_h)?maxy[pos+w-1]:_max_h;
			}
			else {
			
				for (x=0; x < columns; x++) {
					cursor = maxy[x] < maxy[cursor] ? x : cursor;
				}

				$(this).css('left', cursor*(COL_WIDTH_list+GAP_list) + offx_list).css('top',maxy[cursor] + offy_list);
				maxy[cursor] += $(this).outerHeight() + GAP_list;
				
				_max_h=(maxy[cursor]>_max_h)?maxy[cursor]:_max_h;
			}
		});
		
	_footer_y=(_footer_y<_max_h)?_max_h:_footer_y;
	
	$('#list_container').css({'height':_footer_y+offy_list});
		
	}
