/**
 * FIX IE6 IMAGE FLICKER PROBLEM
 *
 */
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

$(document).ready(Init);





function Init()
{
	AddThisIsARoyalPain();
	//PageBrowser();
	CurrentNavState();
	newWindowCert();
}


function newWindowCert(){
    $('a.new-window').click(function(){
        window.open(this.href);
        return false;
    });
}

function AddThisIsARoyalPain() {
	$('#share li a').mouseover(function(){
		$('#at20mc').hide();
	});
	$('#share li a.email, #share li a.fav, #share li a.print').click(function(){
		$('#at20mc').show();
	});
}


function CurrentNavState() {
	var curr_page = document.location.href;

	if(curr_page.indexOf('/en/declaration') > -1 || curr_page.indexOf('/fr/declaration') > -1) {
		$('#primary li a.link2').addClass('lit');
	}
	else if(curr_page.indexOf('/en/sign') > -1 || curr_page.indexOf('/fr/sign') > -1)	{
		$('#primary li a.link2').addClass('lit');
	}
	else if(curr_page.indexOf('/en/learnmore') > -1 || curr_page.indexOf('/fr/learnmore') > -1)	{
		$('#primary li a.link3').addClass('lit');
	}
	else if(curr_page.indexOf('/en/domore') > -1 || curr_page.indexOf('/fr/domore') > -1) {
		$('#primary li a.link4').addClass('lit');
	}
	else {
		$('#primary li a.link1').addClass('lit');
	}
}

/*
function PageBrowser() {
	var curr_page = '';
	var curr_layout = '';

	$('a[rel="navigation"]').click(function(){
		// Retrieve index of selected menu item, if applicable.
		var navIndex = $('#primary li a').index(this);

		// If a valid index was returned, update the navigation lit state.
		if(navIndex >= 0)
		{
			$('#primary li a').removeClass('lit');
			$('#primary li a:eq(' + navIndex + ')').addClass('lit');
		}

		// Load the selected page, if unique, into the content area.
		if(curr_page !== $(this).attr('href'))
		{
			curr_page = $(this).attr('href');

			$.ajax({
				beforeSend: function(XMLHttpRequest) {
					// Launch the loader overlay.
					$('<div id="overlay" />').appendTo('#body');
					$('<div id="overlay_message"><h2>Loading</h2><p>Please wait while page loads...</p></div>').appendTo('#body');
				},
				complete: function(XMLHttpRequest, textStatus) {
					// Remove the loader overlay.
				},
				dataFilter: function(data, type) {
					//console.log('dataFilter: ', data, type);

					curr_layout = $('#content', data).attr('class');
					data = $('#body', data).html();

					return data;
				},
				dataType: 'html',
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					//console.log('error: ', XMLHttpRequest, textStatus, errorThrown);
					$('#overlay_message').html('<h2>Error!</h2><p>The requested page could not be loaded.</p>');
				},
				success: function(data, textStatus) {
					pause(2000);
					$('#content').attr('class', curr_layout);
					$('#body').replaceWith('<div class="column" id="body">' + data + '</div>');
				},
				url: curr_page
			});
		}

		return false;
	});
}
*/
	/*
	* This function will not return until (at least)
	* the specified number of milliseconds have passed.
	* It does a busy-wait loop.
	*/
	function pause(numberMillis) {
		var now = new Date();
		var exitTime = now.getTime() + numberMillis;
		while (true) {
			now = new Date();
			if (now.getTime() > exitTime)
				return;
		}
	}