$(function () {
	
	var preload = function () {};
	
	/* button hover states */
	$('input[type=image]').each(function () {
		var id = $(this).attr('id');
		preload[id + '-over'] = new Image();
		preload[id + '-over'].src = '/img/' + id + '-over.gif';
		preload[id] = new Image();
		preload[id].src = '/img/' + id + '.gif';
		
		
		$(this).mouseover(function () {
			$(this).attr('src', '/img/' + id + '-over.gif');
		});
		$(this).mouseout(function () {
			$(this).attr('src', '/img/' + id + '.gif');
		});
		
	});
	
	/* external links */
	$('a[rel=external]').each(function () {
		$(this).attr('target', '_blank');
	});
	
	$('#caption-image-thumbs li:nth-child(odd)').css('margin-right', '10px');
	$('.term-dates li[class!="head"]:nth-child(odd)').css('background', '#f5fafb');
	
	$('input[type!=submit][type!=image]').each(function() {
		var node = $(this);
		save(node);
		node.focus(function() {
			if(node.hasClass('pw')) {
				node.addClass('hide');
				node.next('input').removeClass('hide').focus();
			}
			else if(node.attr('value') == node.attr('title')) {
				node.attr('value','');
				node.removeClass('fade');
			}
		});
		node.blur(function() {
			if(node.attr('value') == '' && node.attr('type') == 'password') {
				node.addClass('hide');				
				restore(node.prev('input'));
			}
			else if(node.attr('value') == '') restore(node);
		});
  });
	
	function save(node) {
		node.attr('title' , node.attr('value'));
	}
	
	function restore(node) {
		node.attr('value',node.attr('title'));
		node.addClass('fade');
		node.removeClass('hide');
	}
	
	var el = $('#nav li li:last-child').prev().find('a').css('border-bottom', '0');	
	$('#nav li li:first-child a').css('border-top', '0');
	
	/* click close notifications */
		$('#messages li').live('click', function () {
			var removeList = false;
			if ($('#messages li').length == 1)
				removeList = true;

			$(this).animate({
				'height': 0,
				'paddingBottom': 0,
				'opacity': 0
			},'fast', 'linear', 
			function () {
				$(this).remove();
			});
			
			if (removeList) {
				$('#messages *').css({ overflow : 'hidden' });
					$('#messages').animate({ height : 0, opacity : 0, borderBottom: 0, marginBottom: 0}, 500, 'easeInOutQuint', function () { $(this).remove() });
			}
		});
		
		$('a[rel="external"]').click(function(){
			this.target = "_blank";
		});

			

	
});

/*-------------------------------------------------------------------------*/
function generateEmailLink(n,d) {
	var username = n;
	var hostname = d;
	var linktext = n+"@"+d;
	document.write("<a hr"+"ef=" + "mai"+"l" + "to:" + username +
	"@" + hostname + ">" + linktext + "</"+"a>")
}


