try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}

var highContrast = {

	initStyles: function() {
		var status = (readCookie('contrast') === 'highcontrast') ? true : false;

		$('#contrast').attr('disabled', !status);

		$(window).load(function() {
			document.getElementById('contrast').disabled = !status;
		});

		this.currentStyles(status);

	},

	currentStyles: function(contrast) {
		var elemText = (contrast) ? 'Graphical version' : 'High contrast version';

		$(function() {
			$('div.subheader div.pagetools li.contrast a').text(elemText);
		});
	},

	updateStyles: function() {
		var status = (readCookie('contrast') === 'highcontrast') ? 'graphical' : 'highcontrast';

		createCookie('contrast', status, 365);
		this.initStyles();
	}

}
highContrast.initStyles();


(function () {

	var Init = function() {

		/* div.primary ul.navigation > li > a' */
		Cufon.replace('div.webtabs a, div.takeaction a', { hover: true });
		Cufon.replace('div.subheader h1, div.banner h2, div.social li:first-child');


		$(document).ready(function() {

			// JavaScript support is enabled on the user's device.
			$('html').addClass('js');

			var pagetools = $('div.subheader div.pagetools');

			$('.print > a', pagetools).click(function() {
				window.print();
				return false;
			});

			$('.fontsize a', pagetools).click(function() {
				FontSize($(this).attr('class'));
                Cufon.refresh();
				return false;
			});

            $('.contrast a', pagetools).click(function() {
				highContrast.updateStyles();
                Cufon.refresh();
				return false;
            });

			// Format height of quick links.

		});


		FontSize = function(direction) {
			if(typeof(title) === 'undefined') {
				return false;
			}

			if(title === 'null') title = 'small';

			var fontsizes = ['small', 'medium', 'large'],
				fontindex = jQuery.inArray(title, fontsizes);

			if(direction === 'increase' && fontindex < (fontsizes.length - 1)) {
				title = fontsizes[fontindex + 1];
			} else if(direction === 'decrease' && fontindex > 0) {
				title = fontsizes[fontindex - 1];
			}

			setActiveStyleSheet(title);
		};

	}

	return Init();

})();


var InitTabbedContent = function(elem){

	var tabs = $('.navigation:first', elem),
		tabHeight = 0;

	/* Hide all banners by default; allow jQuery Tools to
	properly initialize the defined starting banner. */
	$('.pane:gt(0)', elem).hide();

	/* Add a 'helper' class for the first tab to allow for
	slightly varied layout settings. */
	$('li:first', tabs).addClass('first');

	/* Add a 'helper' class for the number of active tabs (for
	styling purposes). */
	$(tabs).addClass('navigation-' + $('li', tabs).size())

	/* Dynamically size the content (within each tab) to ensure
	a consistent layout of the text. */
	$('li b', tabs).each(function() {
		tabHeight = ($(this).height() > tabHeight) ? $(this).height() : tabHeight;
	});
	$('li b', tabs).each(function() {
		if($(this).height() < tabHeight) {
			$(this).css('paddingTop', parseInt((tabHeight - $(this).height()) /2));
		}
	});

};
