	var MIN_COLS = 2;
	var COL_WIDTH = 220;
	var GAP = 20; 
	
	var offx, offy = 0;
	maxy = new Array();
	
	$(function() { 
		offy = 0;
		offx = 0;
		arrange(); 
		arrange_video();
	});

	function arrange() {
		var _max_h = 0;
		var _footer_y=0;
		
		var columns = Math.max(MIN_COLS, parseInt(800 / (COL_WIDTH+GAP)));
		$('.eachcomment').css('width',COL_WIDTH  + 'px');

		for (x=0; x < columns; x++) {
			maxy[x] = 0;
		}
		
		// lets iterate over all posts
		$('.eachcomment').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;
	
	$('#news_coment_wapper').css({'height':_footer_y});
		
	}

function arrange_video() {
		var _max_h = 0;
		var _footer_y=0;
		
		var columns_video = Math.max(MIN_COLS, parseInt(460 / (COL_WIDTH+GAP)));
		$('.eachcomment_video').css('width',COL_WIDTH  + 'px');

		for (x=0; x < columns_video; x++) {
			maxy[x] = 0;
		}
		
		// lets iterate over all posts
		$('.eachcomment_video').each(function(i) {

			var pos_video, cursor_video, w_video , altura_video= 0;
	
			w_video = (Math.floor($(this).outerWidth() / COL_WIDTH));
			cursor_video = 0;

			if (w_video>1) {
				for (x=0; x < columns_video-(w_video-1); x++) {
					cursor_video = maxy[x] < maxy[cursor_video] ? x : cursor_video;
				}
				pos_video = cursor_video;
				
				for (var x=0; x<w_video; x++) {
					altura_video = Math.max(altura_video, maxy[pos_video+x]);
				}
				for (var x=0; x<w_video; x++) 
					maxy[pos_video+x] = parseInt($(this).outerHeight()) + GAP + altura_video;
					
				$(this).css('left', pos_video*(COL_WIDTH+GAP) + offx).css('top',altura_video + offy);
				
				_max_h=(altura_video > _max_h)?maxy[pos_video+w_video-1]:_max_h;
			}
			else {
			
				for (x=0; x < columns_video; x++) {
					cursor_video = maxy[x] < maxy[cursor_video] ? x : cursor_video;
				}

				$(this).css('left', cursor_video*(COL_WIDTH+GAP) + offx).css('top',maxy[cursor_video] + offy);
				maxy[cursor_video] += $(this).outerHeight() + GAP;
				
				_max_h=(maxy[cursor_video]>_max_h)?maxy[cursor_video]:_max_h;
			}
		});
		
	_footer_y=(_footer_y<_max_h)?_max_h:_footer_y;
	
	$('#video_coment_wapper').css({'height':_footer_y});
		
	}
