jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: 'x.gif',
		apply_positioning: true
	}, settings);
	
	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};
$(document).ready(function(){
	// Homepage Latest Box Toggle
	$('body').addClass('has_js');	
	$('#home #latest ul.nav li').click(function(event){
		event.preventDefault();
		if ($(this).hasClass('active') != true) {
			$('#home #latest ul.nav li').toggleClass('active');
			$('#home #latest ul#latest_news').toggleClass('active');
			$('#home #latest ul#latest_blogs').toggleClass('active');
		}
	});
	// Carousel Switch-a-roo
	$('#carousel ul li a').click(function(event){
		event.preventDefault();
		$('#carousel ul li').removeClass('active');
		$(this).parent().addClass('active');
		var clicked = $(this).attr('href');
		$('#carousel>div').hide().removeClass('active');
		$(clicked).show().addClass('active');
	});
	$('#main_search').supersleight();
	$('#darts_toggle').supersleight();
	$('a.help_expand').supersleight();
	$('#carousel').supersleight();

	// Team Page Bio/Lifelines Bait n Switch
	var tabs_nav = '<ul class="tabs_nav">'
	$('.team .tabbed h2').each(function(){
		tabs_nav = tabs_nav+'<li><a class="'+$(this).parent().attr('id')+'">'+$(this).text()+'</a></li>';
	});
	tabs_nav = tabs_nav+'</ul>';

	$('.team .tabbed h2').remove();
	$('.team .tabbed:first').before(tabs_nav);
	$('.team .tabs_nav a').click(function(event){
		var clicked = $(this).attr('class');
		$('.team .tabs_nav a').css({
			'background' : '#FFF',
			'color': '#5c5c5d'
		})
		$(this).css({
			'background' : '#F3F3F5',
			'color': '#2a2a2b'
		});
		$('.team .tabbed').hide();
		$('#'+clicked).show();
	});
	$('.team .tabbed:not(:first)').hide();
	$('.team .tabs_nav a:first').css({
		'background' : '#F3F3F5',
		'color': '#2a2a2b'
	});
	// Help Toggles
	$('.option_category p.more_info').hide();
	$("a.help_expand").toggle(function(e){
		e.preventDefault();
		$(this).closest('.option_category').find('p.more_info').show();
	}, function(e){
		e.preventDefault();
		$(this).closest('.option_category').find('p.more_info').hide();
	});
});