window.addEvent('domready',function() {
		
	//Volver arriba global
	new Element('span', {
		'id': 'back-to-top', 
		'styles': {'opacity': 0.6},
		'events': {'click': function() {
			if (window.location.hash) { window.location.hash = "page"; } 
			else { var go = new Fx.Scroll(window).toElement(document.body); }
			}}
	})
	.set("text", 'Volver arriba')
	.injectInside(document.body);
	
	if($chk($('mapaIntercambios')) && $chk($('back-to-top'))){
		$('back-to-top').set('text','Volver al mapa');
	}
		
	window.addEvent('scroll', function() {
		var fn = window.getScrollTop() > (window.getHeight() * 0.8) ? "addClass" : "removeClass";
		$('back-to-top')[fn]('visible');
	});
  	
	//Licenciaturas tooltip
	if($chk($('portada-lateral'))) {
	  //store titles and text
	  $$('a.tipz').each(function(element,index) {
		var content = element.get('title').split('::');
		element.store('tip:title', content[0]);
		element.store('tip:text', content[1]);
	  });
	  
	  //create the tooltips
	  var tipz = new Tips('.tipz',{
		className: 'tipz',
		fixed: true,
		hideDelay: 50,
		showDelay: 50
	  });
	  
		tipz.addEvents({
		  'show': function(tip) {
			tip.fade('in');
		  },
		  'hide': function(tip) {
			tip.fade('out');
		  }
		});
	}
	
	
	//Milbox automático para la portada
	if($chk($('milkbox1'))){
		milkbox.showGallery({gallery:'p1'});
		$('milkbox1').setStyle('display','none');
	}
	
	//SlideShowPortada
	if($chk($('slideshow-container-portada'))) {
		var slideshow2 = new SimpleSlideshow('slideshow-container-portada','#slideshow-container-portada img', {showControls:false});
		slideshow2.start();	
	}
	
	//ZebraTables
	var zTables = new ZebraTables('bordes');
	
	//Tabla de contenidos
	
	//Si estoy en una página normal
	if($('contenidoTexto').getElement('div.pagina-normal')!=null){
		//Iniciar variables
		var finders = ['h1','h2','h3','h4'];
		var matches = [];
	
		//Encontrar el H1 que es el nombre del artículo
		$('contenidoTexto').getElements('h1, h2, h3, h4, not(div.extra h1), not(div.extra h2), not(div.extra h3), not(div.extra h4)').each(function(el,i) {
	
			
			//¿Queremos esto?
			if(finders.contains(el.get('tag')))
			{
				//Crea anclas
				var anchor = new Element('a', {
					'class': el.get('tag'),
					'text': el.get('text'),
					'href': 'javascript:;'
				});
	
				//click event
				anchor.addEvent('click', function() {
					var go = new Fx.Scroll(window).toElement(el);
				});
	
				//Añade a nuestro array de coincidencias
				matches.include(anchor);
				
				//====NUEVO: Regresar arriba
				//Crear elemento "regresar"
				if(!$chk($('mapaIntercambios'))){
					var regresar = new Element('a', {
						'class': 'regresar-arriba',
						'text': 'Subir',
						'href': 'javascript:;'
					});
				} else {
					var regresar = new Element('a', {
						'class': 'regresar-arriba',
						'text': 'Volver al mapa',
						'href': 'javascript:;'
					});
				}
				//Agregar evento al elemento "regresar"
				regresar.addEvent('click', function() {
					var go = new Fx.Scroll(window).toElement(document.body);
				});
				//Sambutir elemento "regresar" antes de cada elemento del array
				if(i>1){
					regresar.inject(el, 'before');
				}
				//====END NUEVO
			}
			
		});
	
		//¿Debemos mostrar la TOC?
		if(matches.length>2)
		{
			//Crea el DIV para la TOC, inyecta el DIV
			var toc = new Element('div', {
				'id': 'toc',
				'html': '<strong>En esta página... <\/strong><br \/>'
			}).inject('contenidoTitulo','after');
	
			//Inyecta las coincidencias
			matches.each(function(el) {
				el.inject(toc);
			});
		}	
	}
	
	//MenuMatic
	if($chk($('menu1'))) var menuMatic1   = new MenuMatic({id:'menu1', subMenusContainerId:'menu1Lienzo' });      // Principal
	if($chk($('webfen1'))) var menuMatic1 = new MenuMatic({id:'webfen1', subMenusContainerId:'webfen1Lienzo' });  // FEN
	if($chk($('webder1'))) var menuMatic1 = new MenuMatic({id:'webder1', subMenusContainerId:'webder1Lienzo' });  // Derecho
	if($chk($('webmed1'))) var menuMatic1 = new MenuMatic({id:'webmed1', subMenusContainerId:'webmed1Lienzo' });  // Medicina
	if($chk($('webdis1'))) var menuMatic1 = new MenuMatic({id:'webdis1', subMenusContainerId:'webdis1Lienzo' });  // Diseño
	if($chk($('webing1'))) var menuMatic1 = new MenuMatic({id:'webing1', subMenusContainerId:'webing1Lienzo' });  // Ingenería
	if($chk($('webnut1'))) var menuMatic1 = new MenuMatic({id:'webnut1', subMenusContainerId:'webnut1Lienzo' });  // Nutrición
	if($chk($('webodo1'))) var menuMatic1 = new MenuMatic({id:'webodo1', subMenusContainerId:'webodo1Lienzo' });  // Odontología
	if($chk($('webpsi1'))) var menuMatic1 = new MenuMatic({id:'webpsi1', subMenusContainerId:'webpsi1Lienzo' });  // Psicología
	if($chk($('webcom1'))) var menuMatic1 = new MenuMatic({id:'webcom1', subMenusContainerId:'webcom1Lienzo' });  // Comunicación
	if($chk($('webarq1'))) var menuMatic1 = new MenuMatic({id:'webarq1', subMenusContainerId:'webarq1Lienzo' });  // Arquitectura
	if($chk($('webcli1'))) var menuMatic1 = new MenuMatic({id:'webcli1', subMenusContainerId:'webcli1Lienzo' });  // Clínica Universitaria
	if($chk($('webpos1'))) var menuMatic1 = new MenuMatic({id:'webpos1', subMenusContainerId:'webpos1Lienzo' });  // Posgrados
	
	//Moo Scroll (noticias)
	if($chk($('noticiasVentana'))) {
		noticias = new Scroller($('noticiasVentana'), {'autostart':true, 'leftm':5, 'topm':10, 'duration':250, 'sleep':5000});
	}
	
	//SiteFeature
	if($chk($('Sitefeature'))) {
		new SiteFeature($('Sitefeature'), {
			autoPlay: true,
			autoPlayInterval: 10000,
			fxDuration: 500,
			fxTransition: 'sine:in',
			navigationOrientation: 'right',
			overlayOpacity: 0.5,
			pauseOnMouseOver: true,
			showArrow: false,
			showLayerOnMouseOverOnly: false,
			trigger: 'click'
		});		
	}
	
});



