(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();
			}
		)
	};

	/**
	* Move Extra Product Images - set this up because originally they used photoswitcher
	* but now the design calls for the usual extra images setup but in the center column
	* @Requires JQuery.1.2.2
	*/
	NewMind.Site.MoveExtraImages = function() {
		//make sure the extra images get hidden from the right side before removing them
		//incase the css isnt set already to do this
		//remove still lets you work with the jquery object
		//clone(true) copies the object and its event handlers
		//display it with css again
		//append what we have to after the product image
		$('#productExtraImages').css({ 'display': 'none' }).remove().clone(true).css({ 'display': 'block' }).appendTo('#colCenterProdContainer .column1');
	};

	/**
	* remove default site search text on click or focus event
	* @Requires JQuery.1.2.2
	*/

	NewMind.Site.RemoveDefaultSearchTxt = function() {
	$('input#sitesearch-keyword').bind('click focus',
			function() {
				//remove the default content if it is there
				if ($(this).val() === 'Search Site') {$(this).val(''); }
			}
		);
	}

	$(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('#topNavigation > ul > li');

			//move the extra product images if required
			NewMind.Site.MoveExtraImages();

			NewMind.Site.RemoveDefaultSearchTxt();

		}
	);


})();