var ANIMACION = 350;

function escribeMail(nombre,dominio,etiqueta){
	if( !etiqueta ){
		etiqueta = nombre+"@"+dominio;
	}
	
	document.write('<a href="mailto:'+nombre+'@'+dominio+'">'+etiqueta+'</a>');
}

jQuery(document).ready(function(){
	jQuery("a.grupo").bind("click",function(){
		if( jQuery(this).hasClass("desplegado") ){
			
			jQuery(this).closest("li").find("ul:first").animate({height:"hide",opacity:"hide"},ANIMACION);
			
		}else{
			var restoOpciones = jQuery(this).closest("li").siblings();
			
			// Ocultamos el resto de grupos
			jQuery(restoOpciones).find("ul:first").animate({height: "hide",opacity:"hide"},ANIMACION);
			jQuery(restoOpciones).find(".grupo").removeClass("desplegado");
			
			jQuery(this).closest("li").find("ul:first").animate({height: "show",opacity:"show"},ANIMACION);
		}
		jQuery(this).toggleClass("desplegado");
		
		jQuery(this).blur();
		return false;
	});
	
	jQuery(".item").bind("click",function(){
		if( jQuery(this).hasClass("desplegado") ){
			jQuery(this).closest("li").find(".elemento").animate({height:"hide",opacity:"hide"},ANIMACION);
			jQuery(this).closest("li").find(".pantalla,img").fadeOut(ANIMACION);
		}else{
			
			var closestLi = jQuery(this).closest("li");
			var restoOpciones = jQuery(closestLi).siblings();
			
			// Ocultamos el resto de grupos
			jQuery(restoOpciones).find(".elemento:first").animate({height:"hide",opacity:"hide"},ANIMACION);
			jQuery(restoOpciones).find(".pantalla,img").fadeOut(ANIMACION);
			jQuery(restoOpciones).find(".item").removeClass("desplegado");
			
			jQuery(closestLi).find(".elemento:first").animate({height:"show",opacity:"show"},ANIMACION);
			//jQuery(closestLi).find(".pantalla,img").fadeIn(ANIMACION);
			jQuery(closestLi).find(".pantalla,img").css({opacity:0}).stop().show().animate({opacity: 1},"slow");

		}
		jQuery(this).toggleClass("desplegado");
		
		jQuery(this).blur();
		return false;
	});
});

