$(document).ready(function() {
	// Search bar
	$('input#s').focus(function() {
		$(this).val('');
	});
	if ($('input#s').blur().val('')) {
		$('input#s').blur(function() {
			$(this).val($(this).attr('title'));
		});
	}
	$('#helpful-link').click(function() {
		$('#helpful-info').dialog({
			//bgiframe:true,
			height:400,
			modal: true,
	                overlay: {
	                          backgroundColor: '#000',
	                          opacity: 0.5
		  	},
	                buttons: {                           
	                          'Close': function() {
     	 	                           $(this).dialog('close').remove();
     		                            return false;
        	                  }
       		        }
		});

	});	
	// Creating custom :external selector
	$.expr[':'].external = function(obj){
		return !obj.href.match(/^mailto\:/) && (obj.hostname != 
location.hostname);
	};
	// Add 'external' CSS class to all external links
	$('a:external').addClass('external');

	$('.external').click(function() {
		var link = $(this).attr('href');
		$('<div><p>Continuing through this link will open a new window or tab in your web browser. This is done as a convenience and notice to viewers who may not want to leave this page.</p></div>').dialog({
			title: "Page opens in a new window",
			modal : true,
			width: 500,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Continue':function() {
					$(this).dialog('close').remove();
					window.open(link);
				},
				'Close': function() {
					$(this).dialog('close').remove();
					return false;
				}
			}
		});
		return false;
	});
	$('#footer').localScroll();
});
