$(document).ready(function(){
	
	$('img.imgthcat').each(function(o){
		var img = $(this);
		var img2 = $('<img />');
		img2.attr('src',img.attr('attrsrc'));
		img2.load(function(){img.attr('src',img2.attr('src')) });

		
	});


	var nPags = $('.subcellthumbs').length;
	//alert($('.subcellthumbs:eq(0)').attr('id'));
	var act = 0;
	if (nPags>1){
		$('.next').bind('click',function(){
			if ( (act)  < (nPags-1) ) {
				$('.ant').show();
				act = act+1;
				$('.act').fadeOut('slow',function(){
					$(this).removeClass('act');
					$('.subcellthumbs:eq('+act+')').addClass('act').fadeIn();
				});
				if ( (act)  == (nPags-1)  ) $('.next').hide(); 
			} 
			return false;
		});
		$('.ant').bind('click',function(){
			if ( (act)  > 0  ) {
				$('.next').show();
				act = act-1;
				$('.act').fadeOut('slow',function(){
					$(this).removeClass('act');
					$('.subcellthumbs:eq('+act+')').addClass('act').fadeIn();
				});
				if ( (act)  == 0  ) $('.ant').hide(); 
			} 
			return false;
		});		
		
	}
	
	var rebindinfo = function(){
		$('.info').toggle(
			function(){$('.cellphotoinfo').slideDown();},
			function(){$('.cellphotoinfo').slideUp();}
		);
	};
	
	rebindinfo();
	
	var baseurl = $('#baseurl').val();
	
	$('.imgth').bind('click',function(){
		id = $(this).attr('id');
		urlfoto= $(this).attr('urlfoto');
		txt = $(this).attr('alt');
		$('.cellphotoinfo').slideUp('fast');
		$('#contefoto').children('img').fadeOut('slow',function(){
			$(this).remove();
			$('#contefoto').append('<img src="'+baseurl+'img_gallery/gallery/'+id+'" class="info" >');
			$('.cellphotoinfo').children('p').html(txt+" <br /> <a href=\""+baseurl+"fotos/view/"+$("#categoria").val()+"/"+urlfoto+".html\">Ver Imagen</a> ");
			rebindinfo();
		});
		
		
	});
	
	
	$("#cmas").toggle(function(){
		$(this).html('menos');
		$('.noshow').each(function(x){
			var div = $(this);
			window.setTimeout(function(){
				div.fadeIn('slow',function(){
					$(this).removeClass('noshow');
					$(this).addClass('show');
				});
			},x*250);
		});
		return false;
	},function(){
		$(this).html('m&aacute;s');
		var z = $('.show').length;
		$('.show').each(function(x){
			z--;
			var div = $(this);
			window.setTimeout(function(){
				div.fadeOut('slow',function(){
					$(this).removeClass('show');
					$(this).addClass('noshow');
				});
			},z*250);
		});
		return false;
	});





	
	
});
