jQuery(document).ready(function() {

	// allow for separate colors of list bullets and text
	//prepareLists();
	
	// allow really long urls in text to wrap
	jQuery('.longurl').each(function() {
		jQuery(this).html(jQuery(this).html().replace(/(\/|\?|=|\&|%)/g, '$1<wbr>'));
		});

	// add external, document, download, etc. icon hints and tooltips to links
	jQuery('#sec_header, #content, #header #navigation').linkHints(
		jQuery('link[@rel=home]').attr('href'),
		function() {
		
			// skip links that have arrows
			// var arrowChildren = jQuery('.arrow', this);
			// if (arrowChildren && arrowChildren.length) return false;
			// if(jQuery(this).next().is('.arrow')) return false;
			
			// skip ones that already have document icons
			var p = jQuery(this).parent();
			var pp = p.parent();
			if(
				p.is('.pdf') || 
				pp.is('.pdf') || 
				p.is('.powerpoint') || 
				pp.is('.powerpoint') || 
				p.is('.word_doc') || 
				pp.is('.word_doc')
				) return false;
			
			return true;
			}
		);
	jQuery('.popup a').click(function() { open($(this).attr('href'), '_blank', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=560'); return false }).append('&nbsp;<span class="external_link_icon" title="This link open a page that is part of another web site."> </span>');
	
	// add magnifying glass icons to lightbox-popup images
	var zoomify = jQuery('img.zoomify');
	zoomify.wrap('<a rel="image_link"></a>');
	jQuery("a[@rel='image_link'], a[@rel='lightbox']").each(function() {
		
		// don't add icon if surrounded (at any level) by class="gallery"
		if(jQuery(this).parents().filter('.gallery').length) return;

		jQuery(this).addClass("image_link");
		jQuery("<span class='magnify'><!-- --></span>").appendTo(this);
		});
	zoomify
		.next('.magnify')
		.css('cursor','pointer')
		.click(function() {$(this).prev('.zoomify').click()});
	
	// fix menus in IE and add keyboard navigation
	jQuery('#navigation, #sec_navigation, #main_links').scriptFocus();

	// fix floats for wide (two-column) dropdowns
	jQuery('#sec_navigation .wide ul li')
		.addClass('even')
		.filter(':odd').removeClass('even').addClass('odd');
	
	// clear "SEARCH UB 2020" out of the search box first time focused
	jQuery('#search_input').one('focus', function() { this.value = '' });
	
	});


	// Equal height columns for home main page
	jQuery(document).ready(function(){
		if(jQuery("body#home.overview").length) {

			var max_height = 1;
			var heights = new Array(jQuery("#main_column"), jQuery("#right_sidebar"));
			jQuery.each(heights, function() {
				if (jQuery(this).height() > max_height) {
					max_height = jQuery(this).height();
				};
			});
			jQuery(".column .module").height(max_height - 203); //203
			
		}
	});
	


// allow for separate colors of list bullets and text
function prepareLists() {
	var main = document.getElementById('main_column');
	var list_items = main.getElementsByTagName('li');
	for (var i=0; i < list_items.length; i++) {
		var content = list_items[i].innerHTML;
		list_items[i].className += " color_fix";
		list_items[i].innerHTML = "<div class=\"color_return\">" + content + "</div>";
	};
}

// helpers for sign-up form
function checkAll(link_text, parent_id) {
	var list = document.getElementById(parent_id);
	var li = list.lastChild;
	var a = document.createElement('a');
	a.href="javascript: addCheck(\'" + parent_id + "\')";
	a.className = "more_link check_all_link";
	var text = document.createTextNode("Select all " + link_text + " news");
	a.appendChild(text);
	li.appendChild(a);
}
function addCheck(parent_id) {
	var list = document.getElementById(parent_id);
	var inputs = list.getElementsByTagName('input');
	for (var i=0; i < inputs.length; i++) {
		inputs[i].setAttribute("checked", true);
	};
}

function navigateThisPage(selector) {
	document.write('<div class="module" id="navigatethispagemodule"></div>')
	jQuery(function() {
		var n = $('<div class="notch title"><!-- --></div><div class="content"><h4>Navigate this page</h4><ul class="navigatethispage"></ul></div><div class="notch bottom_right"><!-- --></div>');
		var l = n.find('ul');
		var h = jQuery(document).find(selector);
		var c= 1;
		h.each(function() {
			var t = jQuery(this);
			if(!t.attr('id')) t.attr('id', 'h'+c++);
			var i = jQuery('<a>')
			i.attr('href', '#'+t.attr('id')).text(t.text());
			i.appendTo(l).wrap('<li></li>');
			});
		jQuery('#navigatethispagemodule').append(n);
		});
	}
