/**
 * Space out boxes to another container
 */
$.fn.spacingBoxes = function(count, id){
	var el1 = $(this);
	var el2 = $('#'+id);
	
	// find boxes
	var boxes = el1.find('.sidebox');
	if(!el2 || boxes.length <= count) return;
	
	// adjust CSS
	el2.show();
	$('#articles').css({
		'margin-right':	'230px'
	});
	
	// move boxes to the other container
	for(var i = count; i < boxes.length; i++){
		boxes.eq(i).appendTo(el2);
	}
}

/**
 * execute this then DOM is ready
 */
$(document).ready(function(){
	$('#sidebar').spacingBoxes(3, 'sidebar-2');

	// login links
	$('#main a').each(function(){
		var href = $(this).attr('href');
		href = href.replace(/login.php\'/, 'login.php?EVENT=SUBSCRIBERS\'');
		$(this).attr('href', href);
	});
});