function registerOverlays()
{
	// register the overlays
	$('.flash-overlay').colorbox({
		width: "950px",
		height: "550px",
		iframe: true
	});

	$('.video-overlay').colorbox({
		width: "550px",
		height: "510px",
		iframe: true
	});

	$('.md-video-overlay').colorbox({
		width: "550px",
		height: "535px",
		iframe: true
	});
	
	$('.locked-resource').colorbox({
		width: "580px",
		height: "430px",
		iframe: true,
		onClosed: onUnlockResourceClosed
	});
	$('.event-registration').colorbox({
		width: "950px",
		height: "600px",
		iframe: true
	});
	$('.documentation-request').colorbox({
		width: "950px",
		height: "510px",
		iframe: true
	});
	$('a[rel="TeamProfile"]').colorbox({
		transition: "fade"
	});

	$('.video-overlay, .flash-overlay, .locked-resource, .event-registration, a[rel="TeamProfile"]').click(trackOverlayPage);

	// add the stop load parameter for resource files
	$('.locked-resource').each(function()
	{
		$(this).attr('href', $(this).attr('href') + '?sl=true')
			.attr('target', '_self');
	});
}

function getOverlayUrl()
{
	return "/Overtis/Handlers/Overlay.ashx?url=" + $(this).attr('href');
}

// removes the overlay for newly unlocked resources
function onUnlockResourceClosed()
{
	if (unlockResources)
	{
		$.colorbox.remove('.locked-resource');
	}
}

// this variable is used to check if the overlay should be removed when closed (unlocking)
var unlockResources = false;
function unlockOnClose()
{
	unlockResources = true;
}

// tracks an overlay page
function trackOverlayPage()
{
	if (this.tagName != 'A') return;
	
	var hostname = this.hostname;
	var href = this.href;
	
	TrackGAVirtualPage(href.substr(href.indexOf(hostname) + hostname.length));
}

function registerMenuHover()
{
	var body = $('body');
	if (body.hasClass('IE6') || body.hasClass('IE7'))
	{
		$('ul.level1 li.level1').hover(
			function()
			{
				$(this).find('ul.level2').css({ 'display' : 'block' });
			},
			function()
			{
				$(this).find('ul.level2').css({ 'display' : 'none' });
			}
		);
		return;
	}

	//Animate level 2 nav lists and hide then by default
	$('ul.level1 li.level1').hover(
	function()
	{
		$(this).find('ul.level2').slideDown(200);
	},
	function()
	{
		$(this).find('ul.level2').hide();
	}).find('ul.level2').hide();
}

// register overlays on document load
$(document).ready(function()
{
	if ($('body').hasClass('hasLoaded'))
	{
		return;
	}

	registerOverlays();
	registerMenuHover();
	$('body').addClass('hasLoaded');
});
