$(document).ready(function () {
	
	/* Modals */
	if ( jQuery('#artista_titulos .titulo').length ) {
		$('#artista_titulos .titulo').each(function(i) {
			$(this).find('.info a').click(function (e) {
				$('#modal'+i).modal();
				return false;
			});
		});
	}
	
	/* Modals */
	if ( jQuery('#contenido_info table tr').length ) {
		$('#contenido_info table tbody tr').each(function(i) {
			$(this).find('.info').click(function (e) {
				$('#modal'+i).modal();
				return false;
			});
		});
	}
	
	$('#enlace-reproductor-anadir').click(function (e) {
		$('#modal-reproductor-anadir').modal();
	});

	$('#enlace-reproductor-enviar').click(function (e) {
		$('#modal-reproductor-enviar').modal();
	});

	$('#enlace-reproductor-eliminar').click(function (e) {
		$('#modal-reproductor-eliminar').modal();
	});
	
	
	/* Paginacion Top titulos */
	if ($('#artista_titulos').length) {
		var elementos = 20;
		pager(0, elementos, '#artista_titulos .titulo', '#anterior-titulos', '#siguiente-titulos');
	}
	
	/* Paginacion Artistas similares */
	if ($('#artista_similar').length) {
		var elementos = 7;
		pager(0, elementos, '#artista_similar .similar', '#anterior-artistas', '#siguiente-artistas');
	}
	
	/* Albumes */
	/*
	if ( jQuery("#contenido-album").length ) {
		jQuery('#contenido-album').pager('.modulo', {
			navId: 'pagednav'
		});
	}
	*/
	
	/* Paginacion Albumes, Singles, EPs y Recopilatorios*/
	if ( $('#contenido_album .modulo').length ) {
	
		var elementos = 4;
	
		$('#contenido_album .modulo').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', 'block');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('#contenido_album .modulo').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#contenido_album .modulo').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', 'block');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Paginacion temas reproductor */
	
	if ( $('#player > table').length ) {
	
		var elementos = 25;
	
		$('#player > table tbody tr').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', '');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('#player > table tbody tr').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#player > table tbody tr').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', '');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Paginacion criticas */
	
	if ( $('#contenido #album_caja .critica').length ) {
	
		var elementos = 2;
	
		$('#contenido #album_caja .critica').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', 'block');
			else 
				$(this).css('display', 'none');
		});
	
		$(".paginacion").pagination($('#contenido #album_caja .critica').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#contenido #album_caja .critica').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', 'block');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}
	
	/* Resultados de busqueda: Artistas, albumes, listas */
	
	if ( $('.principal_busqueda #busqueda_caja .modulo').length ) {
	
		var elementos = 8;
	
		$('.principal_busqueda #busqueda_caja .modulo').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', 'block');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('.principal_busqueda #busqueda_caja .modulo').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('.principal_busqueda #busqueda_caja .modulo').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', 'block');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Resultados de busqueda: Titulos*/
	
	if ( $('.principal_busqueda #busqueda_caja #contenido_info table').length ) {
	
		var elementos = 18;
	
		$('.principal_busqueda #busqueda_caja #contenido_info table tbody tr').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', '');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('.principal_busqueda #busqueda_caja #contenido_info table tbody tr').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('.principal_busqueda #busqueda_caja #contenido_info table tbody tr').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', '');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Generos y paises: Artistas*/
	
	if ( $('#contenido #contenidoGeneros .artistas').length ) {
	
		var elementos = 4;
	
		$('#contenido #contenidoGeneros .artistas > ul li').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', 'block');
			else 
				$(this).css('display', 'none');
		});
		
		//alert($('#contenido #contenidoGeneros .artistas > ul li').length);
	
		$("#contenido #contenidoGeneros .artistas .paginacion").pagination($('#contenido #contenidoGeneros .artistas > ul li').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#contenido #contenidoGeneros .artistas ul li').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', 'block');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});
		
		//alert($('#contenido #contenidoGeneros .artistas ul li').length);

	}	
	
	/* Generos y paises: Albumes*/
	
	if ( $('#contenido #contenidoGeneros .albumes').length ) {
	
		var elementos = 4;
	
		$('#contenido #contenidoGeneros .albumes > ul li').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', 'block');
			else 
				$(this).css('display', 'none');
		});
	
		$("#contenido #contenidoGeneros .albumes .paginacion").pagination($('#contenido #contenidoGeneros .albumes > ul li').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#contenido #contenidoGeneros .albumes ul li').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', 'block');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Usuario: Votaciones , criticas, listas*/
	
	if ( $('#contenido #usuarioBox .recAlbum').length ) {
	
		var elementos = 5;
	
		$('#contenido #usuarioBox .recAlbum').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', 'block');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('#contenido #usuarioBox .recAlbum').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#contenido #usuarioBox .recAlbum').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', 'block');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Usuario: Amigos */
	
	if ( $('#amigosTabla').length ) {
	
		var elementos = 5;
	
		$('#amigosTabla tbody tr').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', '');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('#amigosTabla tbody tr').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#amigosTabla tbody tr').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', '');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
	/* Resultados de busqueda: Titulos*/
	
	if ( $('#recentListsBox > table').length ) {
	
		var elementos = 20;
	
		$('#recentListsBox > table tbody tr').each(function(i) {
			if (i <= elementos-1) 
				$(this).css('display', '');
			else 
				$(this).css('display', 'none');
		});
	
		$("#paginacion").pagination($('#recentListsBox > table tbody tr').length, {
			items_per_page: elementos,
			callback: function(id, container) {
				
				$('#recentListsBox > table tbody tr').each(function(i) {
					if (i >= id*elementos && i < (id*elementos)+elementos) 
						$(this).css('display', '');
					else 
						$(this).css('display', 'none');
				});
				
				return false;
			}
		});

	}	
	
});



function pager(primer, elementos, selector, selector_anterior, selector_siguiente) {

	$(selector_anterior).unbind('click');
	$(selector_siguiente).unbind('click');

	$(selector).each(function(i) {
		if (i >= primer && i<= primer+elementos-1) 
			$(this).css('display', 'block');
		else 
			$(this).css('display', 'none');
	});
	
	i = $(selector).length;
	
	if (primer <= 0) {
		$(selector_anterior).css('display', 'none');
	}
	else {
		$(selector_anterior).css('display', 'inline');
	}
	
	if (primer+elementos >= i) {
		$(selector_siguiente).css('display', 'none');
	}
	else {
		$(selector_siguiente).css('display', 'inline');
	}
	
	$(selector_anterior).bind('click', function() {
		pager(primer-elementos, elementos, selector, selector_anterior, selector_siguiente);	
		return false;
	});
	
	$(selector_siguiente).bind('click', function() {
		pager(primer+elementos, elementos, selector, selector_anterior, selector_siguiente);	
		return false;
	});
	
	return false;
}