/* 
	sIFR Related
*/
var apex = {
    src: 'assets/flash/apex.swf'
    ,ratios: [9, 1.49, 10, 1.39, 13, 1.41, 16, 1.39, 19, 1.38, 20, 1.35, 23, 1.36, 29, 1.35, 30, 1.33, 39, 1.34, 40, 1.32, 44, 1.33, 46, 1.32, 49, 1.33, 74, 1.32, 76, 1.31, 78, 1.32, 80, 1.31, 81, 1.32, 86, 1.31, 87, 1.32, 1.31]
  };
  
sIFR.activate(apex);

sIFR.replace(apex, {
    selector: '#contentHeader h2'
    ,css: ['.sIFR-root { color: #545448; text-transform: uppercase;}']
    ,offsetTop: 4
  
}); 

sIFR.replace(apex, {
    selector: '#contentMain h3'
    ,css: ['.sIFR-root { color: #545448;}']
    ,offsetTop: 4
});

//sIFR.debug.ratios({ src: 'assets/flash/apex.swf', selector: '#contentHeader h2' });


$(function(){

	/*
	Wrap each li's content with a span, which will show the text as black, b/c the list itself is given 
	a color corrresponding to each section's color. This is the only way to get numbered lists to have a
	different color numbers and text, which is purely presentational. If JS isn't available, all ol's on the
	site are just displayed with as black.
	*/
	$('ol').addClass('orderedList').children('li').wrapInner('<span></span>'); 
	
	/*
	Any image given this class will be wrapped in a div, and the ALT text will be displayed below the image
	in a p tag. This is an easier way to manage callout images without having to manually add all the HTML 
	necessary to get the style.
	*/
	$('img.callOut').each(function(){
	    var styles = $(this).attr('class');   
	    var text = $(this).attr('alt');   
	    $(this).attr('class','').wrap('<div class="'+ styles +'"></div>').after('<p>'+ text +'</p>');
	});
	
	// Make the whole region clickable while keeping the HTML valid
	$('ul.news li').each(function(){
		var href = $(this).find('p.more a').attr('href');
		$(this).addClass('clickable').click(function(){
			window.location = href;
		});
	});
	
	// 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)');
		}
	});
	
	$('.hide').hide();
	
	// Toggle hidden divs
	$('a.toggle').toggle(
		function(){
			$(this).addClass('down');
			$(this).parent().next('.hide').show();	
		}
		,function(){
			$(this).removeClass('down');
			$(this).parent().next('.hide').hide();	
		}
	);
	
	
	// Automatically set the widths of the labels based on the width of the longest one
	//$('.form label').autoWidth({limitWidth: 200});
});


jQuery.fn.autoWidth = function(options) 
{
	var settings = {
        limitWidth 	: false
	}
	
	if(options) {
        jQuery.extend(settings, options);
    };
    
    var maxWidth = 0;

	this.each(function(){
		width = $(this).width();
        if ( width > maxWidth || width > settings.limitWidth ){
        	if(settings.limitWidth != false && maxWidth > settings.limitWidth) {
        		maxWidth = settings.limitWidth;
        	} else {
        		maxWidth = $(this).width();
        	}
        }
	});	 
	
	this.width(maxWidth);
}
