$(document).ready(function(){
    /* Para catalogo.php */
	//$('#izq ul li:first a:first').addClass('hover');
	//$('#izq ul li:first ul').css('display', 'block');
	//$('#izq ul li:first ul li:first a:first').addClass('hover');
	
	//Muestro el li que contiene un enlace con class hover
	$('#izq ul li a[class=\'hover\']').parent().parent().show();
	//Doy class hover a su categoria "padre"
	$('#izq ul li a[class=\'hover\']').parent().parent().prev().addClass('hover');
	
	/* Para catalogo-ampliado.php */
	$('#fotos img:first').css('display', 'inline');
	$('#anterior').hide();
	$('#siguiente').hide();
	if($('#fotos img:first').next().is('img'))
		$('#siguiente').show();
	$('#anterior').hover(function(){
			$(this).children().show();
		},function(){
  			$(this).children().hide();
		});
	$('#siguiente').hover(function(){
 		 	$(this).children().show();
		},function(){
			$(this).children().hide();
		});
});

function desplegarMenu(a){
	if($(a).next().css('display')=='none'){
		$('#izq ul li a').removeClass('hover');
		$('#izq ul li ul').slideUp('normal');
		//Hago slideUp a todos los ul que no tengan un a con class hover
		//$('ul').not('#izq ul li ul li a[class=\'hover\']').parent().parent().slideUp('normal');
		$('#izq ul li ul li a').removeClass('hover');
		$(a).addClass('hover');
		$(a).next().slideDown('normal');
		$(a).next().children(':first').children(':first').addClass('hover');
	}
	else{
		$(a).next().children().children().removeClass('hover');
		if (!$(a).next().children().children().hasClass('hover')) {
			$(a).next().slideUp('normal');
			$(a).removeClass('hover');
		}	
	}
}

var imagenVisible = null;

function imagenAnterior(){
		
		if(imagenVisible==null){
			imagenVisible = $('#fotos').children(':first');
			imagenVisible.hide();
			imagenVisible = imagenVisible.prev();
		}
		else {
			imagenVisible.hide();
			imagenVisible = imagenVisible.prev();
		}
		imagenVisible.fadeIn('normal');
		$('#siguiente').show();
		if(imagenVisible.prev().is('img'))
			$('#anterior').show();
		else
			$('#anterior').hide();	
}

function imagenSiguiente(){
		
		if(imagenVisible==null){
			imagenVisible = $('#fotos').children(':first');
			imagenVisible.hide();
			imagenVisible = imagenVisible.next();
		}
		else {
			imagenVisible.hide();
			imagenVisible = imagenVisible.next();
		}
		imagenVisible.fadeIn('normal');
		$('#anterior').show();
		if(imagenVisible.next().is('img'))
			$('#siguiente').show();
		else
			$('#siguiente').hide();
}	
