jQuery(document).ready(function(){
	//banner
	jQuery('.slideshow').cycle({fx:'turnDown'});
	jQuery('.portlet_encabezado .slideshow img').click(function(e){
		window.location.href = "?_nfpb=true&_pageLabel=HyC";
	});
	//Herramientas de plantillas
	jQuery('.herramientas').tools();
	//Transiciones subportadas
	if(jQuery('.portlet_estructura .portlet_pie .banner').size() > 0){
		var bannerattr = jQuery('.portlet_estructura .portlet_pie .banner').attr("id").split("*");
		var idbanner = bannerattr[0];
		var fotosbanner = bannerattr[1];
		for(var i = 0; i < fotosbanner; i++){
			var urlimg = "/ImageServlet?idDocumento=" + idbanner + "&indice=" + i;
			var img = new Image();
			img.src = urlimg;
			jQuery('.portlet_estructura .portlet_pie .banner').append(img);
		}
		jQuery('.portlet_estructura .portlet_pie .banner').cycle({fx:"fade"});
	}
	/*galeria de fotos*/
	jQuery('#galeria .titulo_subportada').find('a').html(jQuery('#galeria .tit_porlet_grande').text());
	//buscador uchile
	var valtxtbusqueda = 'Buscar en uchile.cl';
	jQuery('.encabezado #txtBusqueda').focus(function(){
		if(jQuery(this).val() == valtxtbusqueda){
			jQuery(this).val('');
		}
	});
	jQuery('.encabezado #txtBusqueda').blur(function(){
		if(jQuery(this).val() == ''){
			jQuery(this).val(valtxtbusqueda);
		}
	});
	/*Enviar a un amigo*/
	jQuery('#scopeOneSpan table').removeAttr('width');
	jQuery('#scopeOneSpan table tr').removeAttr('bgcolor');
	//Destacados
	if(jQuery('#home').size() > 0){
		jQuery('.portlet_destacados').destacados({'items':4});
	}else{
		jQuery('.portlet_destacados').destacados({'items':2});
		jQuery('.portlet_destacados .destacados_contenedor_lista ul').css('width', '240px');
	}
	//agenda portada
	jQuery('#T712200684061258466220498 table:eq(0) tbody:eq(0)').children('tr:eq(2)').remove();
	jQuery('#T712200684061258466220498 table:eq(1)').addClass('cuerpo_hora');
	jQuery('#T712200684061258466220498, #T708805993171258226363688').show();
	jQuery('#T712200684061258466220498').prepend('<h2 class="titulo">Agenda</h2>');
	jQuery('.portada-superior .cuerpo_hora td.link_pequeno[width="98%"]').addClass('llamada-agenda');
	jQuery('#T712200684061258466220498 br').remove();
	//coreccion href gabriel
	jQuery('.portlet_estructura ul.clasificaciones span.llamado_portada a[href*="Label=&"]').each(function(i){
		var a=jQuery(this).attr('href').split('&');    
		jQuery(this).attr('href','/'+a[a.length-1]);
	})
	//menu principal
	jQuery('.navegacion').menu();
	//menu agenda
	jQuery('.menu-agenda-botonera').menuagenda();
	//
	jQuery('.acceso_facultades').accesofacultades();
	//@mover clasificacion de plantillas a breadcrumb
	jQuery('.plantilla p.clasificacion').appendTo('.breadcrumbs');
	jQuery('.plantilla_plan_postgrado div.tit_porlet_grande').appendTo('.breadcrumbs');
	jQuery('.portlet .portlet_pie table').attr({'cellpadding':'0', 'cellspacing':'0'});
	jQuery('.plantilla .cuadro > *').wrapAll('<div class="cuadro_contenedor"></div>');
	jQuery('.plantilla .cuadro').prepend('<div class="esquina"></div>');
	jQuery('.date-pick').datePicker();
	//br de mas en plantillas
	jQuery('.plantilla .descripcion p').contents(':first').filter(function(){return limpiarBr(this);});
	function limpiarBr(node){
		if(node.nodeName == 'BR'){
			jQuery(node).remove();
		}
	}
	//funcionarios
	jQuery('#T510401149261256227795280 .portlet_pie div.mostrar').removeAttr('style');
	//agenda
	if(jQuery('.no_actividades').size() > 0){
		jQuery('.portlet_resultado_agenda_espacio .contenedor_plantilla h2, .portlet_resultado_agenda_tipo .contenedor_plantilla .fecha_resultado_agenda_tipo').hide();
	}else{
		jQuery('.portlet_resultado_agenda_espacio .contenedor_plantilla h2, .portlet_resultado_agenda_tipo .contenedor_plantilla .fecha_resultado_agenda_tipo').show();
	}
	//
	if(jQuery.support.opacity){
		jQuery('.buscador_uchile #txtBusqueda').css('marginLeft', '30px');
	}
	//eliminar relacionados de agena si esta vacio*/
	if(jQuery('.plantilla_agenda .relacionados').children().length == 0){
		jQuery('.plantilla_agenda .relacionados').remove();
	}
	//@portlet_noticias_fila
	jQuery('.portlet_noticias_fila .noticia:odd').addClass('noticia_odd');
	//@remover bullets (td) de tablas en subportadas
	jQuery('.columna-izquierda-contenido .wlp-bighorn-window td.link_pequeno[width=15]').contents('[src=images/arrow.gif]').attr('src', '../images/iconos/bullet-naranjo-relacionados.gif');
	jQuery('.columna-izquierda-contenido .wlp-bighorn-window td[width=5]').remove();
	//correciones html
	jQuery('#home .cuerpo_hora tbody tr td:first').attr('valign','top');
	jQuery('#not .despliegue2-columna-izquierda table').find('td').children('img').parent('td').remove();
	jQuery('#acad #T523613373951256590886419 table table tr:last').addClass('ver_mas');
	jQuery('.portlet_estructura img[srcjQuery=arrow.gif]').each(function(){
		jQuery(this).parent().remove();
	});
	jQuery('#conUrl table.ficha1 b:contains(:)').remove();
	jQuery('#conUrl table.ficha1').parent('td').addClass('cuadro_contenedor');
	jQuery('.portlet_estructura table').attr('width','100%');
	jQuery('#conUrl ul.contenidos_estructurados li a[hrefjQuery=' + document.location.search + ']').parent().addClass('activo');
	if(jQuery('.plantilla .cuadro_informaciones dl').text().length == 29 && jQuery('.plantilla .cuadro_informaciones dl').text().substring(0, 1) != ' '){
		jQuery('.plantilla .cuadro_informaciones dl').parent().remove();
	}else{
		jQuery('.plantilla .cuadro_informaciones').show();
	}
	//link externo
	jQuery('.columna-izquierda-contenido a').filter(function(){
		var url = jQuery(this).attr('href');
		return this.hostname && this.hostname !== location.hostname && this.hostname !== 'www2.uchile.cl' && jQuery(this).children().not('img') && url.slice(-3) !== 'pdf' && url.slice(-3) !== 'doc';
	}).addClass('enlace-externo');
	//
	


	//@aplicar a todas las tablas dentro de plantillas un ancho fijo y resetear atributos
	jQuery('.plantilla:not(.plantilla_plan_pregrado) table[width]').each(function(i){
		var f = jQuery(this).attr('width').indexOf("%");
		if(f != -1){
			jQuery(this).css('width', jQuery(this).attr('width') + '');
		}else{
			jQuery(this).css('width', jQuery(this).attr('width') + 'px');
		}
	});
	//enviar a un amigo
	var windowform = jQuery('#FormularioCorreo').closest('.tema-alert');
	windowform.addClass('ventana-enviar-amigo');
	jQuery(windowform).find('button[name="cerrar"]').click(function(e){
		e.preventDefault();
		jQuery(windowform).hide();
	});
	jQuery('.herramientas li.enviar').click(function(e){
		e.preventDefault();
		var p = jQuery(this).offset();
		jQuery(windowform).css({'top':(p.top - windowform.height() - 170) + 'px', 'left':'450px'});
		jQuery(windowform).toggle();
	});
	//
	jQuery('.plantilla_noticias, .plantilla_contenidos_generales, .plantilla_plan_pregrado, .plantilla_plan_postgrado').prepend('<div class="tamano_de_fuente"><a rel="disminuir" href="Disminuir" title="Disminuir" class="disminuir">Disminuir</a><a class="restablecer" title="Restablecer" rel="restablecer" href="Restablecer">Restablecer</a><a class="aumentar" title="Aumentar" rel="aumentar" href="Aumentar">Aumentar</a></div>');
		jQuery('.plantilla .tamano_de_fuente a').click(function(e){
			e.preventDefault();
			var target = e.currentTarget;
			jQuery('.plantilla .descripcion > *').each(function(){
				var obj = jQuery(this);
				var p = obj.css('fontSize');
				var pf = parseInt(p.substring(0, p.indexOf("p")));
				switch(jQuery(target).attr('rel')){
					case 'disminuir':
					jQuery(obj).css('fontSize', (pf - 1) + 'px');
					break;
					case 'aumentar':
					jQuery(obj).css('fontSize', (pf + 1) + 'px');
					break;
					case 'restablecer':
					jQuery(obj).removeAttr('style');
					break;
				}
				
			});
		});
});


