(function() {

	/**
	 * @author NPrice
	 */
	var NewMind = window.NewMind || {};
	NewMind.Site = window.NewMind.Site || {};
	
	/**
	 * RolloverNav
	 * @Requires JQuery.1.2.2
	 */
	NewMind.Site.RolloverNav = function(selector) {
	
		//add hover mouseover and mouseout events for the selected element
		//hover is used because it caters for bubbling problems 
		//that mouseover and mouseout dont do separately
		$(selector).hover(
			function(){
				
				var liObj = $(this);
				
				//add hover class to the li
				liObj.addClass('hover');
				
				//get the classes of the li
				//using attr because it returns a string of the value
				var classAttr = String(liObj.attr('class'));
				
				//assign just the first class found to the parent ul
				//this needs to be the pagename for the top level
				liObj.parent().addClass(classAttr.substring(0,classAttr.indexOf(' ')));
			},
			function(){
				//for mouseout just remove class from the li and its parent
				$(this).removeClass('hover').parent().removeClass();
			}
		)
	};
	
	$(document).ready(
		function() { 
			
			//optional extra bit for IE - fixes background image load flickering when hovering anchors
			//this issue will not happen if a user goes to tools > internet options > settings... > selects 'automatically'
			if ($.browser.msie) {
				try {
					document.execCommand('BackgroundImageCache',false,true);
				} catch(e) {
					// just in case this fails dont do anything
				}
			}
		
			//selector adds rollover to main nav direct child li of a direct child ul
			NewMind.Site.RolloverNav('.ctl_MainNavigation > ul > li'); 
		
		
		}
	);


})();