$(document).ready(function() {
	
	var velocidad = 800;
	
	// Reproductor de portadas
	$('#rep_anterior').click(function() {
		obj = $('#elemento_' + (id_actual - 1));
		obj.click();
		$(this).blur();

		if ((id_actual) % 3 == 0)
			$('#pag_anterior').click();
	});
	
	$('#rep_siguiente').click(function() {
		obj = $('#elemento_' + (id_actual + 1));
		obj.click();
		$(this).blur();

		if ((id_actual + 1) % 3 == 0)
			$('#pag_siguiente').click();
	});
	
	$('#pag_anterior').click(function() {
		$('#listado_elementos').scrollTo('-=233px', velocidad);
		$(this).blur();
	});
	
	$('#pag_siguiente').click(function() {
		$('#listado_elementos').scrollTo('+=233px', velocidad);
		$(this).blur();
	});
	
	// Reproductor de galerķas
	$('#rep_anterior_galeria').click(function() {
		alert('bu');
	});
	
	$('#rep_siguiente_galeria').click(function() {
		alert('bu');
	});
	
	$('#retroceso').click(function() {
		$('#lista').scrollTo('-=75px', velocidad, {axis:'x'});
		$(this).blur();
	});
	
	$('#avance').click(function() {
		$('#lista').scrollTo('+=75px', velocidad, {axis:'x'});
		$(this).blur();
	});
	
	
	
	// Galeria de servicios
	$('#siguiente_pag').click(function() {
		$('#galeria_elementos').scrollTo('+=233px', velocidad);
		$(this).blur();
	});	
	$('#anterior_pag').click(function() {
		$('#galeria_elementos').scrollTo('-=233px', velocidad);
		$(this).blur();
	});	
});

var id_actual = 0;

function carga_video(id, orden)
{
	if (id != '')
	{
		$.ajax({
			type: 'POST',
			url: 'reproductor_portada/cargar',
			data: 'id=' + id + '&tipo=video',
			success: function(msg) {
				id_actual = orden;
				eval(msg);
				
				seleccionar(id_actual);
			}
		});
	}
}

function carga_imagen(id, orden)
{
	if (id != '')
	{
		$.ajax({
			type: 'POST',
			url: 'reproductor_portada/cargar',
			data: 'id=' + id + '&tipo=imagen',
			success: function(msg) {
				id_actual = orden;
				eval(msg);
				
				seleccionar(id_actual);
			}
		});
	}
}

function carga_i(imagen)
{
	$('#reproductor_contenido').fadeOut('slow', function(){
		$('#reproductor_contenido').attr('innerHTML', imagen);
		$('#reproductor_contenido').fadeIn('slow');
		
		$('.ampliar').fancybox({
			overlayShow: true
		});
	});
}

function carga_v(video)
{
	if($.browser.msie && $.browser.version <= 6.9)
	{
		mensaje = 	'<div style="text-align: center; color: #fff; margin-top: 75px;">' +
						'Su navegador es muy antiguo y no puede reproducir este contenido. <br>' + 
						'Por favor, actualice su navegador a una versi&oacute;n m&aacute;s actual.' +
					'</div>'; 
		$('#reproductor_contenido').attr('innerHTML', mensaje);
	}
	else
	{
		$('#reproductor_contenido').fadeOut('slow', function(){
			$('#reproductor_contenido').attr('innerHTML', video);
			$('#reproductor_contenido').fadeIn('slow');
		});
	}
}

function leyenda(texto)
{
	$('#texto_reproductor').attr('innerHTML', texto);
}

function seleccionar(id_actual)
{
	obj1 = $('.seleccionable');
	obj2 = $('#elemento_' + id_actual);
	
	obj1.removeClass('sel');
	obj2.addClass('sel');
}

function carga_img(id)
{
	if (id != '')
	{
		$.ajax({
			type: 'POST',
			url: '../../galerias/cargar',
			data: 'id=' + id,
			success: function(msg) {
				eval(msg);
			}
		});
	}
}

function carga_img_reproductor(imagen)
{
	$('#imagen').fadeOut('slow', function(){
		$('#imagen').attr('innerHTML', imagen);
		$('#imagen').fadeIn('slow');
		
		$('.ampliar').fancybox({
			overlayShow: true
		});	
	});
}