$(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]').attr('target', '_blank');
	
	$('#top-nav li').each(function(){
		if($(this).find('a').hasClass('current')) $(this).next('li').css('background','0');
	});
	
	/* input text */
	$('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');
	}

});

/*-------------------------------------------------------------------------*/
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>")
}
/*-------------------------------------------------------------------------*/
