var GB_ANIMATION = true;

$(document).ready(function() {	
	
	var navSection = $("#NavSection").val();


	// NEW NAVBAR CODE
	$("ul.subnav").parent().append("<span></span>"); // Only shows drop down trigger when js is enabled 
	$("ul.topnav li").hover(function()
	{
		$(this).find("ul.subnav").slideDown('fast').show(); // Drop down the subnav on click

		$(this).hover(function() {
		}, function(){	
			$(this).find("ul.subnav").slideUp('fast'); // When mouse exits subnav, move it back up
		});

		// Hover events
		}).hover(function() { 
			$(this).find("span").addClass("subhover");     // On hover over, add class "subhover"
		}, function() {
			$(this).find("span").removeClass("subhover");  // On hover out, remove class "subhover"
	});
		
	$("ul.topnav li").each(function () {
		if ( navSection.length > 1 && $(this).find("a:first").text().indexOf(navSection) >= 0 ) {
			$(this).find("a:first").css({ 'color' : '#dfc955'});
			// $(this).attr("currentSection","currentSection");
			return false; // stop the loop.
		}
	});



	// OLD NAVBAR CODE -- REMOVE ONCE EPA + NEW NAVBAR LAUNCHES
	// Top-level navigation
	$("ul#topnav li").hover(function() {

		$("ul#topnav li[currentSection]").css({ 'background' : 'none'}); //Ditch the background
		$("ul#topnav li[currentSection]").find("span").hide(); //Hide the subnav

		$(this).css({ 'background' : '#015296'}); //Add background color + image on hovered list item
		$(this).find("span").show(); //Show the subnav
	} , function() { // on hover out...
		$(this).css({ 'background' : 'none'}); //Ditch the background
		$(this).find("span").hide(); //Hide the subnav
	});

	
	// This code pre-selects the appropriate menu based on
	// the value of the hidden input element with an ID of "NavSection"
	$("ul#topnav li").each(function () {
		if ( navSection.length > 1 && $(this).find("a:first").text().indexOf(navSection) >= 0 ) {
			$(this).css({ 'background' : '#015296'}); //Add background color + image on hovered list item
			$(this).find("span").show(); //Show the subnav
			$(this).attr("currentSection","currentSection");
		}
	});

	// When the user mouses out of the navigation area, reset the highlight
	// to the current page.
	$("ul#topnav").mouseleave(function() {
		// This code pre-selects the appropriate menu based on
		// the value of the hidden input element with an ID of "NavSection"
		var navSection = $("#NavSection").val();
		$("ul#topnav li").each(function () {
			if ( navSection.length > 1 && $(this).find("a:first").text().indexOf(navSection) >= 0 ) {
				$(this).css({ 'background' : '#015296'}); //Add background color + image on hovered list item
				$(this).find("span").show(); //Show the subnav
			}
		});


	});


	// --- END OLD NAVBAR CODE --

	// Greybox modal window

	$("a.greybox").click(function() {
		var t = this.title || this.innerHTML || this.href;
		GB_show(t,this.href,470,600);
		return false;
	});
	$("a.greyboxdemo").click(function() {
		var t = this.title || this.innerHTML || this.href;
		GB_show(t,this.href,600,800);
		return false;
	});
	$("a.greyboxcal").click(function() {
		var t = this.title || this.innerHTML || this.href;
		GB_show(t,this.href,770,1000);
		return false;
	});

});

function showFpass() {
window.open('https://secure2.360training.com/vu3/index.cfm?event=forgotPassword&cId=3229','ForgotPassword','width=400,height=400,location=no,status=no,directories=no,toolbar=no,scrollbars=yes,menubar=no,resize=no,top=30,left=30');
}

// For conversion tracking
function trackSale(productCode)
{
	try {
		var pageTracker = _gat._getTracker("UA-4665872-9");
		pageTracker._setDomainName(".osha.com");
		pageTracker._trackPageview('/sold/'+productCode);
	} catch(err) {}
	return true;
}

// For compliance store banner tracking
function trackBanner(bannerCode,bannerUrl)
{
	try {
		var pageTracker = _gat._getTracker("UA-4665872-9");
		pageTracker._setDomainName(".osha.com");
		pageTracker._trackPageview('/banner/'+bannerCode);
	} catch(err) {}
	window.location = bannerUrl;
}

