$(function() {
	$('label').autoWidth();

	$('ol').addClass('orderedList').children('li').wrapInner('<span></span>'); 
	
	// Automatically call out linked PDF documents so we don't surprise users
	$('a').each(function(){
		var href = $(this).attr('href');
		if(href.indexOf('.pdf') != -1){
			$(this).addClass('pdf');
			$(this).append(' (pdf)');
		}
	});
		
	var overlay = $("#overlayBox").overlay({
		 
	    expose: {
	        color: '#000000',
	        loadSpeed: 200,
	        opacity: 0.5
	    },
	    
	    api: true
	});
	
	overlay.load();
	
	$("#overlayBox").click(function(){
		overlay.close();
	});
	
});

jQuery.fn.autoWidth = function(options) 
{
    var settings = {
    	minWidth	 	: false,
        limitWidth  	: false,
        ignore	: ''
    }
	
    if(options) {
        jQuery.extend(settings, options);
    };
    
    var maxWidth = 0;
    
	this.not(settings.ignore).each(function(){
        if ($(this).width() > maxWidth){
        	if(settings.limitWidth && maxWidth >= settings.limitWidth) {
        		maxWidth = settings.limitWidth;
        	} 
        	else if(settings.minWidth && maxWidth <= settings.limitWidth)
        	{
        		maxWidth = settings.minWidth;
        	} 
        	else 
        	{
        		maxWidth = $(this).width();
        	}
        }
	});	 
	
	this.not(settings.ignore).width(maxWidth);
}

