$(document).ready(function() {
	$('#polLinks li').putBar();
	$("#welcomefooter li").putBar();
	
	$("dd.a ul li ul").hide();
	
	$("#search").removeButton();
	$("label.overlabel").overlabel();
	
	var addLinkage = $("dd.a ul li ul").parent();
	
	addLinkage.prev().children(':first').wrap("<a href=\"#\" title=\"More information\"></a>");	
	
	addLinkage.prev().toggle(
      function () {
        $("dd.a ul li ul").show("slow");
      },
      function () {
        $("dd.a ul li ul").hide();
      }
    );
});

jQuery.fn.putBar = function(){
	$(this).not(":last").each(function(i) {
		$(this).append( " | ");
	});
}

jQuery.fn.removeButton = function(){
	$("#goSearch").remove();
	$("#user_query").after(' <a href="/search.jsp" id="searchLink">GO</a>');
	$("#searchLink").click(function(e){
		e.preventDefault();
		$("#search").submit();
	});
};

jQuery.fn.overlabel = function() {
    this.each(function(index) {
        var label = $(this); var field;
        var id = this.htmlFor || label.attr('for');
        if (id && (field = document.getElementById(id))) {
            var control = $(field);
            label.addClass("overlabel-apply");
            if (field.value !== '') {
                label.css("text-indent", "-1000px");
            }
            control.focus(function () {label.css("display", "none");}).blur(function () {
                if (this.value === '') {
                    label.css("display", "block");
                }
            });
        }
    });
};