$(document).ready(function(){
	
	/* PAGINACION DE ACTIVIDADES */	
	$(".activities .nav a").click(function(){
		var position = $(this).text()-1;
		var obj = $(this).parent().parent().parent().parent();
		
		if(!$(".activity .actContainer", obj).eq(position).hasClass('show')){
			/* PAGINACION ACTUAL */
			$("a",$(this).parent()).removeClass('selected');
			$(this).addClass('selected');
			/* ESCONDER Y MOSTRAR EL DIV QUE SE ESTA PAGINADO*/
			$(".activity .actContainer", obj).removeClass('show');
			$(".activity .actContainer", obj).slideUp();
			$(".activity .actContainer", obj).eq(position).slideDown();
			$(".activity .actContainer", obj).eq(position).addClass('show');
		}
		
		return false;
	})
	
	/* PAGINACION DE VIDEOS */
	$(".videos .next").click(function(){
		var obj = $(this).parent().parent().parent().parent();
		var action = false;
		var total = $("li",obj).size()-1;
		$("li",obj).each(function(){
			if($(this).hasClass('show')){
				$(this).slideUp();
				$(this).removeClass('show');
				if($(this).index()==total){
					$("ul li",obj).eq(0).addClass('show');
					$("ul li",obj).eq(0).slideDown();
				}else{
					$(this).next().addClass('show');
					$(this).next().show();			
				}
				return false;
			}
		})
		return false;
	})
	
	$(".videos .prew").click(function(){
		var obj = $(this).parent().parent().parent().parent();
		var action = false;
		var total = $("li",obj).size()-1;
		$("li",obj).each(function(){
			if($(this).hasClass('show')){
				$(this).slideUp();
				$(this).removeClass('show');
				if($(this).index()==0){
					$("ul li",obj).eq(total).addClass('show');
					$("ul li",obj).eq(total).slideDown();
				}else{
					$(this).prev().addClass('show');
					$(this).prev().slideDown();			
				}
				return false;
			}
		})
		
		return false;
	})
	
	/* FORMULARIO DE MUSICO*/
	
	$("#frmMusico").submit(function(){
		var obj = $(this);
		$("button",obj).hide();
		$.post($(this).attr('action'),
			$(this).serialize(),
		function(data){
			$(".musicsDialog").html('<div class="result"></div>');
			$(".musicsDialog").attr('title','Se encontraron '+data.total+' músicos para su criterio de búsqueda ..')
			$.each(data.musicos,function(i,d){
				$(".musicsDialog .result").append('<H3><a href="#">'+d.usuario+' '+d.nombre+' '+d.apellido+'</a></H3><div><ul><li>Corrreo: '+d.correo+'</li><li>Instrumentos: '+d.instrumentos+'</li><li>Generos: '+d.generos+'</li></ul></div>');
			})
			$(".musicsDialog").dialog({
				modal: true,
				width: '600px',
				heigth: 'auto',
				show: "blind",
				hide: "explode",
				draggable: false,
				resizable: false,
				open: function(){
					$(".musicsDialog .result").accordion();
				}
			})
			$("button",obj).show();
		},'json')
		return false;
	})
})
