$(document).ready(function() {   
function addMega(){
$(this).addClass("hovering");
ContentBlockWidth = 220;
ContainerWidth = 900;
PaddingToRemove = 22;
navcontainerHeight = $("#navcontainer ul").height();
ContainerOffset = $("#navcontainer").offset().left;
currentID = $(this).attr("id");
offsetLeft = $("#" + currentID +" a").offset().left
offsetDif = ( (offsetLeft + ContentBlockWidth) - (ContainerWidth + ContainerOffset) );
// $("#debug").html("menu left gap: " + ContainerOffset + "<br/> item left gap:" + offsetLeft + "<br/> Diff: " + offsetDif);
$("ul#headerMenu li.mega div").css({"width": ContentBlockWidth + "px"});
if ( (ContentBlockWidth + offsetLeft) >= (ContainerWidth + ContainerOffset) ) { offsetLeft = (offsetLeft - offsetDif - PaddingToRemove); }
$("ul#headerMenu li.mega div").css({"margin-top": navcontainerHeight + "px", "left": offsetLeft + "px"});
divContents = $("#display_" + currentID).html();
if (divContents == ""){$("#display_" + LoopID).remove();}
}

function removeMega(){
$(this).removeClass("hovering");
}

var megaConfig = {
    interval: 0,
    sensitivity: 4,
    over: addMega,
    timeout: 0,
    out: removeMega
};
$("li.mega").hoverIntent(megaConfig);
});

/*
ContentURL = "/jquery/headerMenuContent.cfm"; 
if (typeof(ContentURL) != 'undefined' && ContentURL != ''){loadContentAjax(ContentURL);}
	
function loadContentAjax(ContentURL){
total_ContentBlockDiv = $("ul#headerMenu li.mega").size();
for (i=0; i <= total_ContentBlockDiv; i++){
LoopID = $("ul#headerMenu li.mega:eq(" + i + ")").attr("id");
$("ul#headerMenu li.mega:eq(" + i + ")").append( "<div class='ContentBlockContent' id='display_" + LoopID + "'></div>");
	$("#display_" + LoopID).load(ContentURL, {display_ID: "display_" + LoopID}, function(data){
			if(data == '') {$(this).remove();}
	}); 
}
}
*/