$(document).ready(function() {
	
	new Blockster({
		holder: '#header-slider',
		rows: 5,
		cols: 6
	});
	
	// Timestamps
	$("span.meta-timestamp").timeago();
	
	if ( $('#contenedor-fans').length ) {
		ordenar_fanclubs();		
	}
	
});

function ordenar_fanclubs() {
	// Obtener número de clubes
	$('#contenedor-fans').num_clubs = $('#contenedor-fans .fanclub').length ;
	$('#contenedor-fans').actualizando = 0;
	
	//Obtener número de fans
	$('#contenedor-fans .fanclub').each(function(){
		var pid = this.id.replace('club-','');
		var query = FB.Data.query('select fan_count from page where page_id={0}', pid);
		query.wait( function(fdata) {
			$('#club-'+pid+' .meta-members').text(fdata[0].fan_count);
			$('#contenedor-fans').actualizando++ ;
			if ( $('#contenedor-fans').actualizando == $('#contenedor-fans').num_clubs ) {
				$("#contenedor-fans .fanclub").tsort("span.meta-members",{order:"desc"});
			}
		});
	});
	
}
