// REMENYI Global Object
 if (typeof REMENYI == "undefined" || !REMENYI) {
    var REMENYI = {};
}

// Utility classes
REMENYI.Util = {
	addBodyClass: function() {

		var url = location.pathname;
		var urlParts = url.split('/');
		// Check for valid data before proceeding
		if(urlParts.length > 1) {
			var MainSectionName = urlParts[1];
			// If the MainSectionName contains an .aspx suffix, chop it out
			if(MainSectionName.indexOf(".aspx") > 0) {
				MainSectionName = MainSectionName.substring(0, MainSectionName.length-5);
			}
			$("body").addClass(MainSectionName);
			
		}

	},
	isCMSEditMasterPage: function() {
		var url = location.pathname;
		var urlParts = url.split('/');
		if(($.inArray('cms', urlParts) > 0) && ($.inArray('default.aspx', urlParts) > 0)) {
			return true;
		}
		else {
			return false;
		}
	}
}

// MegaNav
REMENYI.MegaNav = {
	init: function() {
		// Before initializing the megaNav, make sure we are not editing the CMS master page
		if(REMENYI.Util.isCMSEditMasterPage() == false) {
			var myClassName;
			// Set up hoverIntent config object
			var hoverConfig = {
				over: function() {
					myClassName = $(this).children('a').attr('class');
					if(myClassName != "") {
						$(this).append($("div#megaNav div."+myClassName));
						$(this).children("div.megaNavPanel").hide();
						$(this).children("div.megaNavPanel").fadeIn('fast');
					}
				},
				out: function() {
					$(this).children("div.megaNavPanel").fadeOut('fast', function() {
						$("div#megaNav").append($(this).children("div.megaNavPanel"));
					}); 
				}, 
				timeout: 250
			};
			$("ul#top-nav li").hoverIntent(hoverConfig);
		}
		// If we are editing the CMS master page, then make the meganav blocks visible so we can edit them
		else {
			$("div#megaNav div.megaNavPanel").show();
		}
	}
}



// Start!
$(document).ready(function() {
		REMENYI.Util.addBodyClass();
		REMENYI.MegaNav.init();
});
